Postgresql – several idle connections SET bytea_output

postgresql

i have a situation that i don't know if it is normal, i think not.

I have several idle connections with the query SET bytea_output='escape', so i arrive to max_connections and have issues with my applications, why are there so many connections idle with that query?

Best Answer

Many libraries which manage connections for you will execute some housekeeping queries on the new connection before returning it to the caller. SET bytea_output='escape' is just the type of housekeeping query you might expect to see.

So the likely explanation is that someone keeps asking for a new connections, and then immediately forgets about it without either using it or closing it. To figure out who, you should be looking at other fields of "pg_stat_activity", like usename, application_name, and client_addr.

And ultimately if you don't know who is connecting to your database, you should be changing the passwords or other authentication methods.