-
Notifications
You must be signed in to change notification settings - Fork 1
/
initdb.sh
40 lines (28 loc) · 1.39 KB
/
initdb.sh
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
#!/bin/sh
#start postgres
service postgresql start
#Provide a password for default user (postgres)
psql -c "ALTER USER postgres WITH PASSWORD 'postgres';"
#Set postgis-2.1 path
POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis-2.3
#Create the spatial database that will be used as a template
createdb -E UTF8 -T template0 template_postgis
#Add PLPGSQL language support
createlang -d template_postgis plpgsql
#Load the PostGIS SQL routines
psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
#Allow users to alter spatial tables
psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
#Perform garbage collection
psql -d template_postgis -c "VACUUM FULL;"
psql -d template_postgis -c "VACUUM FREEZE;"
#Allows non-superusers the ability to create from this template.
psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
psql -d postgres -c "UPDATE pg_database SET datallowconn='true' WHERE datname='template_postgis';" #this was false
#Create a spatially-enabled database named endpoint.
createdb endpoint -T template_postgis
#stop postgres
service postgresql stop