feat: dynamically set shm

Set a higher SHM if there's 4GB+ of RAM on the host.

Attempting to fix DRIVER_ERROR encountered in the wild.
This commit is contained in:
fryorcraken 2024-10-29 12:07:09 +11:00
parent 7f1e11f86d
commit 4a24932922
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 18 additions and 4 deletions

View File

@ -112,7 +112,7 @@ services:
# and the store-message-db-url is set to use Postgres
image: postgres:15.4-alpine3.18
restart: on-failure:5
shm_size: '1g' # Set shared memory size to 1 GB
shm_size: "${POSTGRES_SHM:-1g}" # Set default shared memory size to 1 GB
environment:
<<: *pg_env
volumes:

View File

@ -54,10 +54,24 @@ fi
# check if STORAGE_SIZE is already specified
if [ -f "./.env" ]; then
. ./.env
if [ -n "$STORAGE_SIZE" ]; then
>&2 echo "STORAGE_SIZE is specified in .env file, doing nothing"
exit 0
fi
# Set PostgreSQL container Shared Memory value
if [ -z "${POSTGRES_SHM}" ]; then
TOTAL_MEM_MB=$(free -m|grep Mem| awk '{ print $2 }')
if [ "${TOTAL_MEM_MB}" -ge 4096 ]; then
# Allocate 2GB of Shared Memory for Postgres if machine has more than 4GB RAM
POSTGRES_SHM='2g'
echo "Setting PostgreSQL container SHM to ${POSTGRES_SHM}"
echo "POSTGRES_SHM=${POSTGRES_SHM}" >> .env
fi
else
>&2 echo "POSTGRES_SHM is already specified in .env file"
fi
if [ -n "$STORAGE_SIZE" ]; then
>&2 echo "STORAGE_SIZE is specified in .env file, doing nothing"
exit 0
fi
SUDO=""