diff --git a/Changelog.md b/Changelog.md index d7fc417..12be3de 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ **9.4-12** - removed use of single-user mode - added `DB_TEMPLATE` variable to specify the database template +- added support for `PostGIS` extension **9.4-11** - added `PG_PASSWORD` variable to specify password for `postgres` user diff --git a/Dockerfile b/Dockerfile index d7b13b6..2d57e72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ MAINTAINER sameer@damagehead.com ENV PG_APP_HOME="/etc/docker-postgresql"\ PG_VERSION=9.4 \ + PG_POSTGIS_VERSION=2.2 \ PG_USER=postgres \ PG_HOME=/var/lib/postgresql \ PG_RUNDIR=/run/postgresql \ @@ -17,6 +18,7 @@ RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-k && apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y acl \ postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION} \ + postgresql-${PG_VERSION}-postgis-${PG_POSTGIS_VERSION} \ && ln -sf ${PG_DATADIR}/postgresql.conf /etc/postgresql/${PG_VERSION}/main/postgresql.conf \ && ln -sf ${PG_DATADIR}/pg_hba.conf /etc/postgresql/${PG_VERSION}/main/pg_hba.conf \ && ln -sf ${PG_DATADIR}/pg_ident.conf /etc/postgresql/${PG_VERSION}/main/pg_ident.conf \ diff --git a/README.md b/README.md index 8889a56..888edfc 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ - [Creating database user](#creating-database-user) - [Creating databases](#creating-databases) - [Enabling unaccent extension](#enabling-unaccent-extension) + - [Enabling PostGIS extension](#enabling-postgis-extension) - [Granting user access to a database](#granting-user-access-to-a-database) - [Creating replication user](#creating-replication-user) - [Setting up a replication cluster](#setting-up-a-replication-cluster) @@ -185,6 +186,33 @@ docker run --name postgresql -itd \ *By default the unaccent extension is disabled* +# Enabling PostGIS extension + +**Available in versions > `9.4-11`** + +PostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects allowing location queries to be run in SQL. + +You can enable the PostGIS extension on database(s) by specifying `DB_POSTGIS=true`. For example, the following command enables the PostGIS extension for the `dbname` database. + +```bash +docker run --name postgresql -itd \ + --env 'DB_NAME=dbname' --env 'DB_POSTGIS=true' \ + sameersbn/postgresql:9.4-11 +``` + +Additionally, creation of PostGIS topology extension can be enabled by specifying `DB_POSTGIS_TOPOLOGY=true`: + + +```bash +docker run --name postgresql -itd \ + --env 'DB_NAME=dbname' --env 'DB_POSTGIS=true' --env DB_POSTGIS_TOPOLOGY=true \ + sameersbn/postgresql:9.4-11 +``` + +Note that topology extension creation can be enabled only when PostGIS extension is enabled. + +*By default the PostGIS extension is disabled* + ## Granting user access to a database 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. diff --git a/VERSION b/VERSION index da7431a..5cfec21 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.4-12 +9.4-12 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 96cd48d..f2ec8bb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,8 @@ PostgreSQL: - DB_TEMPLATE= - DB_UNACCENT= + - DB_HSTORE= + - DB_POSTGIS= - REPLICATION_MODE= - REPLICATION_USER= diff --git a/runtime/env-defaults b/runtime/env-defaults old mode 100644 new mode 100755 index 8636742..2bdcf44 --- a/runtime/env-defaults +++ b/runtime/env-defaults @@ -19,3 +19,6 @@ DB_PASS=${DB_PASS:-} DB_TEMPLATE=${DB_TEMPLATE:-template1} DB_UNACCENT=${DB_UNACCENT:-false} +DB_HSTORE=${DB_HSTORE:-false} +DB_POSTGIS=${DB_POSTGIS:-false} +DB_POSTGIS_TOPOLOGY=${DB_POSTGIS_TOPOLOGY:-false} \ No newline at end of file diff --git a/runtime/functions b/runtime/functions index 93f2049..31b8c4b 100755 --- a/runtime/functions +++ b/runtime/functions @@ -323,6 +323,20 @@ create_database() { psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS unaccent;" >/dev/null 2>&1 fi + if [[ ${DB_HSTORE} == true ]]; then + echo "‣ Loading hstore extension..." + psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS hstore;" >/dev/null 2>&1 + fi + + if [[ ${DB_POSTGIS} == true ]]; then + echo "‣ Loading PostGIS extension..." + psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS postgis;" >/dev/null 2>&1 + if [[ ${DB_POSTGIS_TOPOLOGY} == true ]]; then + echo "‣ Loading PostGIS Topology extension..." + psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS postgis_topology;" >/dev/null 2>&1 + fi + fi + if [[ -n ${DB_USER} ]]; then echo "‣ Granting access to ${DB_USER} user..." psql -U ${PG_USER} -c "GRANT ALL PRIVILEGES ON DATABASE \"${database}\" to \"${DB_USER}\";" >/dev/null