How does dblink work when using it on remote client - postgresql

The scenario is we have a host with postgresql9.6 installed this is working perfectly fine. We have another host in AWS with redshift installed which contains a bunch of views. We are using dblink between these two hosts to query data / bulk inserts etc and they are working. The issue occurs when we add a client machine into the scenario. I have a laptop with the psql module and I can successfully connect to my postgresql database on the above host and run queries without any trouble but when I try executing the dblink connect command from my psql client on my laptop it fails stating ...
ERROR: could not establish connection
DETAILS: FATAL: password authentication for user " **** "
FATAL : no pg_hba.conf entry for host " ***.**.**.**", " username " , database "db", SSL off
I don't understand why we get this error because the exact commands for dblink work fine when executing local to the postgresql host.
Has anyone encountered the same issue?
Thanks

I had a very similar issue, it is not a user issue but an IP issue.
Check your laptops IP, it most likely is not listed in pg_hba.conf
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all xxx.xxx.xxx.xxx/24 md5
The first line is the local machine, the second line is for the network you are on. i.e. 198.162.1.0, would allow connection from 198.162.1.0.
Your laptop most likely is on a separate network and will have to be added.
You will also have to restart the service after making changes to pg_hba.conf
Good luck.

Related

Connecting to Postgres from Remote Network

Unable to get data from Postgres from remote network. We have a Postgres DB setup for our MItel System and users from different vlans cannot get data. They can connect to the DB successfully but getting "no records found" when connected. The users that are connect to the same vlan as the DB can connect fine and get all the data (call History) but users from a branch office cannot receive data.
What I have setup in the pg_hba.conf file is:
host all all 10.0.0.0/24 trust (I've tried md5 as well)
host all all 172.0.0.0/24 trust
In the Postgressql.conf I have:
Listen_addresses = '*'
All users are using the same database username and password.
I found out what i needed to put in the pg_hba.conf file. The line needed to read
host all all 0.0.0.0/0 md5
Not quite sure why the network address or subnet didn't work but they didn't. For whatever reason that line worked and all data is flowing. Thanks

How to connect to a local postgreSQL database from a remote pc

I am pretty new to everything that is database management, remote connection etc... And I need this for a university project.
I have a local postgreSQL database on my Windows computer, which I access through localhost. What I want to do now is connect to this database using my laptop (which is in the same WLAN, don't know if that helps).
I changed the file pg_hba.conf, and added host all all 0.0.0.0/0 md5 and host all all ::0/0 md5. Also in the postgresql.conf file, there is one line listen_addresses = '*' which was the default, but as I understand it it is what it needs to be so a non-localhost can connect to the database.
How can I do this? On my laptop I tried running psql and for the server I put the IPv4 address of my PC(where the local database is stored), but it doesn't connect (Connection timed out)

postgresql dblink_connect timeout

I am trying to use dblink to move data from one system to another. Both machines are RHEL 5.11, both running postgresql 9.2, both on the corp internal net with no firewall rules between them. I am working from my desktop vpn'ed into the corp internal net.
Call the two machines FROM and TO. The FROM machine has dblink installed as an extension, the TO machine does not. For both machines the user I am specifying has a pg_hba.conf host entry listing all for db's, 0.0.0.0/0 for address, and trust.
Using pgadmin3, I can connect to both machines from my desktop, see/add/modify databases on both. I think this rules out both trivial connection issues and permissions as potential sources of the problem.
in a pgadmin query window for the FROM machine, I execute this:
SELECT dblink_connect('AAA','host=TO dbname=XXX user=postgres password=ZZZ');
-OR-
SELECT dblink_connect('host=TO dbname=XXX user=postgres password=ZZZ');
-OR-
Either variety above entered at a psql command line on the FROM machine.
Results in this message delivered in the messages-pane or to the command line:
----- ERROR: could not establish connection DETAIL: could not connect to server: Connection timed out Is the server running on host
"TO" (AAA.BBB.CCC.DDD) and accepting TCP/IP connections on port 5432?
********** Error **********
ERROR: could not establish connection SQL state: 08001
Detail: could not connect to server: Connection timed out Is the
server running on host "TO" (AAA.BBB.CCC.DDD) and accepting TCP/IP
connections on port 5432?
Suggestions?
Update
-- tried replacing hostname "TO" with "localhost", same result.
-- however, dblink_connect('dbname_on_FROM'); works. so basic dblink functionality IS functionaing.
-- original problem remains unsolved as I want to ship data to a server on TO machine.
I am not sure if you were able to figure out the problem or not, but I am going to answer anyway. The "TO" machine's database might be running on a port different than 5432. You need to make sure the port your DB Server is running on and the port you specified in the "FROM" machine are the same.
If the port number is same, then there has to be a mistake in host, username or password when specifying these parameters in the "FROM" machine.

Postgres and Atlassian Jira: driver issue

I am trying to setup a server with centOS 32 bit to install Atlassian Jira on it.
I followed the official Atlassian installation guide at https://confluence.atlassian.com/display/JIRA/Installing+JIRA
Now I am running the Setup Wizard and I need to configure a PostgreSQL database. On my centOS, I installed version 8.4.20 via yum.
However, I am having a hard time setting Jira. Postgres is running and I can login via Linux console, but when I test the connection to the database, I get the following error:
Error connecting to database
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection refused
Also, this error appears when I type the full public IP address. If I insert localhost, I get this:
Error connecting to database
FATAL: Ident authentication failed for user "jiradbuser"
If I insert
http://<public ip>
I get the following:
Error connecting to database
No suitable driver found for jdbc:postgresql://http://<public ip>:5432/jiradb
However, I put my jdbc driver into /opt/atlassian/jira/lib and its name is postgresql-8.4-703.jdbc4.jar. Postgresql version is 8.4.20.
Where am I doing wrong?
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
By default, PostgreSQL listens only on the local loopback interface, so connecting to the public IP won't work. If you're connecting from localhost you don't need to anyway, just use localhost.
FATAL: Ident authentication failed for user "jiradbuser"
This is good, it shows that you're connecting to PostgreSQL successfully, then getting an authentication error when trying to log in.
Your PostgreSQL server install defaulted to ident authentication for TCP/IP connections, but the JIRA application isn't running under a unix user named "jiradbuser" so the connection is rejected. Change pg_hba.conf to use md5 instead of ident and set a password for the user. See the client authentication chapter in the docs, particularly, pg_hba.conf.
No suitable driver found for jdbc:postgresql://http://:5432/jiradb
I have no idea where you got the idea that that URL would work...
You want something like:
jdbc:postgresql://localhost:5432/jiradb
I had the same problem. I could solve it setting up the postgres driver .jar from maven repository to \target\jira\webapp\WEB-INF\lib\
Pretty late to the question here but thought I'd add a couple bits to help out the future, going backwards:
No suitable driver found for jdbc
A while ago Atlassian didn't distribute the PostGreSQL JDBC driver file with the JIRA releases. They have been doing this for a while now (I'd say since mid 2013) - regardless, the driver file belongs in the <jira-base>/lib directory unless you are doing a WAR install, in which case you shouldn't, and just put the driver file in the lib directory anyway
FATAL: Ident authentication failed for user "jiradbuser"
1. Listen on a socket if you need to - The best approach to this is to look at your JDBC driver URL - if it has an IP/hostname other than 127.x.x.x or 'localhost' you need to modify PostGreSQL to listen to a TCP port by modifying your postgresql.conf file to enable listening on ports. Just find the file, back it up, then open it and search for localhost, read the file comments and make the correct change. If you find yourself looking around in multiple locations in the file or changing more than a single word you are trying too hard - restore your backup and try again. Just remember to *stop* and *start* your postgres db cluster when you are done
2. enable the correct login METHOD in pg_hba.conf (same directory as the postgresql.conf file - on unix typically under /etc/postgresql/<version>/main/.) - this is difficult to writeup in brief but I'll try
1. backup the pg_hba.conf file - I ain't foolin, this is something you'll be happy with later - back the sucker up
2. edit the file
3. go to the bottom of the file - look for the last line like "# TYPE DATABASE USER ADDRESS METHOD"
4. comment out every line under this 'table heading' line
- the reason to do this is that the package maintainers often fall back to commenting here and so you'll have 2 commented out lines and then one line that isn't commented out - and you'll never notice it - it's easiest to just start off with commenting out the whole block of stuff so there isn't a single uncommented line in the file
- add a two lines for the postgres user to connect local and to a db socket unless your corporate security does not allow - something like this:
local all postgres 127.0.0.1/32 peer
host all postgres 127.0.0.1/32 trust
- add a line for your jiradbuser to connect to the newly created database via sockets with md5 encryption. md5 isn't the best - there are other options to google - if you use md5, it'd look something like this:
host jiraversiondb jiradbuser 127.0.0.1/32 md5
Then save the file, restart postgres cluster (with a stop and start, not with the 'restart' option), and test connecting from the command line.
How to test connections from the command line
If you are logged into a unix system with the postgres tools installed you should be able to mimic the connection attempt which the JIRA server will try to connect to the database. If you cannot connect to the new postgresql db from the command line it's a REAL GOOD chance that JIRA won't be able to either. Plus you'll get better error messages. So to do this just bring up a shell and enter (replacing variables where appropriate - things within the '<' and '>' characters) - all the values for these are in your head and the postgresql.conf file:
psql --port <port - default is 5434> --username=<db user name> --password --dbname=<database name>
Once you can connect from the command line it's a good bet JIRA will as well - no promises, but you'll be on sound footing.
...ahhh....now, that'll hopefully help someone...

PostgreSQL: Access to database denied

I'm using PostgreSQL 9.1 on an Ubuntu 12.04 server. The database instance seems to run fine in general and when I try and connect from pgAdmin III via localhost on the server machine itself, there is no problem.
Whenever I try to use the LAN address 192.168.1.16 from the server, I get the error "Access to database denied."
From what I gather, the common culprit in these sorts of situations seems to be the configuration described in the pg_hba.conf file, which currently contains the following:
host all all 192.168.0.1/32 md5
As far as I understand, the instance should accept all users. Is there anything I'm missing here?
Note that you are trying to connect from 192.168.1.16, however, your pg_hba.conf is allowing only 192.168.0.1 (that's what the /32 means).
Check https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#IPv4_CIDR_blocks to learn more about CIDR notation.
If you want to allow 192.168.1.16 only you can add the following line at your pg_hba.conf:
host all all 192.168.0.16/32 md5
Then, run pg_ctl reload to apply the change made above.
This answer is assuming that you have verified the listen_address parameter in your postgresql.conf file and it's binding the correct IP values.