Unable to connect to PostgreSQL - postgresql

I am trying to access a table from PostgreSQL present in other machine.
I am getting the following error.
Connection refused. Check that the hostname and port are correct and that the
postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
I have configured my ip in pg_hba.conf file as well but the same error exists. What could be the solution for it?

Can you telnet to the IP address and port number where you think PostgreSQL is listening?
If not, the trouble is that the postmaster is not running, or that you have something screwball in your network - firewalls blocking access to the port, or can't locate the host or whatever.
If you can get to the postmaster via telnet, then it may be that you've given the wrong credentials or something - but the error suggests that your client code is unable to find the remote PostgreSQL. More likely, though, the configuration being used by the Java code is not the same as the one you successfully demonstrated as working with telnet.

I am new to PostgreSql but i also had a same problem so many times, at last i found solution.
The problem was with firewall blocking port (for Ex : 5432) , once this was granted access through the firewall, i was able to connect to the database server.
You have to add only port which you are using in postgreSql to Firewall.
after this my postgreSql works Fine with Jdbc.

What is the setting for "listen_addresses" in postgresql.conf?
SHOW listen_addresses;
And did you reload the configurationfiles after the changes in pg_hba.conf and postgresql.conf?
SELECT pg_reload_conf();

I has same problem. I added following entry in pg_hba.conf and worked. Make sure you restart postgres after changin configuration file
host all all 0.0.0.0/0 md5

Related

Unable to establish a psql session with remote heroku database

I have a remote heroku database ('hobby' tier) and want to establish a remote psql connection but when I type:
heroku pg:psql
I am receiving the following error:
psql: could not connect to server: Operation timed out
Is the server running on host "ec2-54-163-230-199.compute-1.amazonaws.com" (54.163.230.199) and accepting
TCP/IP connections on port 5432?
I've edited postgresql.conf such that
listen_addresses = '*'
and added the line:
host all all 0.0.0.0/0 md5
to pg_hba.conf as I thought the issue may be my postgres configuration only accepting connections to localhost, but having restarted Postgres I am still getting the same error.
Anyone have any advice on what may be going wrong? If my firewall is blocking this would anyone have any advice on how to change that? Thanks in advance.
There must be network restrictions or firewall settings as it should work without making changes to conf file.

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.

postgres server running in local host, but postico, pgadmin can't access to it

I successfully installed postgres through homebrew, and i set it run automatically by doing
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
So, right now i can access to psql from my terminal (i use iterm2 + oh my zsh)
psql (9.6.1)
Type "help" for help.
ty2kim=#
The problem is, postgres management tools like postico, pgadmin cannot access to it
for postico, error message is
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5435?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5435?
which is weird because from my understanding, accessing to the database from terminal and management tools are basically the same if configured correctly
My pg_hba.conf and postgresql.conf are set as default (didn't make any changes there), but i tried doing
listen_addresses = 'localhost'
=>
listen_addresses = '*'
(restart server)
still didn't work
Please help!
Port 5435 is not standard for PostgreSQL. Are you sure PG is running on it? If you didn't change it in postgresql.conf it must be 5432. Please check it.
must check pg_hba.conf. If there doesn't have much restriction, you can put to end of this file by below line:
host all all all trust
After that, reload/restart instance.
Check if your PC is using firewall. If yes, please turn off it.

Geoserver(VPS) connection to PostgreSql(localhost)

I am trying to connect Geoserver (installed in a VPS) to a PostgreSql database wich is running into my pc(localhost). I have follow the steps to allow this kind of connection(I do not know if all needed):
POSTGRESQL:
1.- Edit pg_hba.config of PostgreSql to allow Ip of VPS(Geoserver):
host all all ip_VPS/24 md5
2.- Edit postgresql.conf to allow remote connections:
listen_addresses ='*'
WINDOWS:
1.- Firewall configuration to allow Ip(VPS) access.
,but i still getting this connection error:
Unable to obtain connection: Cannot create PoolableConnectionFactory
(Connection to My_Ip(pc):5432 refused. Check that the hostname and
port are correct and that the postmaster is accepting TCP/IP
connections.).
Would i have to make other configuration ?.
Thanks in advance.
0k. You have in pg_hba.config:
host all all ip_VPS/24 md5
Maybe you should try this:
host all all ip_VPS/24 trust
Then you should restart postgres.
(For the parameter "trust" or "md5" I recommend reviewing:
www.postgresql.org/docs/9.5/static/auth-pg-hba-conf.html)
Greetings.

postgresql server doesn't listen

I just recently install PostgreSQL on our server via SSH. The installation went successful, until the time I tried to connect to it using pgAdmin on my Windows machine.I received this kind of error:
could not connect to server: Connection refused (0x0000274D/10061) Is
the server running on host "xxx.xxx.xxx.xxx" and accepting TCP/IP
connections on port 5432?
xxx.xxx.xxx.xxx = my server's public IP.
The docs suggest this can be fixed by setting the value of listen_addresses = '*' in the /etc/postgresql/9.1/main/postgresql.conf. I did that but still it won't let me.
additional error came up
FATAL: no pg_hba.conf entry for host "xxx.xx.xxx.xxx", user
"postgres", database "postgres", SSL on FATAL: no pg_hba.conf entry
for host "xxx.xx.xxx.xxx", user "postgres", database "postgres", SSL
off
xxx.xx.xxx.xxx = my IP address.
What seems to be I'm missing?
Things that could block a postgres connection:
misconfigured listen_address in postgresql.conf
selinux (?)
iptables
pg_hba.conf (although this should cause a different error, not server doesn't listen)
Can you connect to the server locally, if you ssh in and run psql?
On our internal dev servers, I just turn off selinux and iptables. This is a bad idea from a security standpoint, but it might serve as a temporary step to help you narrow down where the problem is.
You might need to change more than one configuration file. In your case, you probably need to edit pg_hba.conf, too. Search that file for "non-local connections".
I like to keep configuration files under version control. It's easier to recover from mistakes that way.
You probably need to restart the PostgreSQL server after making those changes.
After changing listen_addresses settings on the server, make sure to restart the PostgreSQL server (send SIGHUP to the postmaster process, with kill -HUP, etc).
Make sure that postgresql.conf port is set to 5432
Make sure that if a firewall is running on the server, that port 5432 is open for connections coming from the window's (client) machine you are using
Check pg_hba.conf to make sure that the subnet of your client machine is given access
Try using psql locally