CREATE EXTENSION from /docker-entrypoint-initdb.d
I'm trying to create Docker image based on citusdata/citus:7.5.1. Accordingly to Docker Postgres documentation there is a folder /docker-entrypoint-initdb.d/ where init scripts (both sql and sh) can be put. I use the following scripts:
-- pg-extension-init.sql
CREATE EXTENSION pg_cron;
CREATE SCHEMA jobmon;
CREATE EXTENSION pg_jobmon SCHEMA jobmon CASCADE;
CREATE SCHEMA partman;
CREATE EXTENSION pg_partman SCHEMA partman CASCADE;
and
#!/usr/bin/env bash
# pg-extension-config.sh
shared_preload_libraries=citus,pg_cron,pg_partman_bgw
sed -i "s/shared_preload_libraries='citus'/#shared_preload_libraries='citus'\nshared_preload_libraries='${shared_preload_libraries}'/" /var/lib/postgresql/data/postgresql.conf
printf "\n" >> /var/lib/postgresql/data/postgresql.conf
printf "cron.database_name = 'postgres'\n" >> /var/lib/postgresql/data/postgresql.conf
printf "pg_partman_bgw.dbname='postgres'\n" >> /var/lib/postgresql/data/postgresql.conf
printf "pg_partman_bgw.interval=60\n" >> /var/lib/postgresql/data/postgresql.conf
printf "pg_partman_bgw.role='postgres'\n" >> /var/lib/postgresql/data/postgresql.conf
My Docker file:
FROM citusdata/citus:7.5.1
COPY pg-extension-config.sh /docker-entrypoint-initdb.d/
COPY pg-extension-init.sql /docker-entrypoint-initdb.d/
RUN apt-get update && \
apt-get install -y gcc && \
apt-get install -y make && \
apt-get install -y wget && \
apt-get install -y postgresql-server-dev-10 && \
echo "*** Installing pg_jobmon extension ***" && \
mkdir /tmp/pg_jobmon && \
cd /tmp/pg_jobmon && \
wget https://github.com/omniti-labs/pg_jobmon/archive/v1.3.3.tar.gz && \
tar xzf v1.3.3.tar.gz --strip-components=1 && \
make && \
make install && \
echo "*** Installing pg_partman extension ***" && \
mkdir /tmp/pg_partman && \
cd /tmp/pg_partman && \
wget https://github.com/pgpartman/pg_partman/archive/4.0.0.tar.gz && \
tar xzf 4.0.0.tar.gz --strip-components=1 && \
make && \
make install && \
echo "*** Installing pg_cron extension ***" && \
mkdir /tmp/pg_cron && \
cd /tmp/pg_cron && \
wget https://github.com/citusdata/pg_cron/archive/v1.1.2.tar.gz && \
tar xzf v1.1.2.tar.gz --strip-components=1 && \
make && \
make install && \
echo "*** Cleaning the container ***" && \
cd / && \
rm -r /tmp/pg_partman /tmp/pg_jobmon /tmp/pg_cron && \
apt-get purge -y gcc && \
apt-get purge -y make && \
apt-get purge -y wget && \
apt-get purge -y postgresql-server-dev-10 && \
apt-get autoremove --purge -y
I figured out that creating pg_cron extension using init script doesn't work (despite that other extensions are created successfully). During container startup I'm getting the following error:
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/pg-extension-init.sql
2018-10-16 13:43:13.159 UTC [94] ERROR: unrecognized configuration parameter "cron.database_name"
2018-10-16 13:43:13.159 UTC [94] CONTEXT: PL/pgSQL function inline_code_block line 3 at IF
2018-10-16 13:43:13.159 UTC [94] STATEMENT: CREATE EXTENSION pg_cron;
psql:/docker-entrypoint-initdb.d/pg-extension-init.sql:2: ERROR: unrecognized configuration parameter "cron.database_name"
CONTEXT: PL/pgSQL function inline_code_block line 3 at IF
But creating extension in running container (after excluding corresponding line from init sql script) works fine. Is it a bug? It's not clear from documentation how it should perform. Is there any workaround to create pg_cron extension during image build?
Have the same problem... Try https://stackoverflow.com/a/51797554
@peppered
I've created a Postgres 11 docker image which contains a successful installation of pg_cron. I hope it helps.