Getting OperationalError: FATAL: sorry, too many clients already using psycopg2
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.
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.
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.