Crunchy Postgres提供了在kubernetes/openshift上运行的一种机制,用起来非常方便,它包括了Postgres, pgbackrest, pgbouncer, patroni, postgres-exporter等开源组件,它的Operator是用go语言开发的,开源的。Crunchy提供了企业级的Postgresql的功能,这里不在赘述。 crunchy postgres operator 是开源的,但是想免费的在生产环境中使用它是不行的,因为它提供的container docker image只能用在development环境,如果你想用在非development环境,是需要向crunchy公司订阅的。我们不禁想到构建自己的docker images,而不是使用crunchy提供的images。 Crunchy postgres提供了构建container docker image的Dockerfile,但是如果你不是crunchy的客户,是没法直接使用这些Dockerfile的,因为在这些Dockerfile中,它使用的是Crunchy自己的一个私有rpm package的仓库来安装软件包。 那么是不是可以使用Postgresql的community的repository来代替crunchy的私有repository,然后修改Dockerfile来构建container docker image?答案是可以的,但是这个地方需要做很多工作,因为crunchy的私有rpm package和Postgresql community的rpm package不是完全一样的,它做了一些customization的工作,尤其是对于pgbackrest这个package的rpm。我个人的一个建议是: 在Dockerfile中把这些customization的地方实现。 我的一个是用心得是尽量不要从 registry.developers.crunchydata.com pull docker 镜像,有时候pull到的image有问题,具体原因我不清楚,但从 registry.connect.redhat.com pull的镜像就没有问题了,这个问题是我在某一个版本(v5.3.0)中遇到的。其他版本还没有发现。 如果你既想使用crunchy提供的image,又想要做一些改动,比如安装新版本的软件,加入自己的extension等,这个还是比较容易做到的,如下是一个Dockerfile例子:
FROM registry.connect.redhat.com/crunchydata/crunchy-postgres:ubi8-14.6-2
USER root
ENV PGROOT="/usr/pgsql-14"
ENV PATH="${PGROOT}/bin:${PATH}"
RUN rpm -ivh https://mirrors.huaweicloud.com/postgresql/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm && \
mv /etc/yum.repos.d/crunchypg14.repo /tmp/ && \
mv /etc/yum.repos.d/ubi.repo /tmp/ && \
rpm -e pg_cron_14-1.4.2-0Crunchy.el8.x86_64 && \
rpm -e orafce_14-3.25.1-0Crunchy.el8.x86_64 && \
rpm -e timescaledb_14-2.8.1-0Crunchy.el8.x86_64 && \
rpm -e wal2json_14-2.5-0Crunchy.el8.x86_64 && \
rpm -e pg_partman_14-4.7.1-0Crunchy.el8.x86_64 && \
rpm -e pgaudit14-1.6.2-0Crunchy.el8.x86_64 && \
rpm -e python3-psycopg2-2.9.3-0Crunchy.el8.x86_64 && \
rpm -e pgaudit14_set_user-3.0.0-0Crunchy.el8.x86_64 && \
rpm -e pgaudit_analyze-1.0.8-1Crunchy.el8.x86_64 && \
microdnf install -y postgresql14-devel-14.6 orafce_14 pg_cron_14 timescaledb_14 wal2json_14 pg_partman_14 pgaudit16_14 python3-psycopg2 set_user_14 pgaudit_analyze redhat-rpm-config openssl-devel && \
mv /tmp/crunchypg14.repo /etc/yum.repos.d/ && \
mv /tmp/ubi.repo /etc/yum.repos.d/ && \
microdnf -y clean all
USER 26
这里我使用华为的Postgresql repo,没有使用Postgresql community的repo,我发现Postgresql community的repo经常丢掉一些package,或者版本不全,之前我经常和 pgsql-pkg-yum@lists.postgresql.org发邮件反映,他们再fix这些问题,时间久了觉得实在是烦,最近发现华为的repo就没有这个问题。
