本节内容来源于PGer的一个问题:
Q:
为什么checkpointer后台进程使用这么多内存?
[pg12@localhost ~]$ ps -aux|grep postgres
pg12 1506 0.0 1.8 753156 34704 ? Ss 10:30 0:00 /appdb/xdb/pg12beta1/bin/postgres
pg12 1507 0.0 0.0 187304 1472 ? Ss 10:30 0:00 postgres: logger
pg12 1509 0.0 24.1 754120 452672 ? Ss 10:30 0:04 postgres: checkpointer
pg12 1510 0.0 28.4 753292 533184 ? Ss 10:30 0:08 postgres: background writer
pg12 1511 0.0 0.9 753260 18012 ? Ss 10:30 0:11 postgres: walwriter
pg12 1513 0.0 0.0 189420 1448 ? Ss 10:30 0:00 postgres: archiver last was 00000001000000020000005C
pg12 1514 0.0 0.0 189556 1324 ? Ss 10:30 0:00 postgres: stats collector
pg12 1515 0.0 0.1 753688 1984 ? Ss 10:30 0:00 postgres: logical replication launcher
pg12 2281 0.0 0.0 112660 972 pts/3 S+ 16:38 0:00 grep --color=auto postgres
[pg12@localhost ~]$ grep 'shared' $PGDATA/postgresql.conf
shared_buffers = 512MB # min 128kB
#shared_memory_type = mmap # the default is the first option
dynamic_shared_memory_type = posix # the default is the first option
#wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers
#shared_preload_libraries = '' # (change requires restart)
比如上例,共享内存设置为512MB,在2G内存的机器上,checkpointer和background writer进程占用了差不多25%的内存大小.
A:
resident” RAM of a postgres subprocess is often just be the fraction of shared_buffers it’s read/written. checkpointer must necessarily read all dirty pages from s-b and write out to disk (by way of page cache), so that’s why its RSS is nearly 32GB. And the recovery process is continuously writing into s-b.
原因是checkpointer和bg writer需要从shared memory中读取数据(从s-b到page cache)并刷到磁盘上,因此给人占用大量内存的假象.
参考资料
Re: checkpoint and recovering process use too much memory
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/6906/viewspace-2650715/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/6906/viewspace-2650715/