pg_cron installation error on postgres 13 Docker image.
Hi, I am using Postgres 13.2 Docker image and I have installed pg_cron using the below command, apt-get -y install postgresql-13-cron But when I try to create pg_cron getting below error,
testdb=# CREATE EXTENSION pg_cron; ERROR: unrecognized configuration parameter "cron.database_name" CONTEXT: PL/pgSQL function inline_code_block line 3 at IF
You need to configure cron.database_name in the postgres config (https://github.com/citusdata/pg_cron#setting-up-pg_cron).
In case of docker, It can be solved in this way (there are probably other/cleaner ways, but this works):
Directory structure:
runtime
docker-entrypoint-initdb.d
000_bash.sh
Dockerfile
Dockerfile:
FROM postgres:13.2
RUN apt-get update && apt-get -y install postgresql-13-cron
COPY runtime/ /
000_bash.sh:
#!/usr/bin/env bash
# use same db as the one from env
dbname="$POSTGRES_DB"
# create custom config
customconf=/var/lib/postgresql/data/custom-conf.conf
echo "" > $customconf
echo "shared_preload_libraries = 'pg_cron'" >> $customconf
echo "cron.database_name = '$dbname'" >> $customconf
chown postgres $customconf
chgrp postgres $customconf
# include custom config from main config
conf=/var/lib/postgresql/data/postgresql.conf
found=$(grep "include = '$customconf'" $conf)
if [ -z "$found" ]; then
echo "include = '$customconf'" >> $conf
fi
till I couldn't configure pg_cron extension in docker Postgres 13
@scientiststwin You can see my implementation Doker Container ... https://github.com/sgrinko/docker-postgres/tree/master/14/docker-postgres