postgresql 获取 OperationalError: FATAL: 抱歉,已经有太多客户在使用 psycopg2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/519296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:39:03  来源:igfitidea点击:

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

pythonpostgresqlpsycopg2

提问by Greg

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.

我收到错误 OperationalError: FATAL: 抱歉,使用 psycopg2 时已经有太多客户端了。完成后,我在我的连接实例上调用 close 方法。我不确定是什么原因造成的,这是我第一次使用 python 和 postgresql,但我有几年使用 php、asp.net、mysql 和 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:

编辑:我在本地运行它,如果连接像它们应该的那样关闭,那么我一次只打开 1 个连接。我确实有一个对数据库打开的 GUI,但即使关闭我也收到此错误。在我运行我的程序后不久就会发生这种情况。我有一个我调用的函数,它返回一个打开的连接,如:

psycopg2.connect(connectionString)

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

最终编辑:这是我的错误,我在一遍又一遍地打开相同方法的错误中递归调用相同的方法。这是一个漫长的一天..

采纳答案by WolfmanDragon

This error means what it says, there are too many clients connected to postgreSQL. 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.

这个错误意味着它所说的,连接到 postgreSQL 的客户端太多。你是唯一一个连接到这个数据库的人吗?你在运行图形 IDE 吗?你用什么方法连接?您是否在运行代码的同时测试查询?这些事情中的任何一个都可能是问题所在。如果您是管理员,则可以增加客户端的数量,但如果某个程序将其挂起,那么这将无济于事。

There are too many reasons that you could be having too many clients running at the same time with the sparse info that you gave us.

有太多原因可能会导致太多客户端同时运行,而您提供给我们的信息却很少。

回答by SWiT

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.

确保您的 db connection 命令不在任何类型的循环中。在我将 db.database() 移出重复执行循环的程序之前,我的脚本出现了相同的错误。