Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Postgres Major Version #76

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion netdisco-postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# vim: ft=Dockerfile
FROM docker.io/postgres:13.4-alpine
FROM docker.io/postgres:17.2-alpine

ARG BUILD_DATE
ARG COMMITTISH=HEAD
Expand All @@ -18,12 +18,14 @@ LABEL org.label-schema.docker.schema-version="1.0" \
org.netdisco.version=${COMMITTISH}

RUN apk add --no-cache \
su-exec \
curl \
tzdata \
tar

COPY netdisco-initdb.sh /docker-entrypoint-initdb.d/
COPY netdisco-db-entrypoint.sh netdisco-updatedb.sh /usr/local/bin/
COPY README_UPGRADE.md /
RUN chmod +x /usr/local/bin/netdisco-*

WORKDIR /var/lib/postgresql/netdisco-sql
Expand Down
47 changes: 47 additions & 0 deletions netdisco-postgresql/README_UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

Beginning from version 2.09000 netdisco-docker includes Postgres 17,
while the existing database is an older major version.

It's possible to upgrade the old database in-place using pgautoupgrade,
executed in the directory where docker-compose.yml is located. Make
sure all other netdisco containers are stopped.

```
docker run --rm -it \
--mount type=bind,source=$PWD/netdisco/pgdata,target=/var/lib/postgresql/data \
-e PGAUTO_ONESHOT=yes \
pgautoupgrade/pgautoupgrade:17-alpine
```

Before doing so, please make sure to have a working backup. If you don't
have one already, a simple way to create one is:

```
docker-compose exec -u postgres netdisco-postgresql \
pg_dump -c -d netdisco -C --format=p > $HOME/netdisco-backup.sql

```

For the above command to work, or to avoid upgrading right now, edit
docker-compose.yml to use the last version of the images that used
Postgres 13:

```
image: netdisco/netdisco:2.080003-postgresql
image: netdisco/netdisco:2.080003-backend
image: netdisco/netdisco:2.080003-web
image: netdisco/netdisco:2.080003-do
```

When you are ready to use Postgres 17, set the version numbers in image:
to `latest` again.

```
image: netdisco/netdisco:latest-postgresql
etc...
```

We apologize for the inconvenience. While we can not offer full
Postgres DBA support or any responsibility for data loss, we try to
help with reported issues on github or the IRC channel.

5 changes: 5 additions & 0 deletions netdisco-postgresql/netdisco-db-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ if [ ! -s "${PGDATA}/PG_VERSION" ]; then
/usr/local/bin/docker-entrypoint.sh "$@"
fi

if ! grep -q "17" "${PGDATA}/PG_VERSION" ; then
cat /README_UPGRADE.md
exit 1
fi

if [ "$1" = 'postgres' ]; then
echo >&2 -e "${COL}netdisco-db-entrypoint: starting pg privately to container${NC}"
"${su[@]}" pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost' -c log_min_error_statement=LOG -c log_min_messages=LOG" -w start
Expand Down