1
0
Fork 0

postgres: upgrade

This commit is contained in:
Daniel Kempkens 2023-12-15 20:42:43 +01:00
parent b95414f56a
commit 22601f3f6d
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM

View file

@ -1,9 +1,9 @@
{ pkgs, ... }:
{ pkgs, config, ... }:
{
services.postgresql = {
enable = true;
package = pkgs.postgresql_15_jit;
package = pkgs.postgresql_16_jit;
enableJIT = true;
enableTCPIP = true;
@ -25,4 +25,34 @@
};
networking.firewall.interfaces."tailscale0".allowedTCPPorts = [ 5432 ];
# See: https://nixos.org/manual/nixos/unstable/#module-services-postgres-upgrading
environment.systemPackages = [
(
let
newPostgres = pkgs.postgresql_16_jit;
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="${config.services.postgresql.dataDir}"
export OLDBIN="${config.services.postgresql.package}/bin"
install -d -m 0700 -o postgres -g postgres "$NEWDATA"
cd "$NEWDATA"
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
sudo -u postgres $NEWBIN/pg_upgrade \
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
--old-bindir $OLDBIN --new-bindir $NEWBIN \
"$@"
''
)
];
}