How to fix PostgreSQL installation

You need to increase the maximum size of a chunk of shared memory Linux kernel allows to allocate at once (known as SHMMAX parameter)

You need to edit /etc/sysctl.conf and add the following line:

kernel.shmmax = 41943040

(where 41943040 is the size of memory in bytes, i.e. 40 megabytes. On production system you probably want to set this value way higher - Postgres documentation recommends to start with 1/4 of available memory)

Then run

sudo sysctl -p

and restart postgres again.

Alternatively, you can edit /etc/postgresql/<version>/main/postgresql.conf and reduce the value of shared_buffers parameter.

This is a bug, more info here

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/264336

(there's also /etc/sysctl.d/30-postgresql-shm.conf file which is supposed to be used for this purpose but it doesn't seem to be included from the main config so editing it has no effect)