CREATE EXTENSION from /docker-entrypoint-initdb.d
- Dominant language
- C
- Stars
- 3.9k
- Forks
- 260
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 1
Description
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?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the startup sequence with pg-extension-config.sh and pg-extension-init.sql under /docker-entrypoint-initdb.d/, then read /usr/local/bin/docker-entrypoint.sh and the reported CREATE EXTENSION failure. Determine why cron.database_name is unavailable during initialization while the extension works later. Done means pg_cron can be created during image initialization without the configuration error, or the required workaround is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, postgresql, shell, sql
- Domain
- databases, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100