From 00ec781b6822c810dc50093f66683d03cb4e19f8 Mon Sep 17 00:00:00 2001 From: Simon L Date: Sat, 21 Oct 2023 15:40:57 +0200 Subject: [PATCH 1/2] postgresql - close idling sessions automatically Signed-off-by: Simon L --- Containers/postgresql/start.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Containers/postgresql/start.sh b/Containers/postgresql/start.sh index 8d5f7b05081..7fb3b8f1d13 100644 --- a/Containers/postgresql/start.sh +++ b/Containers/postgresql/start.sh @@ -155,10 +155,14 @@ if [ -f "/var/lib/postgresql/data/postgresql.conf" ]; then sed -i "s|^max_connections =.*|max_connections = $MAX_CONNECTIONS|" "/var/lib/postgresql/data/postgresql.conf" fi - # Modify conf + # Do not log checkpoints if grep -q "#log_checkpoints" /var/lib/postgresql/data/postgresql.conf; then sed -i 's|#log_checkpoints.*|log_checkpoints = off|' /var/lib/postgresql/data/postgresql.conf fi + # Close idling connections automatically after 3s which does not seem to happen automatically so that we run into max_connections limits + if grep -q "#idle_session_timeout" /var/lib/postgresql/data/postgresql.conf; then + sed -i 's|#idle_session_timeout.*|idle_session_timeout = 3000|' /var/lib/postgresql/data/postgresql.conf + fi fi # Catch docker stop attempts From 416f50b70c52acd8db341bdee5321e7dc79f6e81 Mon Sep 17 00:00:00 2001 From: Simon L Date: Thu, 26 Oct 2023 18:26:05 +0200 Subject: [PATCH 2/2] do not go lower than 100 connections Signed-off-by: Simon L --- Containers/postgresql/start.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Containers/postgresql/start.sh b/Containers/postgresql/start.sh index 7fb3b8f1d13..cef78c1020b 100644 --- a/Containers/postgresql/start.sh +++ b/Containers/postgresql/start.sh @@ -152,6 +152,10 @@ if [ -f "/var/lib/postgresql/data/postgresql.conf" ]; then MEMORY=$(awk '/MemTotal/ {printf "%d", $2/1024}' /proc/meminfo) MAX_CONNECTIONS=$((MEMORY/50+3)) if [ -n "$MAX_CONNECTIONS" ]; then + # 100 is the default, we do not want to go lower than this + if [ "$MAX_CONNECTIONS" -lt 100 ]; then + MAX_CONNECTIONS=100 + fi sed -i "s|^max_connections =.*|max_connections = $MAX_CONNECTIONS|" "/var/lib/postgresql/data/postgresql.conf" fi