Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hstore extension #53

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MAINTAINER [email protected]

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 \
Expand All @@ -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 \
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.4-12
9.4-12
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ PostgreSQL:
- DB_TEMPLATE=

- DB_UNACCENT=
- DB_HSTORE=
- DB_POSTGIS=

- REPLICATION_MODE=
- REPLICATION_USER=
Expand Down
3 changes: 3 additions & 0 deletions runtime/env-defaults
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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}
14 changes: 14 additions & 0 deletions runtime/functions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down