1

我正在调试 Postgres 的“抱歉,已经有太多客户”问题,并且刚刚了解了该pg_stat_activity表。我注意到其中有很多悬空的空闲连接用于不存在的 PID,这里只是两个示例:

 datid |   datname    |  pid  | usesysid | usename  |            application_name             | client_addr | client_hostname | client_port |         backend_start         |          xact_start           |          query_start          |         state_change          | wait_event_type |     wait_event      | state  | backend_xid | backend_xmin |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   query                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |    backend_type     
-------+--------------+-------+----------+----------+-----------------------------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------------+---------------------+--------+-------------+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------
 32998 | clarity_test |  4700 |       10 | postgres |                                         | 172.19.0.1  |                 |       65056 | 2020-12-26 23:09:44.000108+00 |                               | 2020-12-26 23:09:47.41226+00  | 2020-12-26 23:09:47.439006+00 | Client          | ClientRead          | idle   |             |              | UPDATE "MQTTDevices" SET "numFailedPasswordsTried"=0 WHERE "id" = 6 RETURNING *                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | client backend  
 32998 | clarity_test |  4704 |       10 | postgres |                                         | 172.19.0.1  |                 |       65114 | 2020-12-26 23:09:45.435574+00 |                               | 2020-12-26 23:09:45.496313+00 | 2020-12-26 23:09:45.496469+00 | Client          | ClientRead          | idle   |             |              | UNLISTEN "MQTTDeviceChannels/deviceId/4"                                                                                                                                                            

我很可能用 Ctrl-C 杀死了创建这些连接的测试进程。

我必须从根本上误解一些东西,因为我本以为 Postgres 会发现套接字已损坏,然后关闭这些连接,并在必要时回滚事务。据我在https://dba.stackexchange.com/questions/81408/is-a-postgres-long-running-query-aborted-if-the-connection-is-lost-broken中阅读,当我终止这些进程我的操作系统应该在 TCP 套接字上发送 RST,而 Postgres 应该得到它。

我正在通过 Docker for Mac 运行 Postgres,我认为这不会以某种方式干扰这一点?

我不认为它应该有所作为,但我正在使用node-pg,一些通过池连接,另一些通过单个客户端实例(例如 for LISTEN)。

4

0 回答 0