Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting OperationalError: FATAL: sorry, too many clients already using psycopg2

I am getting the error OperationalError: FATAL: sorry, too many clients already when using psycopg2. I am calling the close method on my connection instance after I am done with it. I am not sure what could be causing this, it is my first experience with python and postgresql, but I have a few years experience with php, asp.net, mysql, and sql server.

EDIT: I am running this locally, if the connections are closing like they should be then I only have 1 connection open at a time. I did have a GUI open to the database but even closed I am getting this error. It is happening very shortly after I run my program. I have a function I call that returns a connection that is opened like:

psycopg2.connect(connectionString)

Thanks

Final Edit: It was my mistake, I was recursively calling the same method on mistake that was opening the same method over and over. It has been a long day..

like image 451
Greg Avatar asked Feb 06 '09 06:02

Greg


3 Answers

This error means what it says, there are too many clients connected to postgreSQL.

Questions you should ask yourself:

  • Are you the only one connected to this database?
  • Are you running a graphical IDE?
  • What method are you using to connect?
  • Are you testing queries at the same time that you running the code?

Any of these things could be the problem. If you are the admin, you can up the number of clients, but if a program is hanging it open, then that won't help for long.

There are many reasons why you could be having too many clients running at the same time.

like image 99
WolfmanDragon Avatar answered Oct 18 '22 01:10

WolfmanDragon


Make sure your db connection command isn't in any kind of loop. I was getting the same error from my script until I moved my db.database() out of my programs repeating execution loop.

like image 43
SWiT Avatar answered Oct 18 '22 01:10

SWiT


It simple means many clients are making transaction to PostgreSQL at same time. I was running Postgis container and Django in different docker container. Hence for my case restarting both db and system container solved the problem.

like image 1
yubaraj poudel Avatar answered Oct 18 '22 02:10

yubaraj poudel