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

Actually set MEMORY_LIMIT_IN_BYTES based on cgroups limits #427

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 13 additions & 2 deletions src/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@
export POSTGRESQL_MAX_CONNECTIONS=${POSTGRESQL_MAX_CONNECTIONS:-100}
export POSTGRESQL_MAX_PREPARED_TRANSACTIONS=${POSTGRESQL_MAX_PREPARED_TRANSACTIONS:-0}

# Perform auto-tuning based on the container cgroups limits (only when the
# limits are set).
# Set MEMORY_LIMIT_IN_BYTES based on the container cgroups memory limits
# (only when the limits are set).
if [[ -f /sys/fs/cgroup/memory/memory.limit_in_bytes ]]; then
MEMORY_LIMIT_IN_BYTES=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)
elif [[ -f /sys/fs/cgroup/memory.max ]]; then
# CGroups v2
MEMORY_LIMIT_IN_BYTES=$(cat /sys/fs/cgroup/memory.max)
if [[ "${MEMORY_LIMIT_IN_BYTES}" == "max" ]]; then
unset MEMORY_LIMIT_IN_BYTES
fi
fi

# Perform auto-tuning based on MEMORY_LIMIT_IN_BYTES.
# Users can still override this by setting the POSTGRESQL_SHARED_BUFFERS
# and POSTGRESQL_EFFECTIVE_CACHE_SIZE variables.
if [[ "${NO_MEMORY_LIMIT:-}" == "true" || -z "${MEMORY_LIMIT_IN_BYTES:-}" ]]; then
Expand Down