thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

postgresql: from 18 to 19 on alpine linux

• 340 words • 2 min

Human voice: does it even make sense to keep posting here? Everything is Gen AI now. I didn’t have to bother to manually fix this DB upgrade. I just pointed out pi with GPT-6.2 Sol to my beloved Alpine Linux VPS.


Previously.

Problem statement: how do we move Miniflux to PostgreSQL 19 without replacing the running PostgreSQL 18 cluster?

I installed the versioned packages side by side and left 18 as Alpine’s active version. From a root shell:

shell
# apk add postgresql19 postgresql19-contrib
# pg_versions list
19
18

While Miniflux was still running, I initialized the new cluster with the same collation, character type, and checksum setting. I copied the existing authentication rules and carried over the active settings, not the whole 18 postgresql.conf:

sh
old=/var/lib/postgresql/18/data
new=/var/lib/postgresql/19/data
work=/var/lib/postgresql/19/upgrade
oldbin=/usr/libexec/postgresql18
newbin=/usr/libexec/postgresql19

install -d -m 0700 -o postgres -g postgres "$new" "$work"
doas -u postgres "$newbin/initdb" -D "$new" --encoding=UTF8 \
  --locale-provider=libc --locale=C.UTF-8 --lc-collate=C --lc-ctype=C.UTF-8 \
  --data-checksums --auth=trust
doas -u postgres cp "$old/pg_hba.conf" "$old/pg_ident.conf" "$new/"
doas -u postgres psql -XAt -v ON_ERROR_STOP=1 -d postgres <<'SQL' >> "$new/postgresql.conf"
SELECT name || ' = ' || quote_literal(setting)
FROM pg_file_settings WHERE applied ORDER BY seqno;
SQL

I stopped Miniflux before taking the backup. Then I stopped PostgreSQL and ran the compatibility check and migration with the 19 pg_upgrade:

sh
set -eu
set -o pipefail
umask 077
backup=$(mktemp -d /root/knol-postgresql19-migration.XXXXXXXX)
rc-service miniflux stop
doas -u postgres "$newbin/pg_dumpall" | gzip > "$backup/cluster.sql.gz"
gzip -t "$backup/cluster.sql.gz"
rc-service postgresql stop

db_upgrade() {
  doas -u postgres sh -c 'cd "$1"; shift; exec "$@"' sh "$work" "$newbin/pg_upgrade" \
    --old-bindir="$oldbin" --new-bindir="$newbin" \
    --old-datadir="$old" --new-datadir="$new" --socketdir="$work" --copy "$@"
}
db_upgrade --check
db_upgrade

--check printed *Clusters are compatible*. Copy mode left the old cluster in place. Only after Upgrade Complete did I switch the default:

shell
# pg_versions set-default 19
# rc-service postgresql start
 * Starting PostgreSQL 19 ... [ ok ]

Before restarting Miniflux, I compared row counts and ID ranges: 563 feeds and 3,324 entries matched. to_tsvector('english', 'running') returned 'run':1. After restart, feed #133 refreshed with zero errors and no new entries. ∎

🤖 This post was drafted with an AI agent through /bloggify, then reviewed and edited by me. More agent-assisted posts.

ESC