Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u1h8T-006Z1Z-HP for pgsql-performance@arkaria.postgresql.org; Mon, 07 Apr 2025 07:43:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u1h8R-00DAZz-Du for pgsql-performance@arkaria.postgresql.org; Mon, 07 Apr 2025 07:43:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u1Qcv-00ENzt-PF for pgsql-performance@lists.postgresql.org; Sun, 06 Apr 2025 14:05:34 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u1Qcu-003IQp-0m for pgsql-performance@postgresql.org; Sun, 06 Apr 2025 14:05:33 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-ac41514a734so614143766b.2 for ; Sun, 06 Apr 2025 07:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743948331; x=1744553131; darn=postgresql.org; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=XLZ7H/FcuhxoKPWHQ7LCppP+rhkkgyJGsbJHu1KMGZE=; b=muNysYrf2SwKeLBFllpaZoqPhvZ0aZCTjKX5o8amplYdwsTRyIapxHJHPfJTonxIMu a4Z2cV9yUArs2dFETu5xtAk/jsZ/kM5mo+lSORwNI4pJ80AqvfjBM2FsbHHgV5oqjXc+ zu7iA2j6A59LAUlWGx/Ec12YzE0Y561XJt10+nsr+U/rDYaC1bcpbuIpMJ1J5cxjBxhB CW6qhWnu1+SlMemFfdC/Vp+hlp5kXTiCLP7bnki97n49PMAMQZQPrJJiWn3L8e1nOKVf UAOc8alcbj7DhO7SGaEsuRTIiVk7V3GS5pqKEikgjRz4Fbpsb9ubOo8tMGDaz474aqKO sBcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743948331; x=1744553131; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XLZ7H/FcuhxoKPWHQ7LCppP+rhkkgyJGsbJHu1KMGZE=; b=Q16g35RYueOy0wl1fz7NrCbATrYcagLQ0Snkv0apGavIoNW4+BjdZw7KMHZukkOgwd kSjFpZHf/EvU6ntOmhuvKGbVbPAAwGJ4bAMfd9pkPQkbulvxlvRcWQkhk1NkWhhn5Wrh oaARaUrL4krRfbhGIzBomDCOYauPkhjlV7NSeBt+dfr7YyOMuvBgf1acayrj7s6q66aE /cP/I8b3UYztU97Mhdz0dddTT4aGICQRCrOGmfTUyR5KkdRgW6MnWXtEvLVk6Eq4+T9x zVbP8THfMXWNRMU+oJSaWe/Wi9Z1Quh7gSLNifvKHaQSW7PGs4PZmiGtGve6GvRilAQl IReg== X-Gm-Message-State: AOJu0YxjsfrBPg27lMUoIbboSTm4FUvEDVYcCXthS1XcBYMPK+SApUF+ 308RmxbUirbT4rWbo9naRetFN68eUKT57yTU8mXlsmNk1jO7rSnX X-Gm-Gg: ASbGncuqzchc3doeE/gjh5wqHrkeUypR371yPM3Q/tZkqGB3R4PVMiqQeAgXyNRb5HK PWro+1Phik7CujRoClK3YhXRxKv11NIP8SXckFwu0W4J4NZYRxJoQ8/OBIpLyEjO6PRqQo/Rot3 2mX466F+wqCR/QADgGpKm+KEo7TJU5yPvfpvLeGwN7YEkHi3pbwbU5Acm0k2sp2rSroaNWJzlu3 e9AL9Xoaz+UnbdBq+eClZLAtcqQsVJKOU5pbeG0kDcpTvX1cOoyP+BSanDNSnrjtjNOMaAgTzvT 6+z7QOQAQa9W8QJnKQA6eLpdZ7QWNhUONO3Ez4ZvGa5WY9V9LhIIdYuV8M8ulRcAZVBCEcp1CJz ZfrdQ13GhJc0WuV7BJRKba3aDUOsTJ6Eytw== X-Google-Smtp-Source: AGHT+IHVF9dZyy5fdppb2B9fC4zY58AKH7Z5elA6R5m1Fx+djQTrBpZYu8XpNrxC9Lvo2t0n034MaA== X-Received: by 2002:a17:907:7f0b:b0:abf:fb78:673a with SMTP id a640c23a62f3a-ac7e72e01aamr648812066b.29.1743948330294; Sun, 06 Apr 2025 07:05:30 -0700 (PDT) Received: from smtpclient.apple (178-222-114-237.dynamic.isp.telekom.rs. [178.222.114.237]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac7c013eb4csm589427166b.96.2025.04.06.07.05.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Apr 2025 07:05:29 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: =?utf-8?B?0JXQstCz0LXQvdC40Lkg0KfQtdC60LDQvQ==?= Mime-Version: 1.0 (1.0) Subject: =?utf-8?Q?Re:_Memory_Not_Released_After_Batch_Completion_?= =?utf-8?Q?=E2=80=93_Checkpointer/Background_Writer_Behavior_,_po?= =?utf-8?Q?stgres_15?= Date: Sun, 6 Apr 2025 16:05:18 +0200 Message-Id: <0A3E5AC0-218C-4808-932F-6D227C48AF7E@gmail.com> References: Cc: pgsql-performance@postgresql.org In-Reply-To: To: Motog Plus X-Mailer: iPhone Mail (21G93) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Checkpointer process holds the shared_buffers memory and it is the expected b= ehaviour. Even during idle, shared buffers are there for reads and future mo= difications. You have SB configured to be 10GB and it will stay allocated th= roughout the whole uptime of the server. This is totally OK and should help (= generally) with the performance.=20 The =E2=80=9Cidle=E2=80=9D thing is slightly less straightforward, as checkp= ointer and writer try to spread the load in time.=20 As for memory climbing to 90%, you might want to reduce shared buffers to so= mething less than 1/3 of your RAM and see if it helps.=20 But again, if there=E2=80=99s no issues with system availability and health t= hen you should not be bothered imo > 6 =D0=B0=D0=BF=D1=80. 2025=E2=80=AF=D0=B3., =D0=B2 14:37, Motog Plus =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0): >=20 > =EF=BB=BF >=20 > Hi All, >=20 > I=E2=80=99m running PostgreSQL on an EC2 c5.4xlarge Ubuntu instance with t= he following specs: >=20 > 32 GB RAM >=20 > 1.2 TB disk >=20 > 16 vCPUs >=20 >=20 > Pgpool-II Configuration: >=20 > max_pool =3D 2 >=20 > num_init_children =3D 1000 >=20 > client_idle_limit =3D 300 seconds >=20 > connection_life_time =3D 300 seconds >=20 > load_balance_mode =3D on >=20 >=20 > PostgreSQL Configuration: >=20 > max_connections =3D 3000 >=20 > checkpoint_timeout =3D 15min >=20 > checkpoint_completion_target =3D 0.9 >=20 > shared_buffers =3D 10GB >=20 > wal_buffers =3D 64MB >=20 > min_wal_size =3D 80MB >=20 > max_wal_size =3D 10GB >=20 > effective_cache_size =3D 20GB >=20 > work_mem =3D 4MB >=20 > maintenance_work_mem =3D 1GB >=20 > bgwriter_delay =3D 200ms >=20 > bgwriter_lru_multiplier =3D 2 >=20 > bgwriter_lru_maxpages =3D 100 >=20 > max_standby_streaming_delay =3D 5s (on standby) >=20 >=20 > I have a primary-standby streaming replication setup, and application modu= les (running in Kubernetes pods) connect to the database through Pgpool-II u= sing HikariCP. >=20 >=20 > --- >=20 > Issue Observed: >=20 > Even when no queries are running and application batch jobs have completed= , memory usage remains high(40%)=E2=80=94 particularly attributable to the c= heckpointer and background writer processes. According to Grafana, memory co= ntinues to remain cached. >=20 > When I manually kill the checkpointer process on the node, memory usage dr= ops immediately(9%). If I don't kill it and start another batch, memory usag= e increases further =E2=80=94 reaching up to 90%, though under normal condit= ions it stays around 65=E2=80=9370%. >=20 >=20 > --- >=20 > System Memory Snapshot (when idle): >=20 > free -h : > total 30 Gi > used 12 Gi > free 2.2 Gi > shared 10Gi > buff/cache 27Gi > available 18Gi > PostgreSQL memory usage from ps: >=20 > ps -eo pid,rss,cmd | grep postgres | awk '{sum+=3D$2} END {print sum/1024 "= MB"}' >=20 > Output: > 25682.4 MB >=20 > Note: Even though the system is idle for over 50 hours, connections connec= t, become idle and drop. >=20 > --- >=20 > Question: >=20 > Is it normal for the checkpointer and background writer to hold onto memor= y like this after workloads finish? Is this related to how PostgreSQL manage= s shared buffers or dirty pages in a streaming replication setup? >=20 > Are there any parameters in postgresql.conf or Pgpool that can help ensure= memory is better reclaimed when the system is idle? >=20 > Any guidance would be much appreciated. >=20 > Best regards, > Ramzy