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 1uCdhx-000CfO-MD for pgsql-general@arkaria.postgresql.org; Wed, 07 May 2025 12:17:06 +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 1uCdhw-00DuIA-FY for pgsql-general@arkaria.postgresql.org; Wed, 07 May 2025 12:17:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uCdhw-00DuI2-4w for pgsql-general@lists.postgresql.org; Wed, 07 May 2025 12:17:04 +0000 Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uCdht-000cr6-1F for pgsql-general@lists.postgresql.org; Wed, 07 May 2025 12:17:03 +0000 Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-e7585d4f921so2929550276.1 for ; Wed, 07 May 2025 05:17:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746620220; x=1747225020; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ITJSZU6Np3s7QrrpoGoC6H20sdvDOxtgi5+jmhkTHF0=; b=eAD3MIQcAUGNoGmZFxO3yef6MVuUaav2RsSGbDrnbB+JXK87bb8QtN1kf5NWWE2tf/ tgBbcRjU9d4cXatjzjrSFQ1UCFZKUxuQ1vQenb0V8Sp5LMqR+nwsZX/3kwi4vG3RJf87 I3SrYkCDDwqvZvOsVNqu8IeNh9SCi1VKBaMxK9DtF3CzSWMDquM5vBAqYxaOYnH0BAki 4JvGm2+cXa49eLITC6pPWj6lBFwiy4mMptEFFhbYL+FdDGGw2MmvFqh6hGvZW5ED+LVu N18NoOCwSgo9zIBfLuwnPPGVWHonoMgbOhmk4pT9zCJQVMUIrAoS6c5tbB4pPKeKb+uI dgIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746620220; x=1747225020; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ITJSZU6Np3s7QrrpoGoC6H20sdvDOxtgi5+jmhkTHF0=; b=Vx4IKlC4Rtzt+fVWiWO6JloqOM0DsgF3ld2zdC0CXve9hvwnNDR1l8rQG4W8oJ5pK9 aDLobj89mEs9MJx4/yTIVXq/dZk9G3i5YUs/yBt4QuNO0ZdaUlbggX2OByEg9kmkQJeY VNVwM0xh1jrKU85xc9CNVVpjavX4lOPyumVO9yvi+dLueyUbl7TzwZxa/Q4sVMHYzFU7 Lc6oNKRjwpJuZtkYfEO5qLFrDSCfEJz+4ejbTEX5moA4fcFzoNhntUUqpHYx3hG0sgI6 0p7/+dXEREq0lA9VLODPRY/GGn2c5msGhmDrS7s9Ka3PPPVdCd8Vui6U0uyFhm5oj/As 3uDw== X-Gm-Message-State: AOJu0Yyxm0PPqFsTfahqXX45Y3S6rwQEeL2XVFEagiI5UHasecyxUp1s VnI+c7tDafX1LYJi/OBgnfXZITAX8r5NoqVKLagwFabVhs7sHOBc6wRzNl+k82D2y7RhEIstWh+ omCn46TdZ4eTNBY+wPDiZ9AbpPU8= X-Gm-Gg: ASbGncumkY510Bx+PERwiv1gcoNGK1ogFL1yULe7WD8K+qCnOkGlndHFRR0byqXfO1Z id3Yjn32IedPrOUkf3v9pmXWM4oeWKjmSm2hIu6DgxrqDQpXgAunlHORp5B/D4QG4BDys36T30p M56j/3SqSaSlQxU3id4wF5KTQ= X-Google-Smtp-Source: AGHT+IGy/HZxAxk03ab9Yt3mKTGOakA/zCEOEswJvy3IX4SEW3E5xR3dKyrEDDNE8rYxnIn/GDZtyj+jms14gAwu5bI= X-Received: by 2002:a05:690c:6e0b:b0:709:967e:e0a3 with SMTP id 00721157ae682-70a1dafd3femr47067947b3.38.1746620220001; Wed, 07 May 2025 05:17:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Alicja Kucharczyk Date: Wed, 7 May 2025 14:16:49 +0200 X-Gm-Features: ATxdqUEJBx47NIE3UZcgEjluNBewQfz85Gq8Qylt0zAfOUntUsGg5B8izUHQHXg Message-ID: Subject: Re: huge_pages=on cause could not map anonymous shared memory: Cannot allocate memory To: Bogdan Siara Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000c554c906348ab541" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000c554c906348ab541 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Bogdan, The root cause here is that the number of huge pages you've configured (vm.nr_hugepages =3D 980) is not sufficient. Each huge page on your system is 2=E2=80=AFMB in size, so 980 pages give yo= u roughly 1.96=E2=80=AFGB of memory (980 =C3=97 2=E2=80=AFMB). However, Postg= reSQL is clearly requesting about 2.2=E2=80=AFGB of shared memory (specifically, 2204106752 = bytes as shown in the error message you provided), which exceeds what's available through huge pages. That=E2=80=99s why PostgreSQL fails to start when huge_pages =3D on - it re= quires the entire shared memory segment to come from huge pages and refuses to fall back to regular ones. Earlier, you had the huge_pages setting commented out, which means PostgreSQL used the default value: huge_pages =3D try. In that mode, it fir= st attempts to use huge pages, but if that fails (like in your case due to insufficient allocation), it falls back to standard memory pages =E2=80=94 = which is why the instance started without issues then. To fix the issue, you should increase vm.nr_hugepages to at least 1100 to fully cover the shared memory request (you can go a bit higher to be safe and then reduce it as described in the article I'm pasting the link to). Also, a side note: max_connections =3D 1000 is quite high for an instance with 8=E2=80=AFGB of RAM and only 2 vCPUs. Even if huge pages are properly allocated, such a high number of connections can lead to performance issues. You might want to consider lowering it or using a connection pooler like PgBouncer. If you=E2=80=99d like to understand how huge pages work in PostgreSQL, incl= uding how to calculate memory needs and configure the OS properly, I wrote a detailed article some time ago (still valid). It=E2=80=99s in Polish, which= I assume is fine for you: https://linuxpolska.com/pl/baza-wiedzy/blog/postgres-pamieci-ram-tipstricks= / best regards, Alicja Kucharczyk > --000000000000c554c906348ab541 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Bogdan,
The root cause here is that the = number of huge pages you've configured (vm.nr_hugepages =3D 980) is not= sufficient.
Each huge page on your system is 2=E2=80=AFMB in size, so 9= 80 pages give you roughly 1.96=E2=80=AFGB of memory (980 =C3=97 2=E2=80=AFM= B). However, PostgreSQL is clearly requesting about 2.2=E2=80=AFGB of share= d memory (specifically, 2204106752 bytes as shown in the error message you = provided), which exceeds what's available through huge pages.

Th= at=E2=80=99s why PostgreSQL fails to start when huge_pages =3D on - it requ= ires the entire shared memory segment to come from huge pages and refuses t= o fall back to regular ones.

Earlier, you had the huge_pages setting= commented out, which means PostgreSQL used the default value: huge_pages = =3D try. In that mode, it first attempts to use huge pages, but if that fai= ls (like in your case due to insufficient allocation), it falls back to sta= ndard memory pages =E2=80=94 which is why the instance started without issu= es then.

To fix the issue, you should increase vm.nr_hugepages to at= least 1100 to fully cover the shared memory request (you can go a bit high= er to be safe and then reduce it as described in the article I'm pastin= g the link to).

Also, a side note: max_connections =3D 1000 is quite= high for an instance with 8=E2=80=AFGB of RAM and only 2 vCPUs. Even if hu= ge pages are properly allocated, such a high number of connections can lead= to performance issues. You might want to consider lowering it or using a c= onnection pooler like PgBouncer.

If you=E2=80=99d like to understand= how huge pages work in PostgreSQL, including how to calculate memory needs= and configure the OS properly, I wrote a detailed article some time ago (s= till valid). It=E2=80=99s in Polish, which I assume is fine for you: https://linuxpolska.com/pl/baza-wiedzy/blog/postgres-pamieci-ram-ti= pstricks/

best regards,
Alicja Kucha= rczyk
--000000000000c554c906348ab541--