feat: upgrade postgres & add update script
This commit is contained in:
parent
f5efff8653
commit
4858f01e31
|
@ -25,6 +25,7 @@ in
|
||||||
../virtualisation/podman.nix
|
../virtualisation/podman.nix
|
||||||
../modules/inadyn.nix
|
../modules/inadyn.nix
|
||||||
../modules/systemdNotify.nix
|
../modules/systemdNotify.nix
|
||||||
|
../services/postgres
|
||||||
../services/mail.nix
|
../services/mail.nix
|
||||||
../services/lldap.nix
|
../services/lldap.nix
|
||||||
../services/authelia.nix
|
../services/authelia.nix
|
||||||
|
|
9
services/postgres/default.nix
Normal file
9
services/postgres/default.nix
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
# Update `newPostgres` version, uncomment & run `upgrade-pg-cluster`. For details,
|
||||||
|
# see https://nixos.org/manual/nixos/stable/#module-services-postgres-upgrading
|
||||||
|
# imports = [ ./upgrade-pg-cluster.nix ];
|
||||||
|
|
||||||
|
services.postgresql.package = pkgs.postgresql_16;
|
||||||
|
}
|
41
services/postgres/upgrade-pg-cluster.nix
Normal file
41
services/postgres/upgrade-pg-cluster.nix
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
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 \
|
||||||
|
"$@"
|
||||||
|
''
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
Loading…
Reference in a new issue