3
# $PostgreSQL: pgsql/src/bin/ipcclean/ipcclean.sh,v 1.15 2003-11-29 19:52:04 pgsql Exp $
8
if [ "$1" = '-?' -o "$1" = "--help" ]; then
9
echo "$CMDNAME cleans up shared memory and semaphores from aborted PostgreSQL"
15
echo "Note: Since the utilities underlying this script are very different"
16
echo "from platform to platform, chances are that it might not work on"
17
echo "yours. If that is the case, please write to <pgsql-bugs@postgresql.org>"
18
echo "so that your platform can be supported in the future."
22
if [ "$USER" = 'root' -o "$LOGNAME" = 'root' ]
25
echo "$CMDNAME: cannot be run as root" 1>&2
26
echo "Please log in (using, e.g., \"su\") as the (unprivileged) user that" 1>&2
27
echo "owned the server process." 1>&2
32
EffectiveUser=`id -n -u 2>/dev/null || whoami 2>/dev/null`
34
#-----------------------------------
35
# List of platform-specific hacks
36
# Feel free to add yours here.
37
#-----------------------------------
41
if [ `uname` = 'QNX' ]; then
42
if ps -eA | grep -s '[p]ostmaster' >/dev/null 2>&1 ; then
43
echo "$CMDNAME: a postmaster is still running" 1>&2
50
# This is based on RedHat 5.2.
52
if [ `uname` = 'Linux' ]; then
55
if ps x | grep -s '[p]ostmaster' >/dev/null 2>&1 ; then
56
echo "$CMDNAME: a postmaster is still running" 1>&2
61
for val in `ipcs -m -p | grep '^[0-9]' | awk '{printf "%s:%s:%s\n", $1, $3, $4}'`
72
# Note: We can do -n here, because we know the platform.
73
echo -n "Shared memory $ipcs_shmid ... "
75
# Don't do anything if process still running.
76
# (This check is conceptually phony, but it's
77
# useful anyway in practice.)
78
ps hj $ipcs_cpid $ipcs_lpid >/dev/null 2>&1
79
if [ "$?" -eq 0 ]; then
80
echo "skipped; process still exists (pid $ipcs_cpid or $ipcs_lpid)."
86
if [ "$?" -eq 0 ]; then
94
for val in `ipcs -s -c | grep '^[0-9]' | awk '{printf "%s\n", $1}'`; do
95
echo -n "Semaphore $val ... "
98
if [ "$?" -eq 0 ]; then
105
[ -z "$did_anything" ] && echo "$CMDNAME: nothing removed" && exit 1
110
# This is the original implementation. It seems to work
111
# on FreeBSD, SunOS/Solaris, HP-UX, IRIX, and probably
114
ipcs | egrep '^m .*|^s .*' | egrep "$EffectiveUser" | \
115
awk '{printf "ipcrm -%s %s\n", $1, $2}' '-' | sh