Skip to content

Instantly share code, notes, and snippets.

@deangrant
Last active June 16, 2023 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deangrant/78e985bb388156762a9cd76047148982 to your computer and use it in GitHub Desktop.
Save deangrant/78e985bb388156762a9cd76047148982 to your computer and use it in GitHub Desktop.
Contains code snippets for installing and configuring pg_cron within a container, for full details see https://github.com/citusdata/pg_cron.
# Dockerfile for building a PostgreSQL container image.
FROM postgres:14.7-bullseye
# Copies the init.sql file from the local './postgres'directory to the
# '/docker-entrypoint-initdb.d' directory in the container. This directory
# is where PostgreSQL will look for initialization scripts to run when the
# container is first started.
ADD ./postgres/init.sql /docker-entrypoint-initdb.d/init.sql
# Retrieves new list of packages and installs the pg_cron extension
# for PostgreSQL.
RUN apt-get update && \
apt-get install -y postgresql-14-cron && \
# Starts the pg_cron background worker process, specifies the database and
# timezone in which the background worker will run at startup, and specifies
# the pg_cron extension as a shared library to load.
CMD ["-c", "shared_preload_libraries=pg_cron", \
"-c", "cron.database_name=postgres", \
"-c", "cron.timezone=UTC"]
-- Creates the pg_cron extension.
CREATE EXTENSION pg_cron;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment