Greg
Greg

Reputation: 7393

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..

Upvotes: 28

Views: 39273

Answers (3)

WolfmanDragon
WolfmanDragon

Reputation: 7952

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.

Upvotes: 20

yubaraj poudel
yubaraj poudel

Reputation: 3889

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.

Upvotes: 0

SWiT
SWiT

Reputation: 41

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.

Upvotes: 4

Related Questions