diff --git a/docker-compose.yml b/docker-compose.yml index 0487c93..abcb184 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/set_storage_retention.sh b/set_storage_retention.sh index 1b81f2e..986397d 100755 --- a/set_storage_retention.sh +++ b/set_storage_retention.sh @@ -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=""