feat(compute01): Upgrade postgres to 16.2

This commit is contained in:
Tom Hubrecht 2024-05-01 16:01:44 +02:00
parent 17a6e085b5
commit 0eb813c8bf
2 changed files with 30 additions and 23 deletions

View file

@ -4,7 +4,7 @@
services.postgresql = { services.postgresql = {
enable = true; enable = true;
package = pkgs.postgresql_14; package = pkgs.postgresql_16;
settings = { settings = {
checkpoint_completion_target = 0.90625; checkpoint_completion_target = 0.90625;
@ -25,4 +25,10 @@
work_mem = "83886kB"; 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 ]);
};
} }

View file

@ -16,6 +16,11 @@ in
default = true; default = true;
}; };
pg-upgrade-from = mkOption {
type = lib.types.package;
default = config.services.postgresql.package;
};
pg-upgrade-to = mkOption { pg-upgrade-to = mkOption {
type = lib.types.package; type = lib.types.package;
default = pkgs.postgresql_15; default = pkgs.postgresql_15;
@ -77,31 +82,27 @@ in
tcpdump tcpdump
]) ])
++ [ config.boot.kernelPackages.perf ] ++ [ config.boot.kernelPackages.perf ]
++ ++ lib.optional (config.services.postgresql.enable && cfg.pg-upgrade-from != cfg.pg-upgrade-to) (
lib.optional pkgs.writeScriptBin "upgrade-pg-cluster" ''
(config.services.postgresql.enable && config.services.postgresql.package != cfg.pg-upgrade-to) set -eux
( # XXX it's perhaps advisable to stop all services that depend on postgresql
pkgs.writeScriptBin "upgrade-pg-cluster" '' systemctl stop postgresql
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}" install -d -m 0700 -o postgres -g postgres "$NEWDATA"
export OLDBIN="${config.services.postgresql.package}/bin" cd "$NEWDATA"
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
install -d -m 0700 -o postgres -g postgres "$NEWDATA" sudo -u postgres $NEWBIN/pg_upgrade \
cd "$NEWDATA" --old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
sudo -u postgres $NEWBIN/initdb -D "$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 \
"$@"
''
);
}; };
} }