一、现象
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data/
LOG: loaded library "pg_stat_statements"
FATAL: could not create shared memory segment: Invalid argument
DETAIL: Failed system call was shmget(key=5432001, size=34381824, 03600).
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 34381824 bytes), reduce PostgreSQL's shared_buffers parameter (currently 3072) and/or its max_connections parameter (currently 254).
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.
二、解决方法
增大操作系统的共享内存段的大小
Linux
The default maximum segment size is 32 MB, which is only adequate for very small PostgreSQL
installations. The default maximum total size is 2097152 pages. A page is almost always 4096
bytes except in unusual kernel configurations with “huge pages” (use getconf PAGE_SIZE to
verify). That makes a default limit of 8 GB, which is often enough, but not always.
The shared memory size settings can be changed via the sysctl interface. For example, to allow
16 GB:
$ sysctl -w kernel.shmmax=17179869184
$ sysctl -w kernel.shmall=4194304
In addition these settings can be preserved between reboots in the file /etc/sysctl.conf.
Doing that is highly recommended.
Ancient distributions might not have the sysctl program, but equivalent changes can be made
by manipulating the /proc file system:
$ echo 17179869184 >/proc/sys/kernel/shmmax
$ echo 4194304 >/proc/sys/kernel/shmall
The remaining defaults are quite generously sized, and usually do not require changes.