3

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?

4
  • Which operating system are you using?
    – user1822
    Jun 13, 2017 at 9:50
  • 2
    Which part of the HINT above seems unclear?
    – mustaccio
    Jun 13, 2017 at 11:20
  • We are using Linux as OS. Jun 16, 2017 at 11:38
  • Does the shared memory segment and shared_buffer value in config file are same? Jun 16, 2017 at 11:39

3 Answers 3

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).

4
  • Does this error leads to database shutdown? Jun 14, 2017 at 5:52
  • @Raghavendra yes, that's what FATAL means above it. Jun 16, 2017 at 0:44
  • Does the shared memory segment and shared_buffer value in config file are same? 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 settings Jun 16, 2017 at 14:40
0

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.