Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dynamically set shm #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 17 additions & 3 deletions set_storage_retention.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +59 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snippet seems not to be related to storage retention so I'd suggest moving it to a separate script


if [ -n "$STORAGE_SIZE" ]; then
>&2 echo "STORAGE_SIZE is specified in .env file, doing nothing"
exit 0
fi

SUDO=""
Expand Down