The following error may be reported when stopping Greenplum:
20200311:22:30:51:386577 gprecoverseg:mdw:gpadmin-[ERROR]:-Unable to clean up shared memory for segment: (ipcrm: permission denied for id (/data2/primary/gpseg15)
This article will discuss how Greenplum cleans the shared memory and also how to handle the error above.
Note: If you have any doubt about the actions below, open a support ticket with Greenplum support for assistance.
When a Greenplum instance is running, it will pre-allocate some memory as shared memory. We can check the list of shared memory by using the below command:
$ ipcs -m -p ------ Shared Memory Creator/Last-op PIDs -------- shmid owner cpid lpid 3964928 gpadmin 28824 28843 3997697 gpadmin 28825 54360 4030466 gpadmin 28826 54359 4063235 gpadmin 28827 28845 4096004 gpadmin 28891 32735 3702789 root 14595 14595
When the Greenplum instance starts, it will allocate the shared memory and put the shared memory ID (SHMID) in its data folder. For example
$ cd /data/primary/gpseg15 $ cat postmaster.pid 28826 << PID for the postgres process /data/primary/gpseg15 20000001 4030466 << the 4030466 is SHMID $ ipcs -m -p | grep 4030466 4030466 gpadmin 28826 54596 << the 4030466 SHMID was owned by process 28826 $ ps -f -p 28826 UID PID PPID C STIME TTY TIME CMD gpadmin 28826 1 0 06:43 ? 00:00:00 /usr/local/greenplum-db/bin/postgres -D /data/primary/gpseg15 -p 20000 --gp_dbid=17 --gp_num_contents_in_cluster=24 --silent-mode=true -i -M quiescent --gp_cont
When any utility that needs to shut down the Greenplum instance (E.g: gpstop, gprecoverseg, etc.), it will up the shared memory.
In short, it does the steps below:
1. Check the file [$DATA_FOLDER]/postmaster.pid to get the SHMID
2. Run "ipcrm -m [SHMID]" to remove the shared memory
In some cases, while stopping Greenplum it reported the error below:
20200311:22:30:51:386577 gprecoverseg:mdw:gpadmin-[ERROR]:-Unable to clean up shared memory for segment: (ipcrm: permission denied for id (/data2/primary/gpseg15)
If the postgres process is running, it can be stopped using "pg_ctl". Ensure it is safe to shutdown the segment.
pg_ctl stop -D [SEG_DATA_DIR]
example: pg_ctl stop -D /data/primary/gpseg15
If there is no process running with the PID specified in the postmaster.pid file and the shared memory is listed with "ipcs -m -p", then it should be safe to clear the shared memory with:
ipcrm -m [SHMID]. # Replace [SHMID] when the correct number from the postmaster,pid file.