feat(mx): add pg_upgrade script for PostgreSQL 14 → 16 migration
Temporary upgrade script following the official NixOS procedure. Run `upgrade-pg-cluster --jobs 4 --link` on the server, then switch the package to postgresql_16 and remove the script. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
dc4594333f
commit
a854caaf19
1 changed files with 29 additions and 0 deletions
|
|
@ -8,4 +8,33 @@
|
|||
services.postgresql = {
|
||||
package = pkgs.postgresql_14;
|
||||
};
|
||||
|
||||
# Temporary: upgrade script for PostgreSQL 14 → 16 migration.
|
||||
# After upgrading, change package above to postgresql_16 and remove this block.
|
||||
environment.systemPackages = [
|
||||
(
|
||||
let
|
||||
newPostgres = pkgs.postgresql_16;
|
||||
cfg = config.services.postgresql;
|
||||
in
|
||||
pkgs.writeScriptBin "upgrade-pg-cluster" ''
|
||||
set -eux
|
||||
systemctl stop postgresql
|
||||
|
||||
export NEWDATA="/var/lib/postgresql/${newPostgres.psqlSchema}"
|
||||
export NEWBIN="${newPostgres}/bin"
|
||||
export OLDDATA="${cfg.dataDir}"
|
||||
export OLDBIN="${cfg.finalPackage}/bin"
|
||||
|
||||
install -d -m 0700 -o postgres -g postgres "$NEWDATA"
|
||||
cd "$NEWDATA"
|
||||
sudo -u postgres "$NEWBIN/initdb" -D "$NEWDATA" ${lib.escapeShellArgs cfg.initdbArgs}
|
||||
|
||||
sudo -u postgres "$NEWBIN/pg_upgrade" \
|
||||
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
|
||||
--old-bindir "$OLDBIN" --new-bindir "$NEWBIN" \
|
||||
"$@"
|
||||
''
|
||||
)
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue