From 280f2d8d33870b1dfdbda494b0b3a0e91262e2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wieche=C4=87?= Date: Fri, 18 Dec 2015 09:49:06 +0100 Subject: [PATCH 1/7] installing postgis packages --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f0870e8..e7e702c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ ENV PG_APP_HOME="/etc/docker-postgresql"\ PG_HOME=/var/lib/postgresql \ PG_RUNDIR=/run/postgresql \ PG_LOGDIR=/var/log/postgresql \ - PG_CERTDIR=/etc/postgresql/certs + PG_CERTDIR=/etc/postgresql/certs \ + PG_POSTGIS_VERSION=2.1 ENV PG_BINDIR=/usr/lib/postgresql/${PG_VERSION}/bin \ PG_DATADIR=${PG_HOME}/${PG_VERSION}/main @@ -15,7 +16,7 @@ ENV PG_BINDIR=/usr/lib/postgresql/${PG_VERSION}/bin \ RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ && echo 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main' > /etc/apt/sources.list.d/pgdg.list \ && apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION} \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION} postgresql-${PG_VERSION}-postgis-${PG_POSTGIS_VERSION} postgresql-${PG_VERSION}-postgis-${PG_POSTGIS_VERSION}-scripts \ && 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 \ From bbd12cf8fa9eb2f42d85d11685e1d194a368964d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wieche=C4=87?= Date: Fri, 18 Dec 2015 09:49:19 +0100 Subject: [PATCH 2/7] adding docs --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 4cf2e63..dbadd70 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,18 @@ docker run --name postgresql -itd \ sameersbn/postgresql:9.4-11 ``` +# Enabling PostGIS extension + +PostGIS is spatial extension to PostgreSQL. + +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. + +```bash +docker run --name postgresql -itd \ + --env 'DB_NAME=dbname' --env 'DB_POSTGIS=true' \ + sameersbn/postgresql:9.4-11 +``` + *By default the unaccent extension is disabled* ## Granting user access to a database From c017a10d8b0f185af8dc1518173bb23acc85a3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wieche=C4=87?= Date: Fri, 18 Dec 2015 09:49:32 +0100 Subject: [PATCH 3/7] adding vars for postgis extension --- runtime/env-defaults | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/env-defaults b/runtime/env-defaults index 17e374b..84f5efe 100644 --- a/runtime/env-defaults +++ b/runtime/env-defaults @@ -18,3 +18,7 @@ DB_USER=${DB_USER:-} DB_PASS=${DB_PASS:-} DB_UNACCENT=${DB_UNACCENT:-false} + +DB_POSTGIS=${DB_POSTGIS:-false} +DB_POSTGIS_HSTORE=${DB_POSTGIS_HSTORE:-true} +DB_POSTGIS_TOPOLOGY=${DB_POSTGIS_TOPOLOGY:-true} From 57abc71320ba20293c34c54700e96d6c382d33da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wieche=C4=87?= Date: Fri, 18 Dec 2015 10:25:13 +0100 Subject: [PATCH 4/7] adding routines to create PostGIS-enabled database normally, to enable PostGIS for a database (including template db), issuing CREATE EXTENSION IF NOT EXISTS postgis; should suffice. However, this is not working in single-user mode (see http://stackoverflow.com/q/28147177/1547895). Instead, we are running PostGIS's SQL scripts. --- runtime/functions | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/runtime/functions b/runtime/functions index 128b535..250a7ff 100755 --- a/runtime/functions +++ b/runtime/functions @@ -308,8 +308,31 @@ create_database() { echo -n "Creating database(s): " for database in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do echo -n "${database} " - echo "CREATE DATABASE \"${database}\";" | \ - exec_as_postgres ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} >/dev/null 2>&1 + + if [[ ${DB_POSTGIS} == true ]]; then + + echo "CREATE DATABASE template_postgis WITH ENCODING = 'UTF8' TEMPLATE = template0;" | \ + exec_as_postgres ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} >/dev/null 2>&1 + + echo "UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';" | \ + exec_as_postgres ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} >/dev/null 2>&1 + + # because we can't create extensions in single-user mode, we will just read the SQL code for PostGIS + PG_POSTGIS_HOME=/usr/share/postgresql/${PG_VERSION}/contrib/postgis-${PG_POSTGIS_VERSION} + exec_as_postgres ${PG_BINDIR}/postgres --single template_postgis -D ${PG_DATADIR} -j \ + < ${PG_POSTGIS_HOME}/postgis.sql >/dev/null 2>&1 + exec_as_postgres ${PG_BINDIR}/postgres --single template_postgis -D ${PG_DATADIR} -j \ + < ${PG_POSTGIS_HOME}/topology.sql >/dev/null 2>&1 + exec_as_postgres ${PG_BINDIR}/postgres --single template_postgis -D ${PG_DATADIR} -j \ + < ${PG_POSTGIS_HOME}/spatial_ref_sys.sql >/dev/null 2>&1 + + # create PostGIS database + echo "CREATE DATABASE \"${database}\" WITH TEMPLATE = template_postgis;" | \ + exec_as_postgres ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} >/dev/null 2>&1 + else + echo "CREATE DATABASE \"${database}\";" | \ + exec_as_postgres ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} >/dev/null 2>&1 + fi if [[ ${DB_UNACCENT} == true ]]; then echo "CREATE EXTENSION IF NOT EXISTS unaccent;" | \ From d7032183632d17bbaa2cc21e3bfffc948dc02a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wieche=C4=87?= Date: Fri, 18 Dec 2015 10:29:25 +0100 Subject: [PATCH 5/7] version bump --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index f36be50..fadb404 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.4-11 +9.4-11-postgis From b598e0a22326a28ee8de2769d2f814aa2bdfee1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wieche=C4=87?= Date: Fri, 18 Dec 2015 10:30:33 +0100 Subject: [PATCH 6/7] version bump --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index fadb404..fafb501 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.4-11-postgis +9.4-12-snapshot From 8c0a352a1050bda180946aec93511ec5489e7610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wieche=C4=87?= Date: Fri, 18 Dec 2015 10:42:10 +0100 Subject: [PATCH 7/7] updating TOC --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbadd70..41e8e2b 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) @@ -180,6 +181,7 @@ docker run --name postgresql -itd \ --env 'DB_NAME=dbname' --env 'DB_UNACCENT=true' \ sameersbn/postgresql:9.4-11 ``` +*By default the unaccent extension is disabled* # Enabling PostGIS extension @@ -192,8 +194,7 @@ docker run --name postgresql -itd \ --env 'DB_NAME=dbname' --env 'DB_POSTGIS=true' \ sameersbn/postgresql:9.4-11 ``` - -*By default the unaccent extension is disabled* +*By default the PostGIS extension is disabled* ## Granting user access to a database