本文共 1211 字,大约阅读时间需要 4 分钟。
最近一次在给公司的数据库做优化,虽然数据库优化有很多点,这里主要是将对内存使用的优化部分进行总结。
关于PostgreSQL的内存单元设置在postgresql.conf文件里
属性wal_buffers,means how much memory to use for buffering write-ahead log data.
也可以登录数据库后,使用命令行方式:
也可以查询pg_settings表
首先是设置操作系统的share memory大小
使用LInux shared memory 增加buffer sizes。
设置方式是使用getconf命令,编写脚本,内容如下: #!/bin/bash # simple shmsetup script page_size='getconf PAGE_SIZE' phys_pages='getconf _PHYS_PAGES' shmall='expr $phys_pages / 2' shmmax='expr $shmall \* $page_size' echo kernel.shmmax = $shmmax echo kernel.shmall = $shmall 保存的文件名为shmsetup。 使之有效,需要增加到/etc/sysctl.conf文件里,使用命令如下: ./shmsetup >> /etc/sysctl.conf 查看shm状态,使用命令: sysctl -p 状态结果里有几个说明下: shmmax is the maximum size(in bytes) for a single shared memory segment. shmall is the total amount of shared memory(in pages) that all processes on the server can use. Kernel semaphores 使用命令:ipcs -l,结果如下:该命令主要是查看相关的限制信息,这里是全部的信息,包括share memory、semaphore、messages三块,在这里主要是查看semaphore的限制值。
也可以使用另一个命令查看如图: 总结如下: All four of the values here might need to be increased on systems with a large number of processes, setting the same way as the increased shared memory sizes. Estimating shared memory allocation PostgreSQL里有一套计算的方式,如图: 这部分主要是将如何去增加share memory,主要在配置文件里去处理。
转载地址:http://jpzob.baihongyu.com/