Skip to content

Commit

Permalink
change postgres default datadir to var/lib/postgresql/data/tensorchord
Browse files Browse the repository at this point in the history
Signed-off-by: xieydd <xieydd@gmail.com>
  • Loading branch information
xieydd committed Nov 13, 2024
1 parent 09bd1e7 commit a6da1db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
22 changes: 14 additions & 8 deletions docker/pg-cnpg/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ ARG PG_MAJOR
ARG FROM_TAG
ARG SCHEMA
ARG TARGETARCH
ARG LIB_DIR

FROM modelzai/pgvecto-rs-binary:${FROM_TAG}-${TARGETARCH}-${SCHEMA} as binary

Expand All @@ -14,6 +13,7 @@ RUN cargo install --version $TRUNK_VER pg-trunk
FROM modelzai/pg-slim:${PG_MAJOR}-${TARGETARCH}
ARG PG_MAJOR
ARG LIB_DIR
ARG ALTDIR=/var/lib/postgresql/data/tensorchord

USER root

Expand Down Expand Up @@ -42,8 +42,8 @@ RUN set -xe; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*;

RUN chown -R postgres:postgres /usr/lib/postgresql/${PG_MAJOR} && \
chmod -R 0700 /usr/lib/postgresql/${PG_MAJOR}
RUN chown -R postgres:postgres ${ALTDIR}/${PG_MAJOR} && \
chmod -R 0700 ${ALTDIR}/${PG_MAJOR}
RUN chown postgres /usr/share/postgresql/${PG_MAJOR}/extension

RUN apt-get update && apt-get install -y \
Expand Down Expand Up @@ -160,13 +160,13 @@ RUN git clone https://github.com/apache/arrow.git && \
RUN git clone https://github.com/pgaudit/pgaudit.git && \
cd pgaudit && \
git checkout REL_${PG_MAJOR}_STABLE && \
make install USE_PGXS=1 PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR}/bin/pg_config && \
make install USE_PGXS=1 PG_CONFIG=${ALTDIR}/${PG_MAJOR}/bin/pg_config && \
cd ../ && rm -rf pgaudit

# Clone and build pg_failover_slots
RUN git clone https://github.com/EnterpriseDB/pg_failover_slots.git && \
cd pg_failover_slots && \
make install PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR}/bin/pg_config && \
make install PG_CONFIG=${ALTDIR}/${PG_MAJOR}/bin/pg_config && \
cd ../ && rm -rf pg_failover_slots

# cache all extensions
Expand All @@ -175,9 +175,15 @@ ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
# Test trunk
COPY trunk-install.sh /usr/local/bin/

RUN set -eux; \
mkdir /tmp/pg_pkglibdir; \
mkdir /tmp/pg_sharedir; \
cp -r $(pg_config --pkglibdir)/* /tmp/pg_pkglibdir; \
cp -r $(pg_config --sharedir)/* /tmp/pg_sharedir

# Change the uid of postgres to 26
RUN usermod -u 26 postgres
RUN chown -R postgres:postgres /usr/lib/postgresql/${PG_MAJOR}
RUN cp /usr/share/postgresql/${PG_MAJOR}/extension/* /usr/lib/postgresql/${PG_MAJOR}/share/extension/
RUN chown -R postgres:postgres ${ALTDIR}/${PG_MAJOR}
RUN cp /usr/share/postgresql/${PG_MAJOR}/extension/* ${ALTDIR}/${PG_MAJOR}/share/extension/
USER 26
ENV PATH $PATH:/usr/lib/postgresql/${PG_MAJOR}/bin
ENV PATH $PATH:${ALTDIR}/${PG_MAJOR}/bin
12 changes: 7 additions & 5 deletions docker/pg-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ARG PG_MAJOR
# 15.8-1.pgdg120+1 16.4-1.pgdg120+2 17.0-1.pgdg120+1
# ARG PG_VERSION
ARG DEBIAN_FRONTEND=noninteractive
ARG ALTDIR=/var/lib/postgresql/data/tensorchord
ENV TZ=Etc/UTC
ENV PGDATA /var/lib/postgresql/data
ENV PATH $PATH:/usr/lib/postgresql/$PG_MAJOR/bin
Expand Down Expand Up @@ -79,7 +80,8 @@ WORKDIR postgres
ENV CFLAGS "-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer"
ENV LDFLAGS "-Wl,-z,relro -Wl,-z,now"
RUN ./configure --prefix=/usr/lib/postgresql/${PG_MAJOR} \
--libdir=/usr/lib/postgresql/$PG_MAJOR/lib \
--datarootdir=${ALTDIR} \
--libdir=${ALTDIR}/${PG_VERSION}/lib \
--with-perl \
--with-python \
--with-tcl \
Expand Down Expand Up @@ -116,16 +118,16 @@ COPY --from=tianon/gosu /gosu /usr/local/bin/

# make the sample config easier to munge (and "correct by default")
RUN set -eux; \
echo "unix_socket_directories = '/var/run/postgresql'" >> /usr/lib/postgresql/${PG_MAJOR}/share/postgresql.conf.sample; \
sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/lib/postgresql/${PG_MAJOR}/share/postgresql.conf.sample; \
grep -F "listen_addresses = '*'" /usr/lib/postgresql/${PG_MAJOR}/share/postgresql.conf.sample
echo "unix_socket_directories = '/var/run/postgresql'" >> ${ALTDIR}/${PG_MAJOR}/share/postgresql.conf.sample; \
sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" ${ALTDIR}/${PG_MAJOR}/share/postgresql.conf.sample; \
grep -F "listen_addresses = '*'" ${ALTDIR}/${PG_MAJOR}/share/postgresql.conf.sample

RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql

# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 ${PGDATA}

ENV PATH $PATH:/usr/lib/postgresql/$PG_MAJOR/bin:/usr/local/bin
ENV PATH $PATH:${ALTDIR}/$PG_MAJOR/bin:/usr/local/bin
COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/
RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh
ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down

0 comments on commit a6da1db

Please sign in to comment.