feat(postgres-runtime): add pgmq support and clean up pg_cache remnants

- remove unused pg_cache build steps
- add pgmq (Postgres message queue) build and installation
- ensure pg_jieba build installs correctly via cmake
- update runtime description to reflect pgmq inclusion
- standardize build-stage layout and file copy structure
This commit is contained in:
Haitao Pan 2025-12-03 17:39:11 +08:00
parent bfc69490fd
commit b59c8f1f2c
2 changed files with 63 additions and 37 deletions

View File

@ -9,75 +9,65 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
wget curl gnupg ca-certificates lsb-release; \
\
wget curl gnupg ca-certificates lsb-release unzip; \
mkdir -p /usr/share/keyrings; \
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
| gpg --dearmor >/usr/share/keyrings/pgdg.gpg; \
\
echo "deb [signed-by=/usr/share/keyrings/pgdg.gpg] \
http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
> /etc/apt/sources.list.d/pgdg.list; \
apt-get update;
# ---------------------------------------------------------
# Stage 1 — Build Extensions: pg_jieba / pg_cache
# Stage 1 — Build Extensions: pg_jieba + pgmq (SQL-only)
# ---------------------------------------------------------
FROM pgdg-base AS builder
ARG PG_MAJOR=16
ARG PG_JIEBA_REPO=https://github.com/jaiminpan/pg_jieba.git
ARG PG_CACHE_REPO=https://github.com/jaiminpan/pg_cache.git
ARG PGMQ_VERSION=0.18.2
RUN set -eux; \
apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
pkg-config \
libicu-dev \
build-essential cmake git pkg-config libicu-dev \
postgresql-server-dev-${PG_MAJOR}; \
\
temp_dir="$(mktemp -d)"; \
\
# -----------------------------------------------------
# Build pg_jieba (fix missing cppjieba include)
# -----------------------------------------------------
git clone --depth 1 "${PG_JIEBA_REPO}" "$temp_dir/pg_jieba"; \
temp_dir="$(mktemp -d)";
# ---------------------------------------------------------
# Build pg_jieba
# ---------------------------------------------------------
RUN git clone --depth 1 "${PG_JIEBA_REPO}" "$temp_dir/pg_jieba"; \
cd "$temp_dir/pg_jieba"; \
git submodule update --init --recursive --depth 1 || true; \
\
# Fix include path mismatch: cppjieba → third_party/cppjieba
ln -s "$temp_dir/pg_jieba/third_party/cppjieba" \
"$temp_dir/pg_jieba/cppjieba"; \
\
cmake -S "$temp_dir/pg_jieba" \
-B "$temp_dir/pg_jieba/build" \
-DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql/${PG_MAJOR}/server; \
cmake --build "$temp_dir/pg_jieba/build" --config Release -- -j"$(nproc)"; \
cmake --install "$temp_dir/pg_jieba/build"; \
\
# -----------------------------------------------------
# Build pg_cache
# -----------------------------------------------------
git clone --depth 1 "${PG_CACHE_REPO}" "$temp_dir/pg_cache"; \
make -C "$temp_dir/pg_cache" \
PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR}/bin/pg_config \
-j"$(nproc)"; \
make -C "$temp_dir/pg_cache" \
PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR}/bin/pg_config install; \
\
rm -rf "$temp_dir";
cmake --install "$temp_dir/pg_jieba/build";
# ---------------------------------------------------------
# Stage 2 — Runtime (PostgreSQL + pgvector + extensions)
# Install pgmq (SQL-only extension)
# ---------------------------------------------------------
RUN mkdir -p "$temp_dir/pgmq"; \
curl -fsSL -o "$temp_dir/pgmq/pgmq.zip" \
"https://github.com/tembo-io/pgmq/archive/refs/tags/v${PGMQ_VERSION}.zip"; \
unzip "$temp_dir/pgmq/pgmq.zip" -d "$temp_dir/pgmq"; \
cp "$temp_dir/pgmq/pgmq-${PGMQ_VERSION}/sql/pgmq.control" \
/usr/share/postgresql/${PG_MAJOR}/extension/; \
cp "$temp_dir/pgmq/pgmq-${PGMQ_VERSION}/sql/"*.sql \
/usr/share/postgresql/${PG_MAJOR}/extension/;
RUN rm -rf "$temp_dir";
# ---------------------------------------------------------
# Stage 2 — Runtime
# ---------------------------------------------------------
FROM pgdg-base AS runtime
LABEL maintainer="XControl" \
description="PostgreSQL 16 + pgvector + pg_jieba + pg_cache (Ubuntu 24.04 Runtime)"
description="PostgreSQL 16 + pgvector + pg_jieba + pgmq (Ubuntu 24.04 Runtime)"
ARG PG_MAJOR=16
ARG PGVECTOR_PACKAGE=postgresql-16-pgvector
@ -91,11 +81,15 @@ RUN set -eux; \
${PGVECTOR_PACKAGE}; \
rm -rf /var/lib/apt/lists/*;
# ---------------------------------------------------------
# Copy compiled shared libraries (*.so)
# ---------------------------------------------------------
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/*.so \
/usr/lib/postgresql/${PG_MAJOR}/lib/
# ---------------------------------------------------------
# Copy extension sql/control files
# ---------------------------------------------------------
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension \
/usr/share/postgresql/${PG_MAJOR}/extension

View File

@ -0,0 +1,32 @@
# TL;DR PostgreSQL Multi-Model Runtime
A lightweight PostgreSQL build providing **Search + Vector + KV + MQ + JSONB**
as a unified data engine for CloudNeutral-Suite applications.
## Includes
- **pg_jieba** Chinese full-text tokenizer
- **pg_trgm** fuzzy search and typo tolerance
- **pgvector** embeddings and semantic search
- **pgmq** lightweight message queue (Kafka-lite)
- **JSONB + GIN** document store and structured filtering
- **hstore + UNLOGGED tables** high-speed key/value cache
## Use Cases
- Documentation, product, and FAQ search
- RAG and embedding-based retrieval
- Application-level KV/session/cache
- Lightweight event queues and workflows
- JSONB content and metadata storage
- Hybrid keyword + semantic search
## Not Included
Platform-level or DBA-oriented extensions are intentionally excluded:
- timescaledb
- pg_partman
- pg_cron
- pg_net
## Why
Keeps the runtime focused, predictable, and portable —
a single ACID engine replacing MongoDB + Redis + Kafka + Elasticsearch + Pinecone
for application-scale workloads.