Pingu
Computer MySQL PostgreSQL Books Publications
Spielereien Kanu Geopolitik Business TopoDB POI Klettersteigen History TransPool Thermal Baden Brokenstuben Goldwaschen
Blog Contact
Shinguz
Google
/ch/open

PostgreSQL and Shared Memory

/ home / computer / postgresql .

Kürzlich bin ich bei meiner PostgreSQL Installation auf folgendes Problem gelaufen:

$ psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5433" failed: FATAL:
could not open shared memory segment "/PostgreSQL.1418094450":
No such file or directory

Problem

Das Problem könnte sein, dass Systemd Shared Memory Segmente nach einem Logout abräumt.

Quellen:

Lösung

Lösungen die wir zur Zeit ausprobieren:

uid < 1000

Die uid des PostgreSQL Users kleiner als 1000. Diese Lösung verfolgen wir zur Zeit nicht weiter, da der Aufwand und der Impact zur Zeit nicht abschätzbar sind.

systemd/logind.conf anpassen

Auf RHEL basierten System NICHT notwendig, da bereits “richtig” gesetzt.

Auf Ubuntu/Debian Systemen:

$ systemd-analyze cat-config systemd/logind.conf | grep RemoveIPC
#RemoveIPC=yes

$ systemctl edit systemd-logind
$ systemctl daemon-reload

$ systemctl cat systemd-logind | grep RemoveIPC   # in current configuration files
RemoveIPC=no

$ systemctl show systemd-logind --property=RemoveIPC   # in current settings
RemoveIPC=no

Es ist zur Zeit noch nicht klar, ob das Problem hiermit gelöst ist!

Allgemeine Shared Memory Analyse

$ free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi        12Gi       460Mi       1.9Gi       4.4Gi       3.2Gi
Swap:             0B          0B          0B

$ grep Shmem /proc/meminfo
Shmem:           1955192 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB

$ ll /dev/shm/PostgreSQL.*
-rw------- 1 mysql mysql   29776 Jan  8 08:33 /dev/shm/PostgreSQL.651615246
-rw------- 1 mysql mysql 1048576 Jan  8 08:33 /dev/shm/PostgreSQL.81733920

$ df -h
Filesystem          Size  Used Avail Use% Mounted on
...
tmpfs               7.7G  1.4M  7.7G   1% /dev/shm


$ smemstat
    PID      Swap       USS       PSS       RSS User       Command
 997723     0.0 B  8632.0 K    11.9 M    23.4 M mysql      /home/mysql/product/postgresql-19.dev-x86_64/bin/postgres
 999638     0.0 B   292.0 K  2674.0 K  7760.0 K mysql      postgres: walwriter
 999639     0.0 B   644.0 K  1779.0 K  6532.0 K mysql      postgres: autovacuum launcher
 999640     0.0 B   544.0 K  1468.0 K  5764.0 K mysql      postgres: logical replication launcher
 999636     0.0 B   392.0 K  1373.0 K  6240.0 K mysql      postgres: checkpointer
 999637     0.0 B   288.0 K  1036.0 K  4752.0 K mysql      postgres: background writer
 999632     0.0 B   292.0 K   632.0 K  3692.0 K mysql      postgres: io worker 0
 999634     0.0 B   264.0 K   533.0 K  3296.0 K mysql      postgres: io worker 2
 999633     0.0 B   264.0 K   533.0 K  3296.0 K mysql      postgres: io worker 1
Total:      0.0 B  2526.7 M  2543.7 M  2637.3 M

$ cat /proc/$(head -n 1 ~/database/postgres-19/data/postmaster.pid)/smaps_rollup
62530851e000-7fff425ff000 ---p 00000000 00:00 0                          [rollup]
...
Shared_Clean:       8164 kB
Shared_Dirty:       7172 kB
...

$ ipcs --shmems --human

------ Shared Memory Segments --------
key        shmid      owner      perms      size       nattch     status
0x3c81b7f5 10         oli        666            4K     0
0x51112843 7897109    oli        600          152B     1
0x005e0006 7897115    mysql      600           56B     9

$ lsof -p $(head -n 1 ~/database/postgres-19/data/postmaster.pid)
COMMAND     PID  USER   FD      TYPE             DEVICE SIZE/OFF     NODE NAME
...
postgres 911472 mysql  DEL       REG               0,27             17306 /dev/shm/PostgreSQL.651615246
...

$ pmap -x $(head -n 1 ~/database/postgres-19/data/postmaster.pid)
997723:   /home/mysql/product/postgresql-19.dev-x86_64/bin/postgres -D /home/mysql/database/postgres-19/data -p 5433
Address           Kbytes     RSS   Dirty Mode  Mapping
...
00007d52ad21d000       4       4       4 rw-s-   [ shmid=0x798036 ]
...
---------------- ------- ------- -------
total kB          206080   23968   14356


$ smem -tu

User     Count     Swap      USS      PSS      RSS
mysql       18        0  2602396  2620797  2717616
---------------------------------------------------
            18        0  2602396  2620797  2717616

Weitere Quellen