Linux shmmax 和 shmall - 如何设置正确的单位?

标签 linux postgresql ubuntu sysctl

我有一台内存为 16 GB 的服务器。

现在我需要设置我的 shmmaxshmall,因为服务器默认是(用 ipcs -l 检查)

------ Messages Limits --------
max queues system wide = 32000
max size of message (bytes) = 8192
default max size of queue (bytes) = 16384
------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 18014398509465599
max total shared memory (kbytes) = 18014398509465599
min seg size (bytes) = 1

------ Semaphore Limits --------
max number of arrays = 32000
max semaphores per array = 32000
max semaphores system wide = 1024000000
max ops per semop call = 500
semaphore max value = 32767

看起来很糟糕,shmallshmmax 比我的 16 GB 还大。

所以我想把设置改成

shmmax -> 16GB/4
shmall -> 16GB/2

但我不能确定我设置的是什么单位

shmmax --> 4420960256 
shmall --> 8620960256

但是我的号码是单位吗?字节还是KB? 因为 ipcs -l 正在显示 KB....

echo "kernel.shmmax=4420960256" >> /etc/sysctl.conf
echo 4420960256> /proc/sys/kernel/shmmax
echo "kernel.shmall=8620960256" >> /etc/sysctl.conf
echo 8620960256> /proc/sys/kernel/shmall

感谢您的帮助,但 postgresql 刚刚崩溃并在昨天被杀死,它显示:

This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 4420960256 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.

我的设置=>

shared_buffers = 4GB
effective_cache_size = 12GB

最佳答案

只需使用:

lsipc

在我的 Ubuntu 16.04 LTS 上我得到:

RESOURCE DESCRIPTION                                    LIMIT USED  USE%
MSGMNI   Number of message queues                       32000    0 0.00%
MSGMAX   Max size of message (bytes)                     8192    -     -
MSGMNB   Default max size of queue (bytes)              16384    -     -
SHMMNI   Shared memory segments                          4096   20 0.49%
SHMALL   Shared memory pages                          2097152 4915 0.23%
SHMMAX   Max size of shared memory segment (bytes) 4294967296    -     -
SHMMIN   Min size of shared memory segment (bytes)          1    -     -
SEMMNI   Number of semaphore identifiers                  128    0 0.00%
SEMMNS   Total number of semaphores                     32000    0 0.00%
SEMMSL   Max semaphores per semaphore set.                250    -     -
SEMOPM   Max number of operations per semop(2)            100    -     -
SEMVMX   Semaphore max value                            32767    -     -

它清楚地说明了我在 /etc/sysctl.conf 中指定的值的度量单位。所以对我来说 SHMMAX 以字节为单位,而 SHMALL 以页为单位(参见 getconf PAGE_SIZE)。

关于Linux shmmax 和 shmall - 如何设置正确的单位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52751256/

相关文章:

java - 如何从 Bash shell 脚本优雅地关闭 Java 服务?

java - pg_dump ProcessBuilder 中的参数太多

java - IS NOT NULL 总是返回真 JPA 查询

linux - Redshift 打开和关闭(闪烁)

linux - 类 Unix 平台的 FTP GUI 客户端,支持 TLS/SSL/SFTP

ruby - 在 nginx 和 thin 下部署 Sinatra 应用程序的最快技巧(当然是 linux)

c - 源代码使用/包含方案生成器

postgresql - 如何从 RowDescription 消息中查看 PostgreSQL 列类型?

c++ - ld 找不到 glfw3

linux - 如何安装具有 GUI(gnome、kde 等)的 Vagrant Linux 机器?