0

We have postgres 9.1 running on Ubuntu box. The postgres db size is 155GB and it has about 13200 tables. The Ubuntu box has 120GB RAM. The Ubuntu box is a docker container.

When an attempt to backup the db was made, it failed saying:

pg_dump: WARNING:  out of shared memory
pg_dump: SQL command failed
pg_dump: Error message from server: ERROR:  out of shared memory
HINT:  You might need to increase max_locks_per_transaction.

So we increased the value of max_locks_per_transaction to 1024 in postgresql.conf, but postgres wouldn't start.

root@abc:# /etc/init.d/postgresql restart
 * Restarting PostgreSQL 9.1 database server
 * The PostgreSQL server failed to start. Please check the log output:
2018-02-04 03:27:22 UTC FATAL:  could not create shared memory segment: Invalid argument
2018-02-04 03:27:22 UTC DETAIL:  Failed system call was shmget(key=5432001, size=70123520, 03600).
2018-02-04 03:27:22 UTC HINT:  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 70123520 bytes), reduce PostgreSQL's 
shared memory usage, perhaps by reducing shared_buffers or max_connections. If the request size is 
already small, it's possible that it is less than your kernel's SHMMIN parameter, in which case raising 
the request size or reconfiguring SHMMIN is called for. The PostgreSQL documentation contains more information 
about shared memory configuration.

So when we attempted to change the value of SHMMAX, it failed:

# echo 1134217728 >/proc/sys/kernel/shmmax
bash: /proc/sys/kernel/shmmax: Read-only file system

Any idea what's wrong and how to go about it?

Maddy
  • 101
  • 1

1 Answers1

0

The Ubuntu box is a docker container.

Containers set limits on memory, and use IPC namespaces, and the default shm limit is nowhere near large enough to run large databases. You will need to configure higher limits in the run command. If the container has more than one hundred GB of memory to use, you could set shm limit quite high, maybe 8 GB.

docker run -m 120G  --sysctl kernel.shmmax=8589934592 --sysctl kernel.shmall=2097152

PostgreSQL documentation on Managing Kernel Resources is a good reference, but does not mention containers.

John Mahowald
  • 32,050
  • 2
  • 19
  • 34