dokku / dokku-postgres

a postgres plugin for dokku

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature request] Add --shm-size option to postgres:create

turicas opened this issue · comments

The default /dev/shm size is 64MB and PostgreSQL can easily need more space if you're running queries with large results. The best way to solve this problem is to create the PostgreSQL container passing --shm-size=<greater-size> (as stated in "Caveats" section on docker postgres docs). The other option is not so simple: change container's ShmSize property - this is not supported by docker and requires some hacking and restarting docker daemon (which is not desirable).

If you're using Dokku and got an error like this:

ERROR:  could not resize shared memory segment "/PostgreSQL.2088012784" to 50438144 bytes: No space left on device

The only solution I've found needs docker service restarting:

PG_NAME="<your-docker-postgres-service-name>"
PG_CONTAINER_ID=$(docker inspect -f '{{ .ID }}' dokku.postgres.$PG_NAME)
PG_HOST_CONFIG=/var/lib/docker/containers/$PG_CONTAINER_ID/hostconfig.json
service docker stop
sed -i 's/"ShmSize":[0-9]\+,/"ShmSize":268435456,/' $PG_HOST_CONFIG
service docker start

Note: in the example above the /dev/shm is set to 256MB (268435456 bytes).

I also ran into this today. I ended up needing just over 1 gig for my DB.

You may also need to restart any deployed apps with dokku ps:restart app-name.

I needed to do that for nginx to work.

Same problem

ERROR: could not resize shared memory segment "/PostgreSQL.1657416213" to 8388608 bytes: No space left on device

☝️ As can be seen in the linked pull request, there is now an option available to set this when creating the database:

-s|--shm-size SHM_SIZE: override shared memory size for postgres docker container

This should probably be the preferred solution, at least for new containers 😉

Just leaving that here for future readers (and future me)