add upgrade-pg-cluster
This commit is contained in:
parent
e1a78e7508
commit
2da556f18c
2 changed files with 36 additions and 0 deletions
|
@ -4,6 +4,10 @@ let
|
|||
inputs = config.dadada.inputs;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./upgrade-pg-cluster.nix
|
||||
];
|
||||
|
||||
i18n.defaultLocale = mkDefault "en_US.UTF-8";
|
||||
console = mkDefault {
|
||||
font = "Lat2-Terminus16";
|
||||
|
|
32
nixos/modules/profiles/upgrade-pg-cluster.nix
Normal file
32
nixos/modules/profiles/upgrade-pg-cluster.nix
Normal file
|
@ -0,0 +1,32 @@
|
|||
{ config, pkgs, lib, ... }:
|
||||
{
|
||||
environment.systemPackages = lib.mkIf config.services.postgresql.enable [
|
||||
(
|
||||
let
|
||||
# Do not forget to list the extensions you need.
|
||||
newPostgres = pkgs.postgresql_15.withPackages (pp: [ ]);
|
||||
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…
Add table
Add a link
Reference in a new issue