RE: Memory issues with PostgreSQL 15 - Mailing list pgsql-general

From Christian Schröder
Subject RE: Memory issues with PostgreSQL 15
Date
Msg-id LO0P265MB270002E8C8CC879FE082A824F9AB2@LO0P265MB2700.GBRP265.PROD.OUTLOOK.COM
Whole thread Raw
In response to Re: Memory issues with PostgreSQL 15  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Memory issues with PostgreSQL 15
Re: Memory issues with PostgreSQL 15
Re: Memory issues with PostgreSQL 15
List pgsql-general
Hi all,
I started this discussion in May and was then dragged into other topics, so I could never follow up. Sorry for that!
Since then, the problem has resurfaced from time to time. Right now, we seem to have issues again, which gives me the
opportunityto follow up on your various suggestions.
 

The current error messages are similar to what we have seen before:

<2024-07-25 12:27:38 CEST - > LOG:  could not fork autovacuum worker process: Cannot allocate memory
<2024-07-25 12:27:38 CEST - mailprocessor> ERROR:  could not resize shared memory segment "/PostgreSQL.1226901392" to
189280bytes: No space left on device
 

As far as I understand, it does not make much sense to look into SysV shared memory (which is what ipcs does). Indeed,
thereis only the same small shared memory segment as we have seen back then:
 

# ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x04000194 45         postgres   600        56         20

Francisco and Tom both pointed at Posix shared memory instead; however, this also does not seem to be used a lot:

# df -h /dev/shm
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           7.8G  6.6M  7.8G   1% /dev/shm

# ls -lhR /dev/shm
/dev/shm:
total 6.6M
-rw------- 1 postgres postgres 1.0M Jul 25 06:26 PostgreSQL.1095217316
-rw------- 1 postgres postgres 1.0M Jul 23 06:20 PostgreSQL.124772332
-rw------- 1 postgres postgres 1.0M Jul 23 06:18 PostgreSQL.1475196260
-rw------- 1 postgres postgres 1.0M Jul 23 06:18 PostgreSQL.1725210234
-rw------- 1 postgres postgres 193K Jul 23 06:15 PostgreSQL.2581015990
-rw------- 1 postgres postgres 193K Jul 23 06:15 PostgreSQL.2929101952
-rw------- 1 postgres postgres 193K Jul 23 06:17 PostgreSQL.3018875836
-rw------- 1 postgres postgres  65K Jul 23 06:15 PostgreSQL.3403523208
-rw------- 1 postgres postgres 193K Jul 23 06:15 PostgreSQL.3482890896
-rw------- 1 postgres postgres 193K Jul 23 06:18 PostgreSQL.3824279998
-rw------- 1 postgres postgres 193K Jul 23 06:18 PostgreSQL.3891977516
-rw------- 1 postgres postgres 193K Jul 23 06:15 PostgreSQL.3929720846
-rw------- 1 postgres postgres 1.0M Jul 23 06:34 PostgreSQL.3969232506
-rw------- 1 postgres postgres 193K Jul 23 06:18 PostgreSQL.4222425006

We also still see a lot of available memory:

# free -m
              total        used        free      shared  buff/cache   available
Mem:          15882        6966         191        2109        8725        6477
Swap:          1999         271        1728

Again, exactly the same situation as before.

Tom suggested that we hit some kernel limits, but I could not find any related kernel setting. The only limit I am
awareof is the size of the /dev/shm filesystem itself. This could be changed, but the default value of 8 GB (which is
halfof the machine's memory) seems to be enough (given that it is not even used).
 

Is there anything else I can analyze? Sorry again for reviving this old thread.

Best,
Christian

PS: The database does not run in a Docker container.

-----Original Message-----
From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: Wednesday, May 29, 2024 11:44 PM
To: Christian Schröder <christian.schroeder@wsd.com>
Cc: Francisco Olarte <folarte@peoplecall.com>; pgsql-general@lists.postgresql.org; Eric Wong <eric.wong@wsd.com>
Subject: Re: Memory issues with PostgreSQL 15

[EXTERNAL]

=?utf-8?B?Q2hyaXN0aWFuIFNjaHLDtmRlcg==?= <christian.schroeder@wsd.com> writes:
> # ipcs -m

> ------ Shared Memory Segments --------
> key        shmid      owner      perms      bytes      nattch     status
> 0x04000194 35         postgres   600        56         19

> I am surprised to see this since I would have expected much more shared memory to be used by the database. Is there
anythingin the configuration that prevents the shared memory from being used?
 

SysV shared memory isn't that relevant to Postgres anymore.  Most of what we allocate goes into POSIX-style shared
memorysegments, which are not shown by "ipcs".  We do still create one small fixed-size data structure in SysV memory,
whichis what you're seeing here, for arcane reasons having to do with the lifespan of the shared memory segments being
differentin those two APIs.
 

>> <2024-05-21 11:34:46 CEST - mailprocessor> ERROR:  could not resize
>> shared memory segment "/PostgreSQL.2448337832" to 182656 bytes: No
>> space left on device

This seems to indicate that you're hitting some kernel limit on the amount of POSIX shared memory.  Not sure where to
lookfor that.
 

                        regards, tom lane


----------------------------------------------
SUPPORT:
For any issues, inquiries, or assistance, please contact our support team at support@wsd.com. Our dedicated team is
availableto help you and provide prompt assistance.
 

CONFIDENTIALITY NOTICE:
This email and any attachments are confidential and intended solely for the use of the individual or entity to whom it
isaddressed. If you have received this email in error, please notify the sender immediately and delete it from your
system.

pgsql-general by date:

Previous
From: Dominique Devienne
Date:
Subject: Re: Issue while creating index dynamically
Next
From: Laurenz Albe
Date:
Subject: Re: Memory issues with PostgreSQL 15