26

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

Greg
  • 7,233
  • 12
  • 42
  • 53

3 Answers3

19

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.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
WolfmanDragon
  • 7,851
  • 14
  • 49
  • 61
3

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.

SWiT
  • 31
  • 1
0

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.

yubaraj poudel
  • 3,821
  • 1
  • 31
  • 28