-
-
Save vothanhkiet/0959dc6d2ea5ad9a105cfcc3eeecf802 to your computer and use it in GitHub Desktop.
Postgres 13 - Alpine - pg_partman with pg_jobmon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM postgres:13-alpine | |
LABEL maintainer="Jordan Gould <[email protected]>" | |
# Based on https://github.com/andreaswachowski/docker-postgres/blob/master/initdb.sh | |
ENV PG_JOBMON_VERSION v1.3.3 | |
ENV PG_PARTMAN_VERSION v4.4.0 | |
# Install pg_jobmon | |
RUN set -ex \ | |
\ | |
&& apk add --no-cache --virtual .fetch-deps \ | |
ca-certificates \ | |
openssl \ | |
tar \ | |
\ | |
&& wget -O pg_jobmon.tar.gz "https://github.com/omniti-labs/pg_jobmon/archive/$PG_JOBMON_VERSION.tar.gz" \ | |
&& mkdir -p /usr/src/pg_jobmon \ | |
&& tar \ | |
--extract \ | |
--file pg_jobmon.tar.gz \ | |
--directory /usr/src/pg_jobmon \ | |
--strip-components 1 \ | |
&& rm pg_jobmon.tar.gz \ | |
\ | |
&& apk add --no-cache --virtual .build-deps \ | |
autoconf \ | |
automake \ | |
g++ \ | |
clang \ | |
llvm \ | |
libtool \ | |
libxml2-dev \ | |
make \ | |
perl \ | |
&& cd /usr/src/pg_jobmon \ | |
&& make \ | |
&& make install \ | |
&& cd / \ | |
&& rm -rf /usr/src/pg_jobmon | |
# Install pg_partman | |
RUN set -ex \ | |
&& wget -O pg_partman.tar.gz "https://github.com/pgpartman/pg_partman/archive/$PG_PARTMAN_VERSION.tar.gz" \ | |
&& mkdir -p /usr/src/pg_partman \ | |
&& tar \ | |
--extract \ | |
--file pg_partman.tar.gz \ | |
--directory /usr/src/pg_partman \ | |
--strip-components 1 \ | |
&& rm pg_partman.tar.gz \ | |
&& cd /usr/src/pg_partman \ | |
&& make \ | |
&& make install \ | |
&& cd / \ | |
&& rm -rf /usr/src/pg_partman \ | |
&& apk del .fetch-deps .build-deps | |
# Copy the init script | |
# The Docker Postgres initd script will run anything | |
# in the directory /docker-entrypoint-initdb.d | |
COPY initdb.sh /docker-entrypoint-initdb.d/initdb.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
echo "Creating dblink extension" | |
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | |
CREATE SCHEMA dblink; | |
CREATE EXTENSION dblink SCHEMA dblink; | |
EOSQL | |
echo "Creating jobmon extension" | |
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | |
CREATE SCHEMA jobmon; | |
CREATE EXTENSION pg_jobmon SCHEMA jobmon; | |
INSERT INTO jobmon.dblink_mapping_jobmon (username, pwd) VALUES ('$POSTGRES_USER', '$POSTGRES_PASSWORD'); | |
EOSQL | |
echo "Creating partman extension" | |
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | |
CREATE SCHEMA partman; | |
CREATE EXTENSION pg_partman SCHEMA partman; | |
EOSQL | |
echo "Adding jobmon permissions" | |
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | |
GRANT USAGE ON SCHEMA jobmon TO $POSTGRES_USER; | |
GRANT USAGE ON SCHEMA dblink TO $POSTGRES_USER; | |
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA jobmon TO $POSTGRES_USER; | |
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA jobmon TO $POSTGRES_USER; | |
GRANT ALL ON ALL SEQUENCES IN SCHEMA jobmon TO $POSTGRES_USER; | |
EOSQL | |
echo "ADDING pg_partman_bgw TO postgresql.conf" | |
echo "shared_preload_libraries = 'pg_partman_bgw'" >> $PGDATA/postgresql.conf | |
echo "pg_partman_bgw.interval = 3600" >> $PGDATA/postgresql.conf | |
echo "pg_partman_bgw.role = '$POSTGRES_USER'" >> $PGDATA/postgresql.conf | |
echo "pg_partman_bgw.dbname = '$POSTGRES_DB'" >> $PGDATA/postgresql.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment