postgres: upgrade
This commit is contained in:
parent
b95414f56a
commit
22601f3f6d
1 changed files with 32 additions and 2 deletions
|
@ -1,9 +1,9 @@
|
||||||
{ pkgs, ... }:
|
{ pkgs, config, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.postgresql_15_jit;
|
package = pkgs.postgresql_16_jit;
|
||||||
enableJIT = true;
|
enableJIT = true;
|
||||||
|
|
||||||
enableTCPIP = true;
|
enableTCPIP = true;
|
||||||
|
@ -25,4 +25,34 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall.interfaces."tailscale0".allowedTCPPorts = [ 5432 ];
|
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 \
|
||||||
|
"$@"
|
||||||
|
''
|
||||||
|
)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue