The startup sequence
When the server process is started allocates the shared segment in memory. In the versions before the 9.3 this was the a potential point of failure because, if the shared_buffers was bigger than the kernel's max allowed shared memory segment the startup will fail with this sort of error
FATAL: could not create shared memory segment: Cannot allocate memory DETAIL: Failed system call was shmget(key=X, size=XXXXXX, XXXXX). 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 XXXXX bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.In this case the kernel parameters needs adjustment. As from my Oracle experience I take no chance and I do use the values suggested for an Oracle installation which incidentally works perfectly for PostgreSQL.
kernel.shmall = 2621440 kernel.shmmax = 18253611008 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 fs.file-max = 658576Put those values into the file /etc/sysctl.conf and, as root, run sysctl -p.
The latest major version PostgreSQL switched from the SysV to Posix shared memory and mmap. This solved completely the shared memory tuning on Linux.
When the memory is allocated the postmaster reads the pg_control file to check if the instance requires recovery.
The pg_control contains references to the last checkpoint and the last known status for the instance.
If the instance is in dirty state, because a crash or an unclean shutdown, the startup replays the blocks from the WAL segments in the pg_xlog directory starting from the last checkpoint position read from the pg_control file.
Any corruption in the wal files or, even worse, the pg_control file results in a not startable instance.
After the recovery is complete or the cluster is in clean state, then the startup completes opening the database in production state.