pg_cron
pg_cron copied to clipboard
Added pg_cron to Alpine Linux
I've added pg_cron to the Alpine Linux distribution; this because alpine is heavily used within docker environments, so pg_cron can be used within a docker container which runs postgresql on Alpine.
Currently it's only available for the latest 'edge' branch under testing. https://pkgs.alpinelinux.org/packages?name=pg_cron&branch=&repo=&arch=&maintainer=
Architectures:
- aarch64
- armhf
- x86
- x86_64
Question: Currently the latest version is a release candidate, is there any information when the final 1.0.0 will be released ?
Awesome!
Currently the latest version is a release candidate, is there any information when the final 1.0.0 will be released ?
Should be in the next 2 weeks.
@marcocitus great to know the final will be released soon. I suggest to keep this issue open until then. Can you send a message or update this issue so I will get a notification. So I can update the alpine package?
Thanks in advance. Gert
@marcocitus are you still on schedule for the 1.0.0 final release ?
Bump. Coming here looking for an easy solution for install pg_cron on alpine or ubuntu.
I've tried apk add --update pg_cron
but it's didn't work. Any update on this, please?
Coming here looking for an easy solution for install pg_cron on alpine or ubuntu.
Ubuntu packages are available from: https://wiki.postgresql.org/wiki/Apt Alpine packages are available from: https://pkgs.alpinelinux.org/packages?name=pg_cron&branch=&repo=&arch=&maintainer=
Current version is 1.0.2
You can build it directly with this script (tested on alpine 3.6 and 3.7), concretely with the official postgres-alpine image postgres:10.1-alpine
:
PG_CRON_VERSION=1.0.2
apk add --no-cache --virtual .build-deps build-base ca-certificates openssl tar \
&& wget -O /pg_cron.tgz https://github.com/citusdata/pg_cron/archive/v$PG_CRON_VERSION.tar.gz \
&& tar xvzf /pg_cron.tgz && cd pg_cron-$PG_CRON_VERSION \
&& sed -i.bak -e 's/-Werror//g' Makefile \
&& sed -i.bak -e 's/-Wno-implicit-fallthrough//g' Makefile \
&& make && make install \
&& cd .. && rm -rf pg_cron.tgz && rm -rf pg_cron-*
That's what I'm doing right now for our postgres docker image.
@marcocitus, @GJRTimmer pg_cron
package ver 1.0.2-r0
is only available on edge branch, which is suposingly not stable enough for production usage. Please consider add it to v3.7
or v3.6
if you consider the package is production ready.
I'm using the following Dockerfile to add pg_cron to the Postgres image based on Ubuntu:
FROM postgres:9.6
# Follow the instructions on https://wiki.postgresql.org/wiki/Apt
# to install pg_cron
RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
RUN apt-get update
RUN apt-get install -y wget ca-certificates
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update
RUN apt-get install -y postgresql-9.6-cron
CMD ["-c", "cron.database_name=app", "-c", "shared_preload_libraries=pg_cron"]
It works but being a relatively inexperienced Docker user, I haven't yet managed to make database_name configurable through an environment variable. Maybe someone here knows how to improve on this.
If you're wondering how the Alpine page is called: postgresql-pg_cron
in community/edge: https://pkgs.alpinelinux.org/packages?name=postgresql-pg_cron
Install: apk add postgresql-pg_cron --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
For pg_cron 1.3.0 you can use this slightly modified version from @danigosa
FROM postgres:13-alpine
ENV PG_CRON_VERSION 1.3.0
RUN apk add --no-cache --virtual .build-deps build-base ca-certificates clang-dev llvm10 openssl tar \
&& wget -O /pg_cron.tgz https://github.com/citusdata/pg_cron/archive/v$PG_CRON_VERSION.tar.gz \
&& tar xvzf /pg_cron.tgz && cd pg_cron-$PG_CRON_VERSION \
&& sed -i.bak -e 's/-Werror//g' Makefile \
&& sed -i.bak -e 's/-Wno-implicit-fallthrough//g' Makefile \
&& make && make install \
&& cd .. && rm -rf pg_cron.tgz && rm -rf pg_cron-* \
&& apk del .build-deps
CMD ["-c", "shared_preload_libraries=pg_cron", "-c", "cron.database_name=postgres"]
If you're pushing these images into a registry or would otherwise like to save ~160MB [all those build deps you installed] on your image size, use a multistage build and only copy the pg_cron.so
into the final image. Eg:
FROM postgres:XX-alpine as build
ENV ...
RUN ...
FROM postgres:XX-alpine as release
COPY --from=build /usr/local/lib/postgresql/pg_cron.so /usr/local/lib/postgresql/pg_cron.so
If you're pushing these images into a registry or would otherwise like to save ~160MB [all those build deps you installed] on your image size, use a multistage build and only copy the
pg_cron.so
into the final image.
Having the .so
is not enough. The following files are also needed:
-
.control
file to show the default version and package name -
.sql
files for schema migrations on extension updates
For pg_cron 1.3.0 you can use this slightly modified version from @danigosa
FROM postgres:13-alpine ENV PG_CRON_VERSION 1.3.0 RUN apk add --no-cache --virtual .build-deps build-base ca-certificates clang-dev llvm10 openssl tar \ && wget -O /pg_cron.tgz https://github.com/citusdata/pg_cron/archive/v$PG_CRON_VERSION.tar.gz \ && tar xvzf /pg_cron.tgz && cd pg_cron-$PG_CRON_VERSION \ && sed -i.bak -e 's/-Werror//g' Makefile \ && sed -i.bak -e 's/-Wno-implicit-fallthrough//g' Makefile \ && make && make install \ && cd .. && rm -rf pg_cron.tgz && rm -rf pg_cron-* \ && apk del .build-deps CMD ["-c", "shared_preload_libraries=pg_cron", "-c", "cron.database_name=postgres"]
Hi.. does it work for 'postgres:12-alpine'. I used PG_CRON_VERSION=1.2.0 but the postgesql.conf file didn't change.
Does this package work or am I missing some extra steps to set it up? Here's my Dockerfile
:
FROM public.ecr.aws/docker/library/postgres:13-alpine
RUN apk add postgresql-pg_cron
CMD ["-c", "shared_preload_libraries=pg_cron", "-c", "cron.database_name=postgres", "-c", "log_statement=all"]
But when container is started I'm getting the following error:
PostgreSQL Database directory appears to contain a database; Skipping initialization
2022-12-19 10:17:20.827 UTC [97] FATAL: could not access file "pg_cron": No such file or directory
2022-12-19 10:17:20.827 UTC [97] LOG: database system is shut down
The pg_cron.so
is installed /usr/lib/postgresql14/pg_cron.so
:
-rwxr-xr-x 1 root root 71792 Nov 12 2021 pg_cron.so
-rwxr-xr-x 1 root root 22192 Aug 15 00:19 pgoutput.so
-rwxr-xr-x 1 root root 198400 Aug 15 00:19 plpgsql.so
pg_cron.control
is present at /usr/share/postgresql14/extension/pg_cron.control
along with .sql files:
comment = 'Job scheduler for PostgreSQL'
default_version = '1.4'
module_pathname = '$libdir/pg_cron'
relocatable = false
FROM public.ecr.aws/docker/library/postgres:13-alpine The pg_cron.so is installed /usr/lib/postgresql14/pg_cron.so:
For me it looks like the pg_cron package is built for Postgres 14, and you can't use it with 13.
That explains why I managed to make it work with PostgreSQL 15, though I still had to make some adjustments:
RUN apk add --no-cache postgresql-pg_cron sudo \
&& cp /usr/lib/postgresql15/pg_cron.so /usr/local/lib/postgresql/ \
&& cp /usr/share/postgresql/extension/* /usr/local/share/postgresql/extension
So I guess I should either try another PostgreSQL base image or build pg_cron
from source.
@gjrtimmer Seems like the package is no longer available? https://pkgs.alpinelinux.org/packages?name=pg_cron&branch=edge&repo=&arch=&maintainer=