comparison backend/doc/schema/postgresql-setup.sh @ 8794:c1cea6c95967

Improve Postgres-DB setup. We depend on 9.1 (having CREATE EXTENSION) since a while.
author Tom Gottfried <tom@intevation.de>
date Thu, 10 Dec 2015 17:40:02 +0100
parents 4ad2b530dbba
children 358a0fd48a00
comparison
equal deleted inserted replaced
8793:d3804d134fd9 8794:c1cea6c95967
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # $1: user name and password for new DB (equals DB name) 3 # $1: name, user and password for new DB (optional. Default: d4e)
4 # $2: path to directory with schema-scripts 4 # $2: host (optional. Default: localhost)
5 # $3: host 5
6 SCRIPT_DIR=`dirname $0`
7 DB_NAME=${1:-d4e}
8 PG_HOST=${2:-localhost}
6 9
7 # run as user postgres (postgresql super-user) 10 # run as user postgres (postgresql super-user)
8 # it is assumed that the owner of the DB has the same name as the DB! 11 # it is assumed that the owner of the DB has the same name as the DB!
9 12
10 # create PostGIS-DB 13 # create PostGIS-DB
11 createuser -S -D -R $1 14 createuser -S -D -R $DB_NAME
12 createdb $1 15 createdb $DB_NAME
13 createlang plpgsql $1 16 createlang plpgsql $DB_NAME
14 # Path appears e.g. as /usr/share/postgresql/contrib/postgis-1.5/ on some systems, 17
15 # /usr/share/postgresql/8.4/contrib/postgis-1.5/ on others 18 psql -d $DB_NAME -c "ALTER USER $DB_NAME WITH PASSWORD '$DB_NAME';"
16 POST_INIT_DIR=`find /usr/share/postgresql/ -name spatial_ref_sys.sql | sed -n '1p'` 19
17 POST_INIT_DIR=`dirname $POST_INIT_DIR` 20 psql -d $DB_NAME -c "CREATE EXTENSION postgis;"
18 psql -d $1 -f $POST_INIT_DIR/postgis.sql 21 psql -d $DB_NAME -c "GRANT ALL ON geometry_columns TO $DB_NAME;
19 psql -d $1 -f $POST_INIT_DIR/spatial_ref_sys.sql 22 GRANT ALL ON geography_columns TO $DB_NAME;
20 psql -d $1 -c "ALTER USER $1 WITH PASSWORD '$1';" 23 GRANT ALL ON spatial_ref_sys TO $DB_NAME;"
21 psql -d $1 -c "GRANT ALL ON geometry_columns TO $1; GRANT ALL ON geography_columns TO $1; GRANT ALL ON spatial_ref_sys TO $1;"
22 24
23 # add credentials to .pgpass (or create .pgpass) 25 # add credentials to .pgpass (or create .pgpass)
24 echo "*:*:$1:$1:$1" >> ~/.pgpass 26 echo "*:*:$DB_NAME:$DB_NAME:$DB_NAME" >> ~/.pgpass
25 chmod 0600 ~/.pgpass 27 chmod 0600 ~/.pgpass
26 28
27 # apply schema-scripts 29 # apply schema-scripts
28 psql -d $1 -U $1 -h $3 -f $2/postgresql.sql 30 psql -d $DB_NAME -U $DB_NAME -h $PG_HOST -f $SCRIPT_DIR/postgresql.sql
29 psql -d $1 -U $1 -h $3 -f $2/postgresql-spatial.sql 31 psql -d $DB_NAME -U $DB_NAME -h $PG_HOST -f $SCRIPT_DIR/postgresql-spatial.sql
30 psql -d $1 -U $1 -h $3 -f $2/postgresql-minfo.sql 32 psql -d $DB_NAME -U $DB_NAME -h $PG_HOST -f $SCRIPT_DIR/postgresql-minfo.sql

http://dive4elements.wald.intevation.org