Skip to content

Commit

Permalink
Merge pull request #59 from cybertec-postgresql/postgis-fix
Browse files Browse the repository at this point in the history
Fixes for postgis, config-template & fixes for pg17 on the exporter
  • Loading branch information
Schmaetz authored Nov 25, 2024
2 parents 65c1afb + 062bb81 commit a3e68a4
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ pgbackrest-build:
pgbackrest: pgbackrest-build;

postgres-build:

docker build $(ROOTPATH) \
--file $(ROOTPATH)/docker/postgres/Dockerfile \
--tag cybertec-pg-container/postgres:$(IMAGE_TAG) \
Expand Down
6 changes: 5 additions & 1 deletion docker/exporter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ RUN ${PACKAGER} -y install --nodocs \
&& ${PACKAGER} -y clean all ;

RUN wget https://go.dev/dl/go1.23.0.linux-amd64.tar.gz && tar -xzf go1.23.0.linux-amd64.tar.gz && mv go /usr/local
ENV PATH=$PATH:/usr/local/go/bin

RUN git clone https://github.com/prometheus-community/postgres_exporter.git && cd postgres_exporter && make build
RUN git clone https://github.com/prometheus-community/postgres_exporter.git && cd postgres_exporter \
# fix for pg17
&& git fetch origin pull/1072/head:pr-pg17 && git fetch origin pull/1072/head:pr-pg17 && git merge pr-pg17 \
&& make build;

FROM ${CONTAINERIMAGE}
COPY --from=builder /usr/bin/dumb-init /usr/bin/dumb-init
Expand Down
12 changes: 10 additions & 2 deletions docker/postgres-gis/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ RUN ${PACKAGER} -y update && ${PACKAGER} -y install --nodocs --noplugins --setop
dumb-init \
libicu \
pgbackrest-${PGBACKREST_VERSION} \
cronie \
&& ${PACKAGER} -y clean all;

# install etcdctl
Expand All @@ -65,6 +66,7 @@ RUN curl -L https://github.com/coreos/etcd/releases/download/v${ETCD_VERSION}/et
ENV PATHBACKUP = $PATH

RUN wget https://smarden.org/runit/runit-2.1.2.tar.gz -P /package/
COPY cron_unprivileged.c /package/

# Install pam_oauth2.so
#RUN #git clone -b $PAM_OAUTH2 --recurse-submodules https://github.com/zalando-pg/pam-oauth2.git \
Expand All @@ -73,7 +75,12 @@ RUN wget https://smarden.org/runit/runit-2.1.2.tar.gz -P /package/
#&& curl -sL https://github.com/zalando-pg/pg_auth_mon/archive/$PG_AUTH_MON_COMMIT.tar.gz | tar xz \

RUN pip3 install 'PyYAML<6.0' setuptools pystache loader kazoo meld3 boto python-etcd psutil requests cdiff ydiff --upgrade \
&& pip3 install patroni[kubernetes$EXTRAS]==$PATRONI_VERSION --upgrade \
&& if [[ $PATRONI_VERSION == "multisite-"* ]]; then \
git clone -b $PATRONI_VERSION https://github.com/cybertec-postgresql/patroni; \
pip3 install ./patroni[kubernetes,etcd,etcd3]; \
else \
pip3 install patroni[kubernetes$EXTRAS]==$PATRONI_VERSION --upgrade; \
fi \
&& mkdir /usr/lib/postgresql \
&& git clone -b $PG_PERMISSIONS https://github.com/cybertec-postgresql/pg_permissions.git \
&& git clone -b $SET_USER https://github.com/pgaudit/set_user.git \
Expand Down Expand Up @@ -113,13 +120,14 @@ RUN pip3 install 'PyYAML<6.0' setuptools pystache loader kazoo meld3 boto python
done \
&& ${PACKAGER} -y install --nodocs --noplugins --setopt=install_weak_deps=0 glibc-static \
&& ${PACKAGER} -y clean all;
RUN gcc -s -shared -fPIC -o /usr/local/lib/cron_unprivileged.so /package/cron_unprivileged.c

RUN cd /package && tar -xvzf runit-2.1.2.tar.gz && rm runit-2.1.2.tar.gz \
&& cd admin/runit-2.1.2 && package/install \
&& ln -s /usr/local/bin/runsvdir /usr/bin/runsvdir \
&& rm -rf /pg_permissions /pgextwlist /pg_stat_kcache /pgnodemx /timescaledb /set_user /pam-oauth2 \
&& rm /etc/pgbackrest.conf && rm -rf /var/spool/pgbackrest \
&& ${PACKAGER} -y remove python3-pip python3-wheel python3-dev python3-setuptools git patchutils flatpak glibc-static gcc glibc-devel \
&& ${PACKAGER} -y remove $(rpm -qa "*devel*") python3-pip python3-wheel python3-dev python3-setuptools git patchutils flatpak glibc-static gcc glibc-devel \
&& ${PACKAGER} -y autoremove \
&& ${PACKAGER} -y clean dbcache \
&& ${PACKAGER} -y clean all;
Expand Down
31 changes: 22 additions & 9 deletions launcher/exporter/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@

EXPORTER_DIR='/postgres_exporter'
QUERIE_FOLDER="$EXPORTER_DIR/queries"
VERSION_SPECIFIC_FOLDER="$EXPORTER_DIR/version_specific/$PGVERSION"
FILES="${QUERIE_FOLDER}/*"
touch /tmp/cpo_queries.yaml
TEMP_QUERY_FILE='/tmp/cpo_queries.yaml'

> $TEMP_QUERY_FILE

for file in $FILES
do
if [[ -f ${file?} ]]
then
cat ${file?} >> /tmp/cpo_queries.yaml
else
echo ${FILES}
echo "Query file ${file?} does not exist (it should).."
exit 1
fi
if [[ -f "$file" ]]; then
cat "$file" >> "$TEMP_QUERY_FILE"
else
echo "Query file $file does not exist (it should).."
exit 1
fi
done

# VERSION_FILES="${VERSION_SPECIFIC_FOLDER}/*"
# for version_file in $VERSION_FILES
# do
# if [[ -f "$version_file" ]]; then
# cat "$version_file" >> "$TEMP_QUERY_FILE"
# else
# echo "Version-specific query file $version_file does not exist for PGVERSION $PGVERSION (it should).."
# exit 1
# fi
# done

/bin/postgres_exporter --extend.query-path=/tmp/cpo_queries.yaml #--auto-discover-databases
14 changes: 5 additions & 9 deletions scripts/configure_spilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,18 +1200,14 @@ def main():
if 'extwlist.extensions' not in user_config.get('postgresql', {}).get('parameters', {}):
config['postgresql']['parameters']['extwlist.extensions'] =\
append_extensions(config['postgresql']['parameters']['extwlist.extensions'], version, True)
if placeholders['cpo_monitoring_stack']:
current_libraries = config['postgresql']['parameters'].get('shared_preload_libraries', '')


# Check if cpo_monitoring is enabled
if 'pgnodemx' not in current_libraries.split(','):
if placeholders['cpo_monitoring_stack']:
current_libraries = config['postgresql']['parameters'].get('shared_preload_libraries', '')
if current_libraries and 'pgnodemx' not in current_libraries.split(','):
config['postgresql']['parameters']['shared_preload_libraries'] = current_libraries + ',' + 'pgnodemx'
else:
if not current_libraries:
config['postgresql']['parameters']['shared_preload_libraries'] = 'pgnodemx'


elif current_libraries and 'pgnodemx' not in current_libraries.split(','):
config['postgresql']['parameters']['shared_preload_libraries'] = current_libraries + ',' + 'pgnodemx'

# Ensure replication is available
if 'pg_hba' in config['bootstrap'] and not any(['replication' in i for i in config['bootstrap']['pg_hba']]):
Expand Down
6 changes: 6 additions & 0 deletions scripts/exporter/queries/queries_pgbackrest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# This file adds Queries to monitor pgbackrest
cpo_lastcheck_update_pgbackrest_info:
query: "SELECT now() as last_check from exporter.update_pgbackrest_info();"
metrics:
- last_check:
usage: "GAUGE"
description: "last_check"

cpo_pgbackrest_time_since_backup:
query: "WITH backups AS (
Expand Down

0 comments on commit a3e68a4

Please sign in to comment.