postgresql dblink_connect timeout - postgresql

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.

Related

How can I connect to server when trying to use postgresql?

I get this error message (see below) and do not know what to do about it.
Error message:
"psql: error: connection to server at "localhost" (::1), port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections? "
I am using Windows 10 (64bit) and have tried the same thing on Kali and Ubuntu and still was not able to use postgresql.
Does anyone have a suggestion what do to? However, please use "language" that I can understand or at least look up simply because I am new to programming (in general). Thank you
P. S. I tried various different things such as using pgAdmin to change ports but cannot solve a problem. I do not know if this is important but I istalled postgresql via Binaries because regular Installer was giving an error message telling me that comspec does not point to cmd.exe even though it actually did...
If you
properly set up your db (installation and initialization using initdb), and if you
have your data directory containing your postgresql.conf and pg_hba.conf among other things, and you
properly started the postgresql service,
then I can assume your problem is in the connection string.
Try to include the superusername and/or db name, your error maybe due to psql connecting to user localhost which does not exist inside your db.
Try to run psql with -U and -d options:
psql -U postgres -d postgres

Remote access to postgresql server windows 10

As the title suggest I'm trying to configure a postgresql server to be accessible remotely. I've followed many guides and viewed some of the other answers here however I'm still having trouble.
The details:
os, windows 10
postgresql version on host is 11.6
postgresql version on remote is 11.2 with anaconda install
I have changed the pg_hba.conf and postgresql.conf to allow for connections to the server.
More specifically I've added the line
host all all xxx.xx.x.0/0 trust
I can verify that the host is listening on local address 0.0.0.0:5432 via netstat.
I can ping the ip of the host from the remote, and I have set windows firewalls on the host to allow connection.
Yet I still recieve the following error when trying to access psql from the remote.
psql: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "xxx.xx.x.144" and accepting
TCP/IP connections on port 5432?```
I had to double check the windows firewall permissions. The connection was enabled but the application was not set to allowed. It turns out a local user can enable connection but I needed the system admin to set the application executable to allowed by the windows fire wall.

How does dblink work when using it on remote client

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.

Is there any issue using the same postgresql database for two different servers?

I am using postgres database which is accessed by jboss and tomcat server.
My server accidentally restarted and then postgres service was not showing in the services list.
When I tried to open postgres local host server using pgadminIII it showed following error:
Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
If you encounter this message, please check if the server you're trying to contact is actually running PostgreSQL on the given port. Test if you have network connectivity from your client to the server host using ping or equivalent tools. Is your network / VPN / SSH tunnel / firewall configured correctly?
For security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first.
For PostgreSQL servers starting with version 8.0, this is controlled using the "listen_addresses" parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use '*' to listen on all available IP addresses. For earlier servers (Version 7.3 or 7.4), you'll need to set the "tcpip_socket" parameter to 'true'.
You can use the postgresql.conf editor that is built into pgAdmin III to edit the postgresql.conf configuration file. After changing this file, you need to restart the server process to make the setting effective.
If you double-checked your configuration but still get this error message, it's still unlikely that you encounter a fatal PostgreSQL misbehaviour. You probably have some low level network connectivity problems (e.g. firewall configuration). Please check this thoroughly before reporting a bug to the PostgreSQL community.
Does this problem arise due to accessing same DB by two different servers?
My server accidentally restarted and then postgres service was not
showing in the services list.
You can't connect because it's not running. You can have as many clients connecting to a PostgreSQL server as your hardware can support - there is no problem with that.
Restart your PostgreSQL service. If it won't, check the logs for why. If you don't know where your PostgreSQL logs are now is a good time to find out. I can't tell you how to restart the service because you haven't said what OS you are running or how you installed PG. Check your documentation.

Perl DBI: connect to REMOTE PostgreSQL db still complains about local socket file

I'm trying to use DBIx::Class to connect to a remote PostgreSQL db.
My connect string: "DBI:Pg:database=asterisk:host=example.com:hostaddr=10.10.10.10:port=5432", $user, $pass
example.com does resolve to '10.10.10.10', swapping both to the IP or having only host=IP all result in
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? at /usr/local/share/perl/5.10.1/DBIx/Class/Storage/DBI.pm line 1489. at db-access.pl line 26
On this debian I don't have or want postgresql, I do have libdbd-pg-perl however. And DBI->available_drivers says that I do have Pg (It didn't before I installed the library).
How can I find out what it's trying to do and do I need anything else installing? The server in question is configured to allow connections from 10.100.* addresses which the machine running this code is on and I can connect to it with tools such as PSequel and pgAdmin on my workstation (same network) with the db user in question.
"DBI:Pg:database=asterisk:host=example.com:hostaddr=10.10.10.10:port=5432"
That should be:
"DBI:Pg:database=asterisk;host=example.com;hostaddr=10.10.10.10;port=5432"
Only the first two separators are colons. The rest of them should be semi-colons.