2020-12-08 02:06:39 +00:00
|
|
|
{
|
2022-03-08 01:42:46 +00:00
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: {
|
|
|
|
environment.systemPackages = let
|
2022-06-04 22:42:58 +00:00
|
|
|
# script from:
|
|
|
|
# https://nixos.org/manual/nixos/stable/index.html#module-postgresql
|
|
|
|
# 1) bump toVersion; rebuild
|
|
|
|
# 2) run this script
|
|
|
|
# 3) bump postgres; rebuild
|
|
|
|
# 4) run analyze_new_cluster.sh; delete_old_cluster.sh from the database dir.
|
|
|
|
toVersion = "14"; # Bump this when there is a new version.
|
2022-06-05 07:45:22 +00:00
|
|
|
new_package = "postgresql_${toVersion}";
|
2022-03-08 01:42:46 +00:00
|
|
|
in [
|
|
|
|
(pkgs.writeScriptBin "upgrade-pg-cluster" ''
|
2022-06-04 22:42:58 +00:00
|
|
|
set -eux
|
|
|
|
|
|
|
|
systemctl stop postgresql
|
|
|
|
|
|
|
|
export NEWDATA="/var/lib/postgresql/${toVersion}"
|
|
|
|
|
|
|
|
export NEWBIN="${pkgs.${new_package}}/bin"
|
|
|
|
|
2022-03-08 01:42:46 +00:00
|
|
|
export OLDDATA="${config.services.postgresql.dataDir}"
|
|
|
|
export OLDBIN="${config.services.postgresql.package}/bin"
|
2020-12-08 02:06:39 +00:00
|
|
|
|
2022-03-08 01:42:46 +00:00
|
|
|
install -d -m 0700 -o postgres -g postgres "$NEWDATA"
|
|
|
|
cd "$NEWDATA"
|
|
|
|
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
|
2020-12-08 02:06:39 +00:00
|
|
|
|
2022-03-08 01:42:46 +00:00
|
|
|
sudo -u postgres $NEWBIN/pg_upgrade \
|
|
|
|
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
|
|
|
|
--old-bindir $OLDBIN --new-bindir $NEWBIN \
|
|
|
|
"$@"
|
|
|
|
'')
|
|
|
|
];
|
2020-12-08 02:06:39 +00:00
|
|
|
}
|