set max connections and max php children based on available hardware

Signed-off-by: szaimen <szaimen@e.mail.de>
This commit is contained in:
szaimen 2022-08-17 19:10:54 +02:00
parent b307c39f70
commit 5804f68824
4 changed files with 18 additions and 6 deletions

View file

@ -1,7 +1,7 @@
# From https://github.com/docker-library/postgres/blob/master/13/alpine/Dockerfile
FROM postgres:14.5-alpine
RUN apk add --update --no-cache bash openssl shadow netcat-openbsd grep
RUN apk add --update --no-cache bash openssl shadow netcat-openbsd grep mawk
# We need to use the same gid and uid as on old installations
RUN set -ex; \

View file

@ -110,6 +110,11 @@ if ! [ -f "$DATADIR/PG_VERSION" ] && ! [ -f "$DUMP_FILE" ]; then
rm -rf "${DATADIR:?}/"*
fi
echo "Setting max connections..."
MEMORY=$(mawk '/MemTotal/ {printf "%d", $2/1024}' /proc/meminfo)
MAX_CONNECTIONS=$((MEMORY/50+3))
sed -i "s|^max_connections =.*|max_connections = $MAX_CONNECTIONS|" "/var/lib/postgresql/data/postgresql.conf"
# Catch docker stop attempts
trap 'true' SIGINT SIGTERM