aboutsummaryrefslogtreecommitdiff
path: root/system/postgresql/setup.postgresql
blob: 9b23bbd2f28ee90d4d9942c20e5c302eebaccca9 (plain)
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
#!/bin/bash
#BLURB="PostgreSQL"

PG_HOME=/var/lib/pgsql
PG_USER=postgres
PG_USER_ID=209
PG_GROUP=postgres
PG_GROUP_ID=209

echo "Adding PostgreSQL user and group..."
groupadd -g $PG_GROUP_ID $PG_GROUP
useradd -g $PG_GROUP -u $PG_USER_ID -d $PG_HOME -c PostgreSQL $PG_USER
mkdir -p $PG_HOME/data

## default permissions
echo "Setting up permissions..."
chown -R $PG_USER:$PG_GROUP $PG_HOME
chmod 700 $PG_HOME
chmod 700 $PG_HOME/data

## database cluster
if [ ! -f $PG_HOME/data/PG_VERSION ]; then
	echo "Creating database cluster in $PG_HOME/data..."
	su $PG_USER -c "initdb -D $PG_HOME/data"
else
	echo "*** WARNING ***" >&2
	echo "  There is already a database cluster in $PG_HOME/data." >&2
	echo "  If you are upgrading from an older version of PostgreSQL" >&2
	echo "  you will have to 'dump' and 'restore' your database." >&2
	echo "  See PostgreSQL manual for more details." >&2
fi

echo "PostgreSQL post-installation setup completed"