如何释放客户端应用程序未正确关闭的PostgreSQL连接?
我有一个数据挖掘应用程序,它启动多个进程,所有连接到本地PostgreSQL 9.1数据库以检索数据。它可以正常运行几个小时,但是由于以下错误而死亡:
FATAL: remaining connection slots are reserved for non-replication superuser connections
对此进行研究表明,这很可能是由于应用程序未正确关闭其连接引起的。但是,即使终止了该应用程序,也永远不会释放这些连接。PostgreSQL是否会自动关闭连接?
我还尝试将Postgres的max_connections从100增加到200,但是重新启动给了我错误:
2014-02-23 10:51:15 EST FATAL: could not create shared memory segment: Invalid argument
2014-02-23 10:51:15 EST DETAIL: Failed system call was shmget(key=5432001, size=36954112, 03600).
2014-02-23 10:51:15 EST HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter. You can either reduce the request size or reconfigure the kernel with larger SHMMAX. To reduce the request size (currently 36954112 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
If the request size is already small, it's possible that it is less than your kernel's SHMMIN parameter, in which case raising the request size or reconfiguring SHMMIN is called for.
The PostgreSQL documentation contains more information about shared memory configuration.
我的系统是Ubuntu 12.04,具有8GB内存,所有其他PG设置均为默认设置,因此我不确定为什么它认为系统没有足够的内存。
然后,我尝试使用pgbouncer合并和重用连接。这似乎工作得更好,但即使最终最终用尽了连接,也给了我错误:
ERROR: no more connections allowed
如何进一步诊断和解决此问题?
显示pg_stat_activity的输出
—
ETL