File: startup-checks-root.sh

package info (click to toggle)
postgresql 7.4.7-6sarge6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 11,168 kB
  • ctags: 27
  • sloc: sh: 1,903; makefile: 337; ansic: 204; perl: 69; sed: 6; tcl: 1
file content (81 lines) | stat: -rw-r--r-- 2,317 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# This script checks some startup conditions for PostgreSQL and prints warning
# and messages if they are violated.
#
# This script is executed with root privileges (called from PostgreSQL's init
# script). Please add checks for which the privileges of the "postgres" user
# are sufficient to postgresql-startup.
#
# Note: Checking kernel variables requires root privileges on security-enhanced
# kernels like grsecurity.

if [ -r /etc/postgresql/postmaster.conf ]; then
    source /etc/postgresql/postmaster.conf
fi

#
# Check that we have enough shared memory
#

# Get the current PostgreSQL buffers setting
BUFFERS="`grep "^ *shared_buffers" /etc/postgresql/postgresql.conf | cut -f2 -d= | cut -f1 -d# `" || true
[ "$BUFFERS" ] || BUFFERS=1000 # default value

# Each buffer is 8192 bytes, and we want bytes... plus some extra
SHMREQ=$(( BUFFERS * 8400 + 6000000 ))
if SHMMAX=`sysctl kernel.shmmax 2>/dev/null` ; then
  sysctl_shmmax=kernel.shmmax
elif SHMMAX=`sysctl kern.ipc.shmmax 2>/dev/null` ; then
  sysctl_shmmax=kern.ipc.shmmax
else
  SHMMAX=0  
  sysctl_shmmax=unknown
fi
SHMMAX="`echo $SHMMAX | sed "s/^.*\(:\|=\) //g"`"
if [ "$SHMMAX" -lt "$SHMREQ" ]
then
cat <<EOF >&2

/etc/postgresql/postgresql.conf sets shared_buffers=$BUFFERS.
Your kernel currently limits a shared memory segment to $SHMMAX bytes,
but PostgreSQL needs $SHMREQ bytes.

The server might not start due to this, without giving a proper error 
message. Please enlarge the amount of shared memory by issuing the 
following command (as root):

sysctl -w ${shmmax}=${SHMREQ}
EOF
fi

#
# check that we can open enough files simultaneously
#

if fmax=`sysctl fs.file-max 2>/dev/null` ; then
  sysctl_fmax=fs.file-max
elif fmax=`sysctl kern.maxfiles 2>/dev/null` ; then
  sysctl_fmax=kern.maxfiles
else
  fmax=0
  sysctl_fmax=unknown
fi
fmax="`echo $fmax | sed "s/^.*\(:\|=\) //g"`"

if [ "$fmax" -lt ${KERNEL_FILE_MAX:=1032} ]
then
    cat <<EOF >&2

/etc/postgresql/postmaster.conf sets KERNEL_FILE_MAX=$KERNEL_FILE_MAX,
but your kernel currently limits the number of simultaneously opened files
to $fmax.

The server might not start due to this, without giving a proper error 
message. Please enlarge the number of open files by issuing the 
following command (as root):

sysctl -w ${sysctl_fmax}=${KERNEL_FILE_MAX}
EOF
fi