Skip to content

Commit af01570

Browse files
author
Sameer Naik
committed
Merge branch 'adding-postgis' of https://github.com/lwiechec/docker-postgresql into lwiechec-adding-postgis
2 parents 23053b3 + 8c0a352 commit af01570

5 files changed

Lines changed: 27 additions & 3 deletions

File tree

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ ENV PG_APP_HOME="/etc/docker-postgresql"\
77
PG_HOME=/var/lib/postgresql \
88
PG_RUNDIR=/run/postgresql \
99
PG_LOGDIR=/var/log/postgresql \
10-
PG_CERTDIR=/etc/postgresql/certs
10+
PG_CERTDIR=/etc/postgresql/certs \
11+
PG_POSTGIS_VERSION=2.1
1112

1213
ENV PG_BINDIR=/usr/lib/postgresql/${PG_VERSION}/bin \
1314
PG_DATADIR=${PG_HOME}/${PG_VERSION}/main
@@ -17,6 +18,7 @@ RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-k
1718
&& apt-get update \
1819
&& DEBIAN_FRONTEND=noninteractive apt-get install -y acl \
1920
postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION} \
21+
postgresql-${PG_VERSION}-postgis-${PG_POSTGIS_VERSION} postgresql-${PG_VERSION}-postgis-${PG_POSTGIS_VERSION}-scripts \
2022
&& ln -sf ${PG_DATADIR}/postgresql.conf /etc/postgresql/${PG_VERSION}/main/postgresql.conf \
2123
&& ln -sf ${PG_DATADIR}/pg_hba.conf /etc/postgresql/${PG_VERSION}/main/pg_hba.conf \
2224
&& ln -sf ${PG_DATADIR}/pg_ident.conf /etc/postgresql/${PG_VERSION}/main/pg_ident.conf \

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Creating database user](#creating-database-user)
1515
- [Creating databases](#creating-databases)
1616
- [Enabling unaccent extension](#enabling-unaccent-extension)
17+
- [Enabling PostGIS extension](#enabling-postgis-extension)
1718
- [Granting user access to a database](#granting-user-access-to-a-database)
1819
- [Creating replication user](#creating-replication-user)
1920
- [Setting up a replication cluster](#setting-up-a-replication-cluster)
@@ -182,9 +183,21 @@ docker run --name postgresql -itd \
182183
--env 'DB_NAME=dbname' --env 'DB_UNACCENT=true' \
183184
sameersbn/postgresql:9.4-11
184185
```
185-
186186
*By default the unaccent extension is disabled*
187187

188+
# Enabling PostGIS extension
189+
190+
PostGIS is spatial extension to PostgreSQL.
191+
192+
You can enable the PostGIS extension on database(s) by specifying `DB_POSTGIS=true`. For example, the following command enables the unaccent extension for the `dbname` database.
193+
194+
```bash
195+
docker run --name postgresql -itd \
196+
--env 'DB_NAME=dbname' --env 'DB_POSTGIS=true' \
197+
sameersbn/postgresql:9.4-11
198+
```
199+
*By default the PostGIS extension is disabled*
200+
188201
## Granting user access to a database
189202

190203
If the `DB_USER` and `DB_PASS` variables are specified along with the `DB_NAME` variable, then the user specified in `DB_USER` will be granted access to all the databases listed in `DB_NAME`. Note that if the user and/or databases do not exist, they will be created.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9.4-11
1+
9.4-12-snapshot

runtime/env-defaults

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ DB_PASS=${DB_PASS:-}
1919
DB_TEMPLATE=${DB_TEMPLATE:-template1}
2020

2121
DB_UNACCENT=${DB_UNACCENT:-false}
22+
23+
DB_POSTGIS=${DB_POSTGIS:-false}
24+
DB_POSTGIS_HSTORE=${DB_POSTGIS_HSTORE:-true}
25+
DB_POSTGIS_TOPOLOGY=${DB_POSTGIS_TOPOLOGY:-true}

runtime/functions

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ create_database() {
323323
psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS unaccent;" >/dev/null 2>&1
324324
fi
325325

326+
if [[ ${DB_POSTGIS} == true ]]; then
327+
psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS postgis;" >/dev/null 2>&1
328+
psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS postgis_topology;" >/dev/null 2>&1
329+
fi
330+
326331
if [[ -n ${DB_USER} ]]; then
327332
psql -U ${PG_USER} -c "GRANT ALL PRIVILEGES ON DATABASE \"${database}\" to \"${DB_USER}\";" >/dev/null
328333
fi

0 commit comments

Comments
 (0)