If I create the pg_cron extension in a docker-entrypoint-initdb.d/init.sql
file, the docker image fails to run and docker logs <id>
just says "No such container." Here's the relevant .sql snippet:
CREATE DATABASE my_database;
\c my_database;
CREATE EXTENSION IF NOT EXISTS postgis CASCADE;
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
CREATE EXTENSION IF NOT EXISTS pg_cron CASCADE;
However, if I create the pg_cron extension after the docker run command completes (i.e. remove the last line above and run it separately with psql --file
after docker run
completes), the extension gets created successfully (postgis and timescaledb extensions seem to be fine regardless).
Is there a reason I can't create the pg_cron extension from docker-entrypoint-init.d
? Is there a correct place?
My docker run command is as follows:
docker run -d \
--name my_container --rm \
-p 5432:5432 \
-clog_line_prefix="%m [%p]: [%l-1] %u@%d" \
-clog_error_verbosity=VERBOSE \
-cshared_preload_libraries='timescaledb,pg_cron' \
-ccron.database_name='my_database'