On a 7.5 GB host (Ubuntu 16.04.5 LTS), I have allocated 3 GB to shared_buffers:

postgres=# SHOW shared_buffers;
(1 row)


postgres@my-host:~$ cat /etc/postgresql/10/main/postgresql.conf | grep shared_buffers
shared_buffers = 3072MB         # min 128kB, valid units are kB, MB, GB, TB

I have also configured my host with HP as:

postgres@my-host:~$ cat /proc/meminfo | grep ^Huge
HugePages_Total:    1600
HugePages_Free:     1600
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

With a Hugepagesize at 2048 kB, that works out as 1600*2048/1024 = 3200 MB of HP. When I then try to turn:

postgres@raeflightcachemaster0-nonprod:~$ cat /etc/postgresql/10/main/postgresql.conf | grep huge_pages
huge_pages = on

PostgreSQL (10.5) is reporting:

2018-09-27 09:31:54.397 BST [16739] FATAL:  could not map anonymous shared memory: Cannot allocate memory
2018-09-27 09:31:54.397 BST [16739] HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 3523592192 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
2018-09-27 09:31:54.397 BST [16739] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.

and the DB server fails to start.

My question is, where is it getting the number 3523592192 bytes from? This value does not match the shared_buffers = 3072MB setting in postgresql.conf as it works out as 3523592192/1024/1024 = 3360.359375 MB. I get around the problem by increasing HugePages_Total slightly to 1700 so that we have 3400 MB of HP but I don't understand the discrepancy between the reported value of shared_bufferes and the configured value. Is this a units issue?

  • Did you notice the " perhaps by reducing shared_buffers or max_connections" ? Sep 27, 2018 at 11:02
  • What do you have as work_mem and max_connections. Does the product of the two approach 300Mb ? Sep 27, 2018 at 11:10
  • @GerardH.Pille, I was focusing on shared_buffers and missed max_connections but max_connections * work_mem >> 300 MB at 16400 MB.
    – dw8547
    Sep 27, 2018 at 11:19
  • 1
    work_mem is irrelevant here. It is allocated in backend-private memory, not shared memory. It is max_locks_per_transaction and few others that are allocated in shared memory scaled for max_connections.
    – jjanes
    Sep 29, 2018 at 21:10
  • 1
    @dw8547 I'm not aware of any place that pulls this all together. The exact sizes are going to change from OS/hardware platform to platform, as well as from PostgreSQL version to version. There are ~31 functions named ending in "ShmemSize" located in src/backend/storage/ipc/ipci.c which would be the place to look.
    – jjanes
    Oct 1, 2018 at 22:28


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.