From 0eb813c8bf06b0cf5a55a98d3d7108a9ab473885 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Wed, 1 May 2024 16:01:44 +0200 Subject: [PATCH] feat(compute01): Upgrade postgres to 16.2 --- machines/compute01/postgresql.nix | 8 +++++- modules/dgn-console.nix | 45 ++++++++++++++++--------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/machines/compute01/postgresql.nix b/machines/compute01/postgresql.nix index 3b15dc3..3feede6 100644 --- a/machines/compute01/postgresql.nix +++ b/machines/compute01/postgresql.nix @@ -4,7 +4,7 @@ services.postgresql = { enable = true; - package = pkgs.postgresql_14; + package = pkgs.postgresql_16; settings = { checkpoint_completion_target = 0.90625; @@ -25,4 +25,10 @@ work_mem = "83886kB"; }; }; + + dgn-console = { + # Update the versions below for upgrading + pg-upgrade-to = pkgs.postgresql_16.withPackages (ps: [ ps.postgis ]); + pg-upgrade-from = pkgs.postgresql_16.withPackages (ps: [ ps.postgis ]); + }; } diff --git a/modules/dgn-console.nix b/modules/dgn-console.nix index f3c8fea..0a852e9 100644 --- a/modules/dgn-console.nix +++ b/modules/dgn-console.nix @@ -16,6 +16,11 @@ in default = true; }; + pg-upgrade-from = mkOption { + type = lib.types.package; + default = config.services.postgresql.package; + }; + pg-upgrade-to = mkOption { type = lib.types.package; default = pkgs.postgresql_15; @@ -77,31 +82,27 @@ in tcpdump ]) ++ [ config.boot.kernelPackages.perf ] - ++ - lib.optional - (config.services.postgresql.enable && config.services.postgresql.package != cfg.pg-upgrade-to) - ( - pkgs.writeScriptBin "upgrade-pg-cluster" '' - set -eux - # XXX it's perhaps advisable to stop all services that depend on postgresql - systemctl stop postgresql + ++ lib.optional (config.services.postgresql.enable && cfg.pg-upgrade-from != cfg.pg-upgrade-to) ( + 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/${cfg.pg-upgrade-to.psqlSchema}" + export NEWDATA="/var/lib/postgresql/${cfg.pg-upgrade-to.psqlSchema}" + export NEWBIN="${cfg.pg-upgrade-to}/bin" - export NEWBIN="${cfg.pg-upgrade-to}/bin" + export OLDDATA="${config.services.postgresql.dataDir}" + export OLDBIN="${cfg.pg-upgrade-from}/bin" - export OLDDATA="${config.services.postgresql.dataDir}" - export OLDBIN="${config.services.postgresql.package}/bin" + install -d -m 0700 -o postgres -g postgres "$NEWDATA" + cd "$NEWDATA" + sudo -u postgres $NEWBIN/initdb -D "$NEWDATA" - install -d -m 0700 -o postgres -g postgres "$NEWDATA" - cd "$NEWDATA" - sudo -u postgres $NEWBIN/initdb -D "$NEWDATA" - - sudo -u postgres $NEWBIN/pg_upgrade \ - --old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \ - --old-bindir $OLDBIN --new-bindir $NEWBIN \ - "$@" - '' - ); + sudo -u postgres $NEWBIN/pg_upgrade \ + --old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \ + --old-bindir $OLDBIN --new-bindir $NEWBIN \ + "$@" + '' + ); }; }