我试图弄清楚为什么〜30个空闲的postgres进程在正常使用后会占用如此多的进程特定内存。我正在使用 Postgres 9.3.1 和 CentOS 版本 6.3(最终版)。使用top
,我可以看到许多 postgres 连接正在使用高达 300mb(平均 ~200mb)的非共享(RES - SHR)内存:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3534 postgres 20 0 2330m 1.4g 1.1g S 0.0 20.4 1:06.99 postgres: deploy mtalcott 10.222.154.172(53495) idle
9143 postgres 20 0 2221m 1.1g 983m S 0.0 16.9 0:14.75 postgres: deploy mtalcott 10.222.154.167(35811) idle
6026 postgres 20 0 2341m 1.1g 864m S 0.0 16.4 0:46.56 postgres: deploy mtalcott 10.222.154.167(37110) idle
18538 postgres 20 0 2327m 1.1g 865m S 0.0 16.1 2:06.59 postgres: deploy mtalcott 10.222.154.172(47796) idle
1575 postgres 20 0 2358m 1.1g 858m S 0.0 15.9 1:41.76 postgres: deploy mtalcott 10.222.154.172(52560) idle
总共大约有 29 个空闲连接。这些空闲连接在内存中不断增长,直到机器开始使用交换,然后性能停止。正如预期的那样,重置连接会清除特定于进程的内存。当我定期重新连接时,同一台机器上相同数量的连接仅使用 20% 的内存(交换为 0)。这些过程保存了什么样的信息?我希望长时间运行的空闲 postgres 进程与全新的空闲进程具有相似的内存使用情况。
值得注意的是:我大量使用模式。在对我的应用程序的每个请求中,我都在设置和重置 search_path。