2022-06-04 12:53:24 -04:00
|
|
|
{ pkgs, config, ... }: {
|
|
|
|
services = {
|
|
|
|
postgresql = {
|
|
|
|
enable = true;
|
2023-02-20 20:01:39 -05:00
|
|
|
package = pkgs.postgresql_14;
|
2022-06-04 12:53:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
postgresqlBackup = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# Postgres upgrades: https://nixos.org/manual/nixos/stable/index.html#module-services-postgres-upgrading
|
|
|
|
environment.systemPackages = [
|
2023-12-11 16:59:00 -05:00
|
|
|
(
|
|
|
|
let
|
|
|
|
# XXX specify the postgresql package you'd like to upgrade to.
|
|
|
|
# Do not forget to list the extensions you need.
|
|
|
|
newPostgres = pkgs.postgresql_15;
|
|
|
|
in
|
|
|
|
pkgs.writeScriptBin "upgrade-pg-cluster" ''
|
|
|
|
set -eux
|
|
|
|
# XXX it's perhaps advisable to stop all services that depend on postgresql
|
|
|
|
systemctl stop postgresql
|
2022-06-04 12:53:24 -04:00
|
|
|
|
2023-12-11 16:59:00 -05:00
|
|
|
export NEWDATA="/var/lib/postgresql/${newPostgres.psqlSchema}"
|
2022-06-04 12:53:24 -04:00
|
|
|
|
2023-12-11 16:59:00 -05:00
|
|
|
export NEWBIN="${newPostgres}/bin"
|
2022-06-04 12:53:24 -04:00
|
|
|
|
2023-12-11 16:59:00 -05:00
|
|
|
export OLDDATA="${config.services.postgresql.dataDir}"
|
|
|
|
export OLDBIN="${config.services.postgresql.package}/bin"
|
2022-06-04 12:53:24 -04:00
|
|
|
|
2023-12-11 16:59:00 -05:00
|
|
|
install -d -m 0700 -o postgres -g postgres "$NEWDATA"
|
|
|
|
cd "$NEWDATA"
|
|
|
|
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
|
2022-06-04 12:53:24 -04:00
|
|
|
|
2023-12-11 16:59:00 -05:00
|
|
|
sudo -u postgres $NEWBIN/pg_upgrade \
|
|
|
|
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
|
|
|
|
--old-bindir $OLDBIN --new-bindir $NEWBIN \
|
|
|
|
"$@"
|
|
|
|
''
|
|
|
|
)
|
2022-06-04 12:53:24 -04:00
|
|
|
];
|
|
|
|
}
|