# docker build -f pgsql.df -t jiagou/pgsql:v18.6 .
## 完成之后,注意检查修改 max_connections = 5000
### 注意修改 paradedb 的 docker/bootstrap.sh
# psql -v ON_ERROR_STOP=1 -d "$1" <<-'EOSQL'
# CREATE EXTENSION IF NOT EXISTS age;
# LOAD 'age';
# CREATE EXTENSION IF NOT EXISTS vector;
# 最后加上
## Add the `paradedb` schema to template1, paradedb, and $POSTGRES_DB
## search_path 增加 ag_catalog,支持 age 扩展
# for DB in template1 paradedb "$POSTGRES_DB"; do
# echo "Adding 'paradedb' search_path to $DB"
# psql -d "$DB" -c "ALTER DATABASE \"$DB\" SET search_path TO ag_catalog,public,paradedb;"
# done
##
##
FROM postgres:18.6-trixie AS build-age
ENV TZ=Asia/Shanghai
ENV PGTZ=Asia/Shanghai
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
RUN apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
bison \
build-essential \
flex \
postgresql-server-dev-18
RUN apt install git -y && git clone -b PG18/v1.8.0-rc0 https://github.com/apache/age.git && cd age && git checkout PG18/v1.8.0-rc0 && make && make install
# RUN make && make install
# Note: Debian Trixie = Debian 13
FROM postgres:18.6-trixie
ENV TZ=Asia/Shanghai
ENV PGTZ=Asia/Shanghai
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
RUN apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
locales
RUN echo "zh_CN.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen \
&& update-locale LANG=zh_CN.UTF-8
ENV LANG=zh_CN.UTF-8
ENV LC_COLLATE=zh_CN.UTF-8
ENV LC_CTYPE=zh_CN.UTF-8
# Install pg_search from GitHub Releases
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends ca-certificates curl; \
arch="$(dpkg --print-architecture)"; \
case "$arch" in \
amd64) checksum="039c7e13beaf8ef400440a7992f4b94d4bae00ce6ec6af803ae0e8c5fdac1d6d" ;; \
arm64) checksum="04661187439835efaef6cf396b5f2c3970d2277d2b1028893881046e2ca11526" ;; \
*) echo "unsupported architecture: $arch" >&2; exit 1 ;; \
esac; \
curl -fsSL -o /tmp/pg_search.deb "https://github.com/paradedb/paradedb/releases/download/v0.26.4/postgresql-18-pg-search_0.26.4-1PARADEDB-trixie_${arch}.deb"; \
echo "${checksum} */tmp/pg_search.deb" | sha256sum --strict --check -; \
apt-get install -y --no-install-recommends /tmp/pg_search.deb; \
apt-get purge -y --auto-remove curl; \
rm /tmp/pg_search.deb; \
apt-get dist-clean
# Install Barman Cloud and its dependencies for Azure, Google, and AWS via `pip`, and clean up after the installation to
# minimize the size of the image. These are required for enabling Postgres backups in our CloudNativePG deployments.
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends libpq5 python3-pip python3-dev python3-psycopg2; \
rm /usr/lib/python*/EXTERNALLY-MANAGED; \
pip3 install --no-cache-dir 'setuptools==82.0.1' 'barman[cloud,azure,snappy,google]==3.18.0'; \
apt-get remove -y python3-dev python3-pip --purge; \
apt-get autoremove -y; \
apt-get dist-clean; \
find /usr/lib | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf; \
find /usr/local | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf; \
find /var/cache -type f -exec truncate --size 0 {} \;; \
find /var/log -type f -exec truncate --size 0 {} \;
# Install core extensions
# Use the PGDG archive so these pinned extension versions remain available after newer
# versions replace them in the live Debian and PGDG apt repositories.
ENV POSTGIS_VERSION_MAJOR=3
RUN set -eux; \
apt-get update; \
echo "deb [ signed-by=/usr/local/share/keyrings/postgres.gpg.asc ] https://apt-archive.postgresql.org/pub/repos/apt trixie-pgdg-archive main" > /etc/apt/sources.list.d/pgdg-archive.list; \
apt-get update; \
apt-get install -y --no-install-recommends \
postgresql-18-pgvector=0.8.6-1.pgdg13+1 \
postgresql-18-cron=1.6.7-3.pgdg13+1 \
postgresql-18-pg-ivm=1.13-1.pgdg13+1 \
postgresql-18-postgis-$POSTGIS_VERSION_MAJOR=3.6.4+dfsg-2.pgdg13+1 \
postgresql-18-postgis-$POSTGIS_VERSION_MAJOR-scripts=3.6.4+dfsg-2.pgdg13+1; \
apt-get dist-clean
# The postgresql.conf.sample file is used as a template for the postgresql.conf file, which
# does not exist until the first time the container is started. By adding our settings to the
# postgresql.conf.sample file, we ensure that our settings are applied onto the postgresql.conf file.
#
# The `postgres` database is the default database that exists in every Postgres installation. The pg_cron
# extension requires a database to store its metadata tables. By using `postgres`, we ensure that it has a
# stable, always-available database for its operations, no matter what other databases are created or deleted.
## 增加 age,
RUN set -eux; \
sed -i "s/^#shared_preload_libraries = ''/shared_preload_libraries = 'age,pg_search,pg_cron,pg_stat_statements'/" /usr/share/postgresql/postgresql.conf.sample; \
grep "shared_preload_libraries = 'age,pg_search,pg_cron,pg_stat_statements'" /usr/share/postgresql/postgresql.conf.sample; \
echo "cron.database_name = 'postgres'" >> /usr/share/postgresql/postgresql.conf.sample; \
echo "pg_stat_statements.track = 'top'" >> /usr/share/postgresql/postgresql.conf.sample
# Copy ParadeDB bootstrap script to install extensions and configure postgresql.conf
COPY ./bootstrap.sh /docker-entrypoint-initdb.d/10_bootstrap_paradedb.sh
## 复制age组件
COPY --from=build-age /usr/lib/postgresql/18/lib/age.so /usr/lib/postgresql/18/lib/
COPY --from=build-age /usr/share/postgresql/18/extension/age--1.8.0.sql /usr/share/postgresql/18/extension/
COPY --from=build-age /usr/share/postgresql/18/extension/age.control /usr/share/postgresql/18/extension/
# The upstream `postgres` Docker image comes with its own `entrypoint.sh` script which
# starts as `root` and then switches to the `postgres` user after running chown and chmod
# on the PostgreSQL data directory. To maintain compatibility with the upstream image and
# ensure that the `postgres` user has the correct permissions on the data directory, we let
# the upstream `entrypoint.sh` script run as the entrypoint and don't specify a custom user.