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>
40 lines
1.1 KiB
Nix
40 lines
1.1 KiB
Nix
{
|
|
pkgs,
|
|
lib,
|
|
config,
|
|
...
|
|
}:
|
|
{
|
|
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" \
|
|
"$@"
|
|
''
|
|
)
|
|
];
|
|
}
|