PostgreSQL Connection Error once in a while - postgresql

Once in a while I face these errors in Postgres.
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
and
org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
My database will work when I restart the server after getting this error.

You could post more about your setup - language and libraries (I suppose it's Java and JDBC), server version, what's its purpose (development or production) etc.
The second error you get is very clear - you exceed the configured number of connections to the server. Check the "max_connections" parameter in the server's configuration and increase it if you have the resources.
The first error AFAICS is a general connection error. I have no idea what could cause this (save for the server crash which I doubt is the case).

Related

Troubleshoot org.postgresql.util.PSQLException: Connection attempt timed out that only occasionally happens

I have several applications running on tomcat with a local PostgresSQL database. And tomcat occasionally reports the following errors:
org.postgresql.util.PSQLException: Connection attempt timed out.
I am able to connect to the database using other tools such as DBeaver. And this problem looks only happens when several applications are connecting to the database. So I want to know how to troubleshoot this issue. Is there any log in PostgresSQL that I can check?
PostgreSQL does have logging. It is very configurable, and we can't tell you how you have it configured. Common locations are /var/log/postgresql/, and in PGDATA/log/. However, a connection timeout will probably not be in the postgresql log as it probably never achieved contact with the postgresql server to start with.

Exception raised when try to run web application using postgres database

when I run start.bat file of tomcat on linux with postgres database. It gives following error after changed in postgres_hba.conf file.
C3P0PooledConnectionPoolManager[identityToken->2u13c99u1fd86im176rze7|779becbd]-HelperThread-#1--WARN -com.mchange.v2.resourcepool.BasicResourcePool:com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask#1de8b573 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
org.postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication superuser connections
The error message is fairly clear. You have tried to open more database connections than you have configured in postgresql.conf. Even the shortest search of your logs and the manuals would have made this clear.

No buffer space available

I am using an application in Yii and postgres database. When i run the application on live server(not local system) i am getting this error
"CDbConnection failed to open the DB connection: SQLSTATE[08006] [7] could not connect to server: No buffer space available (0x00002747/10055)
Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?"
I have 5 active client database. The error not showing every time. How to solve this problem..?
This error message is thrown by PostgreSQL when a Winsock operation returns the error WSAENOBUFS.
Microsoft describes the error as:
No buffer space available.
An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.
It is a problem of the Windows operating system. I don't know a lot about Windows, but it sounds like a resource shortage.
Maybe there are too many open TCP connections?

Heroku PostgreSQL Connection reset by peer

We are using PostgreSQL Crane plan, and got a lot of log like this
app postgres - - [5-1] ... LOG: could not receive data from client: Connection reset by peer
We are using about 50 dynos.
Is PostgreSQL running out of connections with bunch of dynos?
Can someone help me explain this case?
Thanks
From what I've found the cause for the errors is the client not disconnecting at the end of the session, or a new connection not being created.
New connection solving the problem:
Postgres error on Heroku with Resque
Explicit disconnection solving the problem:
https://github.com/resque/resque/issues/367 (comment #2)
There's a Heroku FAQ entry on this: Understanding Heroku Postgres Log Statements and Common Errors: could not receive data from client: Connection reset by peer.
Although this log is emitted from postgres, the cause for the error has nothing to do with the database itself. Your application happened to crash while connected to postgres, and did not clean up its connection to the database. Postgres noticed that the client (your application) disappeared without ending the connection properly, and logged a message saying so.
If you are not seeing your application’s backtrace, you may need to ensure that you are, in fact, logging to stdout (instead of a file) and that you have stdout sync’d.

Database connection error with Postgres & Movable Type

I'm trying to set up MovableType 4.34 using a Postgres database, and I'm getting the following (unhelpful) error message:
Connection error: authentication method 7 not supported
The database server doesn't support SSL connections, so I suspect that's to blame -- but I can't be sure (what is "authentication method 7" ?), and at any rate it's not clear to me how to see if MT is trying to use SSL connections for the database or not. Any ideas?
Did you turn on SSL in postgresql.conf? Just check it using this query:
SHOW ssl;
You have to check pg_hba.conf as well, hostssl needs a proper setting.