postgres 中的max_connection

本文介绍了解决PostgreSQL启动时报错“couldnotcreatesemaphores:Nospaceleftondevice”的方法。通过调整max_connections参数及相关的内核参数如SEMMNI、SEMMNS等,确保PostgreSQL能够正确启动并支持所需的最大连接数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

postgres中的max_connection和mysql、oracle一样,是限制数据库服务器的最大连接数的,但是在postgres中,当max_connect设置过大,启动的时候会报错:

[postgres@localhost ~]$ FATAL:  could not create semaphores: No space left on device
DETAIL:  Failed system call was semget(1949125, 17, 03600).

创建semaphores时空间参数不够,查询官网,对这个错误有这么一段解释:

HINT:  This error does *not* mean that you have run out of disk space.  It occurs when either the system limit for the maximum number of semaphore sets (SEMMNI), or the system wide maximum number of semaphores (SEMMNS), would be exceeded.  You need to raise the respective kernel parameter.  Alternatively, reduce PostgreSQL's consumption of semaphores by reducing its max_connections parameter.
The PostgreSQL documentation contains more information about configuring your system for PostgreSQL.
解决的方法是改小max_connect,当业务不允许的情况下,修改内核参数,max_connect相关的内核参数有:
NameDescriptionReasonable values
SHMMAX Maximum size of shared memory segment (bytes) at least several megabytes (see text)
SHMMIN Minimum size of shared memory segment (bytes) 1
SHMALL Total amount of shared memory available (bytes or pages) if bytes, same as SHMMAX; if pages, ceil(SHMMAX/PAGE_SIZE)
SHMSEG Maximum number of shared memory segments per process only 1 segment is needed, but the default is much higher
SHMMNI Maximum number of shared memory segments system-wide like SHMSEG plus room for other applications
SEMMNI Maximum number of semaphore identifiers (i.e., sets) at least ceil((max_connections + autovacuum_max_workers + 4) / 16)
SEMMNS Maximum number of semaphores system-wide ceil((max_connections + autovacuum_max_workers + 4) / 16) * 17 plus room for other applications
SEMMSL Maximum number of semaphores per set at least 17
SEMMAP Number of entries in semaphore map see text
SEMVMX Maximum value of semaphore at least 1000 (The default is often 32767; do not change unless necessary)
设置方法按照表格中的公式


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值