2021-03-23 22:36:50 +01:00
|
|
|
{
|
2022-04-10 11:54:58 +02:00
|
|
|
config,
|
|
|
|
pkgs,
|
2024-12-02 12:04:07 +01:00
|
|
|
lib,
|
2022-04-10 11:54:58 +02:00
|
|
|
...
|
|
|
|
}: {
|
2021-03-23 22:36:50 +01:00
|
|
|
# set postgresql version so we don't get any bad surprise
|
|
|
|
config.services.postgresql = {
|
2023-12-05 16:51:55 +01:00
|
|
|
package = pkgs.postgresql_15;
|
2021-03-23 22:36:50 +01:00
|
|
|
};
|
2024-12-02 12:04:07 +01:00
|
|
|
|
|
|
|
config.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;
|
|
|
|
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 \
|
|
|
|
"$@"
|
|
|
|
'')
|
|
|
|
];
|
2021-03-23 22:36:50 +01:00
|
|
|
}
|