On a 7.5 GB host (Ubuntu 16.04.5 LTS), I have allocated 3 GB to
postgres=# SHOW shared_buffers; shared_buffers ---------------- 3GB (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
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  FATAL: could not map anonymous shared memory: Cannot allocate memory 2018-09-27 09:31:54.397 BST  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  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?