Hi I’m trying to enable PostGIS extension in kubernetes stolon cluster .
The problem is initdb-postgis.sh not executed in stolon cluster so there’s no database named gis and also extensions not enabled. And also i’ve changed deployment and statefulset yamls images.
I don’t know what i missed.
When i access the instance with psql i get this results:
\dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(1 row)
\l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+------------+------------+-------------------
postgres | stolon | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | stolon | UTF8 | en_US.utf8 | en_US.utf8 | =c/stolon +
| | | | | stolon=CTc/stolon
template1 | stolon | UTF8 | en_US.utf8 | en_US.utf8 | =c/stolon +
| | | | | stolon=CTc/stolon
(3 rows)
I’ve created my stolon image with
make PGVERSION=10 TAG=ieud:pg11 docker
My Dockerfile is:
COPY . .
RUN make
#######
####### Build the final image
######
##
LABEL maintainer="PostGIS Project - https://postgis.net"
FROM postgres:$PGVERSION
RUN useradd -ms /bin/bash stolon
ENV POSTGIS_MAJOR 2.5
ENV POSTGIS_VERSION 2.5.5+dfsg-1.pgdg90+2
RUN apt-get update \
&& apt-cache showpkg postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR \
&& apt-get install -y --no-install-recommends \
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir -p /docker-entrypoint-initdb.d
COPY ./initdb-postgis.sh /docker-entrypoint-initdb.d/10_postgis.sh
COPY ./update-postgis.sh /usr/local/bin
EXPOSE 5432
# copy the agola-web dist
COPY --from=builder /stolon/bin/ /usr/local/bin
COPY ./update-postgis.sh /usr/local/bin
RUN chmod +x /usr/local/bin/stolon-keeper /usr/local/bin/stolon-sentinel /usr/local/bin/stolon-proxy /usr/local/bin/stolonctl /docker-entrypoint-initdb.d/10_postgis.sh /usr/local/bin/update-postgis.sh
And my ./initdb-postgis.sh is
#!/bin/sh
set -e
# Perform all actions as $POSTGRES_USER
export PGUSER="$POSTGRES_USER"
# create databases
psql -c "CREATE DATABASE gis;"
# add extensions to databases
psql gis -c "CREATE EXTENSION IF NOT EXISTS postgis;"
psql gis -c "CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;"
#psql gis -c "CREATE EXTENSION IF NOT EXISTS addressing_dictionary;"
# restore database if dump file exists
if [ -f /opt/backups/restore.dump ]; then
echo "Restoring backup..."
pg_restore -d gis --clean --if-exists /opt/backups/restore.dump
fi