docker exec -it supabase-db bash
root@afe3d0e6ead4:/# ls -l /usr/share/postgresql/15/extension/age*
-rw-r--r-- 1 postgres postgres 105081 Mar 6 08:20 /usr/share/postgresql/15/extension/age--1.5.0.sql
-rw-r--r-- 1 postgres postgres 900 Mar 6 08:20 /usr/share/postgresql/15/extension/age.control
root@afe3d0e6ead4:/# age
因此,出于某种原因,Postgres无法访问扩展文件。我尝试过将年龄添加到Postgres共享预紧库的库,但我认为这不是解决此问题的正确方法。
这是我的dockerfile
FROM supabase/postgres:15.8.1.020 AS builder
# Add proxy configuration
RUN echo 'Acquire::http::Pipeline-Depth 0;' > /etc/apt/apt.conf.d/99fixbadproxy && \
echo 'Acquire::http::No-Cache true;' >> /etc/apt/apt.conf.d/99fixbadproxy && \
echo 'Acquire::BrokenProxy true;' >> /etc/apt/apt.conf.d/99fixbadproxy
# Add PostgreSQL repository
RUN apt-get update && apt-get install -y curl ca-certificates gnupg lsb-release
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg
RUN echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Install build dependencies
RUN apt-get update
RUN apt-get install -y --no-install-recommends --no-install-suggests \
bison \
build-essential \
flex \
git \
postgresql-server-dev-15
# Clone and build Apache AGE
RUN git clone https://github.com/apache/age.git /age
WORKDIR /age
RUN git checkout release/PG15/1.5.0
RUN make install
# Final stage - clean image with just the extension files
FROM supabase/postgres:15.8.1.020
# Copy only the compiled extension files
COPY --from=0 /usr/lib/postgresql/15/lib/age.so /usr/lib/postgresql/15/lib/
COPY --from=0 /usr/share/postgresql/15/extension/age* /usr/share/postgresql/15/extension/
我的Docker撰写文件
db:
container_name: supabase-db
image: localhost:5000/supabase-with-age
restart: unless-stopped
volumes:
- ./volumes/db/realtime.sql:/docker-entrypoint-initdb.d/migrations/99-realtime.sql:Z
# Must be superuser to create event trigger
- ./volumes/db/webhooks.sql:/docker-entrypoint-initdb.d/init-scripts/98-webhooks.sql:Z
# Must be superuser to alter reserved role
- ./volumes/db/roles.sql:/docker-entrypoint-initdb.d/init-scripts/99-roles.sql:Z
# Initialize the database settings with JWT_SECRET and JWT_EXP
- ./volumes/db/jwt.sql:/docker-entrypoint-initdb.d/init-scripts/99-jwt.sql:Z
# PGDATA directory is persisted between restarts
- ./volumes/db/data:/var/lib/postgresql/data:Z
# Changes required for internal supabase data such as _analytics
- ./volumes/db/_supabase.sql:/docker-entrypoint-initdb.d/migrations/97-_supabase.sql:Z
# Changes required for Analytics support
- ./volumes/db/logs.sql:/docker-entrypoint-initdb.d/migrations/99-logs.sql:Z
# Changes required for Pooler support
- ./volumes/db/pooler.sql:/docker-entrypoint-initdb.d/migrations/99-pooler.sql:Z
# Use named volume to persist pgsodium decryption key between restarts
- db-config:/etc/postgresql-custom
healthcheck:
test:
[
"CMD",
"pg_isready",
"-U",
"postgres",
"-h",
"localhost"
]
interval: 5s
timeout: 5s
retries: 10
depends_on:
vector:
condition: service_healthy
environment:
POSTGRES_HOST: /var/run/postgresql
PGPORT: ${POSTGRES_PORT}
POSTGRES_PORT: ${POSTGRES_PORT}
PGPASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
PGDATABASE: ${POSTGRES_DB}
POSTGRES_DB: ${POSTGRES_DB}
JWT_SECRET: ${JWT_SECRET}
JWT_EXP: ${JWT_EXPIRY}
command:
[
"postgres",
"-c",
"config_file=/etc/postgresql/postgresql.conf",
"-c",
"log_min_messages=fatal" # prevents Realtime polling queries from appearing in logs
]
dbmate:
image: amacneil/dbmate
command: --wait up # auto apply migrations
restart: on-failure:3 # Limit restart attempts
volumes:
- ./db/migrations:/db/migrations:Z
environment:
DATABASE_URL: "postgres://postgres:postgres@db:5432/postgres?sslmode=disable"
DBMATE_SCHEMA_MIGRATIONS_TABLE: "schema_migrations" # Explicitly name tracking table
DBMATE_NO_DUMP_SCHEMA: "true" # Skip schema dumping for performance
depends_on:
db:
condition: service_healthy # Requires the healthcheck defined above
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
TDLR:使用supabase_admin创建扩展名,并编辑要安装的扩展程序的控制文件,以直接指向您正在安装的.SO文件。
Supabase出于安全原因,已删除了Postgres用户上的Superuser访问 https://github.com/orgs/supabase/discussions/2495因此,安装扩展时必须使用supabase_admin用户 IE在上面的dbMate服务示例中-Database_url:“ Postgresql:// supabase_admin:$ {postgres_pass_password} @db:$ {postgres_port}/postgres?sslmode?
下一期是Postgres无法安装扩展。首先找到PostgreSQL在您的容器中寻找扩展的位置: 在容器中 pg_config -sharedir 返回/root/.nix-profile/share/postgresql I使用以下方式检查了这些目录中的文件结构: LS-LA/Root/.nix -profile/lib/postgresql/
LS-LA/Root/.nix -profile/share/postgresql/extension/
因此,我可以将Dockerfile中的文件链接到正确的位置。 this this帮助,这些文件显示为Postgres中的可用扩展名,但是当我上安装时,我会遇到错误:无法访问文件“ $ libdir/age”:没有这样的文件或目录。
使用pg_config -pkglibdir显示$ libdir指向的位置,但是当我也将文件链接在此处并保存它们的年龄时,它没有效果。可能是因为目录是不变的,但我不确定。对我有用的解决方案正在编辑控制文件,以指向我存储文件的目录ie
# Modify the control file to use the full path to the library
&& sed -i "s|module_pathname = '\\\$libdir/age'|module_pathname = '/usr/local/pgsql/lib/age.so'|" /usr/local/pgsql/share/extension/age.control \