Recently my client database has restarted and thrown the below error.
FATAL: could not create shared memory segment: Cannot allocate memory
DETAIL: Failed system call was shmget(key=5433001, size=5616156672, 03600).
HINT: This error usually means that PostgreSQL's request for a shared memory segment
exceeded available memory or swap space, or exceeded your kernel's SHMALL
parameter. You can either reduce the request size or reconfigure the kernel with
larger SHMALL. To reduce the request size (currently 5616156672 bytes), reduce
PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or
max_connections.
The PostgreSQL documentation contains more information about shared memory configuration.
LOG: database system was interrupted; last known up at 2017年06月07日 08:10:13 BST
FATAL: the database system is starting up
FATAL: the database system is starting up
How can I resolve this issue?
3 Answers 3
The HINT seems pretty clear,
This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel's SHMALL parameter. You can either reduce the request size or reconfigure the kernel with larger SHMALL. To reduce the request size (currently 5616156672 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
Redhat has really good docs on SHMALL
. The sysctl
method is the new method.
sysctl -w kernel.shmall=5616156672
See man sysctl
. These changes do not persist through reboot. Pay attention to the bottom, to make the change permanent,
echo "kernel.shmall=5616156672" >> /etc/sysctl.conf
Also note the top which is great generic advice This parameter sets the total amount of shared memory pages that can be used system wide. Hence, SHMALL should always be at least ceil(shmmax/PAGE_SIZE).
-
Does this error leads to database shutdown?Raghavendra– Raghavendra2017年06月14日 05:52:45 +00:00Commented Jun 14, 2017 at 5:52
-
@Raghavendra yes, that's what
FATAL
means above it.Evan Carroll– Evan Carroll2017年06月16日 00:44:19 +00:00Commented Jun 16, 2017 at 0:44 -
Does the shared memory segment and shared_buffer value in config file are same?Raghavendra– Raghavendra2017年06月16日 11:39:33 +00:00Commented Jun 16, 2017 at 11:39
-
No "shared memory segment" is a request, it has no config file. You only make that request is shared_buffers is too large for your kernel settingsEvan Carroll– Evan Carroll2017年06月16日 14:40:58 +00:00Commented Jun 16, 2017 at 14:40
If you are running PostgreSQL 9.2 or earlier, it's likely you will have to increase the amount of memory your operating system allows you to allocate at once to set the value for shared_buffers this high. On UNIX-like systems, if you set it above what's supported, you'll get a message like this:
IpcMemoryCreate: shmget(key=5432001, size=415776768, 03600) failed: Invalid argument
This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter. You can either reduce the request size or reconfigure the kernel with larger SHMMAX. To reduce the request size (currently 415776768 bytes), reduce PostgreSQL's shared_buffers parameter (currently 50000) and/or its max_connections parameter (currently 12).
Refer below link for more details to know about this issue under "Shared_Bufferd" Section.
https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server
In my case it was postgresql.auto.conf
file I've created myself with the ALTER SYSTEM
command. Cleaning up this file contents reset settings to system default and error fixed.
HINT
above seems unclear?