Postgresql FATAL: could not create semaphores: No space left on device


昨天安裝完成pg 9.5后,啟動報錯:

FATAL:  could not create semaphores: No space left on device
DETAIL:  Failed system call was semget(xxxxxxxxxx).
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.
 
查看報錯日志是由於內核的相關配置參數設置過小引起的。
 
這里是共享內存段的限制,簡單介紹一下
如果數據庫報FATAL: could not create shared memory segment:Cannot allocate memory 錯誤,可以考慮修改以下相關參數
#ipcs -lm
------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 67108864
max total shared memory (kbytes) = 17179869184
min seg size (bytes) = 1
 
#cat  /proc/sys/kernel/shmmax
68719476736

SHMMAX 單個共享內存段最大字節數

 
# cat  /proc/sys/kernel/shmmni
4096

SHMMNI 共享內存段最大個數 

 
# cat  /proc/sys/kernel/shmall
4294967296

SHMALL系統中共享內存也總數,至少為ceil(shmmax/PAGE_SIZE)

 
獲取page_size值
# getconf PAGE_SIZE
4096

可以根據實際情況修改以上參數值,在/etc/sysctl.conf配置文件中

 今天遇到的錯誤,主要解決以下參數的限制才能解決我們數據庫啟動的報錯
# ipcs -ls
 
------ Semaphore Limits --------
max number of arrays = 1280
max semaphores per array = 50100
max semaphores system wide = 64128000
max ops per semop call = 50100
semaphore max value = 32767
 
 
# cat  /proc/sys/kernel/sem
SEMMSL   SEMMNS         SEMOPM  SEMMNI
50100   128256000       50100   2560
SEMMSL 每個信號量set中信號量最大個數
SEMMNS linux系統中信號量最大個數
SEMOPM semop系統調用允許的信號量最大個數設置,設置成和SEMMSL一樣即可
SEMMNI  linux系統信號量set最大個數
 
所以SEMMNS=SEMMSL*SEMMNI
 
所以要么增大信號量,要么減少max_connect參數
這里我選擇增大信號量
 
修改 vi /etc/sysctl.conf 的以下參數
kernel.sem = 50100 128256000 50100 2560
 
ipcs -ls
 
------ Semaphore Limits --------
max number of arrays = 2560
max semaphores per array = 50100
max semaphores system wide = 128256000
max ops per semop call = 50100
semaphore max value = 32767
 
重新啟動數據庫后無報錯,數據庫可以正常啟動。
 
下面是官方文檔中對s emaphores相關參數的說明:
 
Name Description Reasonable values
SHMMAX Maximum size of shared memory segment (bytes) at least 1kB (more if running many copies of the server)
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 + max_worker_processes + 5) / 16)
SEMMNS Maximum number of semaphores system-wide ceil((max_connections + autovacuum_max_workers + max_worker_processes + 5) / 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)
 
 
參考:
http://blog.163.com/dazuiba_008/blog/static/363349812016314739538/
http://www.postgresql.org/docs/9.4/static/kernel-resources.html#SYSVIPC-PARAMETERS


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM