From 9d03e1167f674ea4d679b860e4e9a397046491e2 Mon Sep 17 00:00:00 2001 From: Kabbone Date: Mon, 30 Dec 2024 10:27:01 +0100 Subject: [PATCH] server: postgresql: update to 16 --- modules/services/server/postgresql.nix | 3 +- .../services/server/postgresql_upgrade.nix | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 modules/services/server/postgresql_upgrade.nix diff --git a/modules/services/server/postgresql.nix b/modules/services/server/postgresql.nix index 803f300..9137622 100644 --- a/modules/services/server/postgresql.nix +++ b/modules/services/server/postgresql.nix @@ -5,9 +5,10 @@ { config, lib, pkgs, ... }: { + imports = [ ./postgresql_upgrade.nix ]; services.postgresql = { enable = true; - package = pkgs.postgresql_15; + package = pkgs.postgresql_16; settings = { max_connections = 200; listen_addresses = "localhost"; diff --git a/modules/services/server/postgresql_upgrade.nix b/modules/services/server/postgresql_upgrade.nix new file mode 100644 index 0000000..e77f6c3 --- /dev/null +++ b/modules/services/server/postgresql_upgrade.nix @@ -0,0 +1,33 @@ +{ config, lib, pkgs, ... }: +{ + environment.systemPackages = [ + (let + # XXX specify the postgresql package you'd like to upgrade to. + # Do not forget to list the extensions you need. + newPostgres = pkgs.postgresql_16.withPackages (pp: [ + # pp.plv8 + ]); + cfg = config.services.postgresql; + in pkgs.writeScriptBin "upgrade-pg-cluster" '' + set -eux + # XXX it's perhaps advisable to stop all services that depend on postgresql + systemctl stop postgresql + + export NEWDATA="/var/lib/postgresql/${newPostgres.psqlSchema}" + + export NEWBIN="${newPostgres}/bin" + + export OLDDATA="${cfg.dataDir}" + export OLDBIN="${cfg.package}/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 \ + "$@" + '') + ]; +}