Compare commits

...

3 commits

3 changed files with 59 additions and 21 deletions

View file

@ -20,6 +20,7 @@ lib.extra.mkConfig {
"nextcloud" "nextcloud"
"outline" "outline"
"plausible" "plausible"
"postgresql"
"rstudio-server" "rstudio-server"
"satosa" "satosa"
"signald" "signald"

View file

@ -0,0 +1,34 @@
{ pkgs, ... }:
{
services.postgresql = {
enable = true;
package = pkgs.postgresql_16;
settings = {
checkpoint_completion_target = 0.90625;
default_statistics_target = 100;
effective_cache_size = "32GB";
effective_io_concurrency = 200;
maintenance_work_mem = "2GB";
max_connections = 500;
max_parallel_maintenance_workers = 4;
max_parallel_workers = 12;
max_parallel_workers_per_gather = 4;
max_wal_size = "4GB";
max_worker_processes = 12;
min_wal_size = "1GB";
random_page_cost = 1.125;
shared_buffers = "16GB";
wal_buffers = "16MB";
work_mem = "83886kB";
};
};
dgn-console = {
# Update the versions below for upgrading
pg-upgrade-to = pkgs.postgresql_16.withPackages (ps: [ ps.postgis ]);
pg-upgrade-from = pkgs.postgresql_16.withPackages (ps: [ ps.postgis ]);
};
}

View file

@ -16,6 +16,11 @@ in
default = true; default = true;
}; };
pg-upgrade-from = mkOption {
type = lib.types.package;
default = config.services.postgresql.package;
};
pg-upgrade-to = mkOption { pg-upgrade-to = mkOption {
type = lib.types.package; type = lib.types.package;
default = pkgs.postgresql_15; default = pkgs.postgresql_15;
@ -76,30 +81,28 @@ in
mtr mtr
tcpdump tcpdump
]) ])
++ lib.optional ++ [ config.boot.kernelPackages.perf ]
(config.services.postgresql.enable && config.services.postgresql.package != cfg.pg-upgrade-to) ++ lib.optional (config.services.postgresql.enable && cfg.pg-upgrade-from != cfg.pg-upgrade-to) (
( pkgs.writeScriptBin "upgrade-pg-cluster" ''
pkgs.writeScriptBin "upgrade-pg-cluster" '' set -eux
set -eux # XXX it's perhaps advisable to stop all services that depend on postgresql
# XXX it's perhaps advisable to stop all services that depend on postgresql systemctl stop postgresql
systemctl stop postgresql
export NEWDATA="/var/lib/postgresql/${cfg.pg-upgrade-to.psqlSchema}" export NEWDATA="/var/lib/postgresql/${cfg.pg-upgrade-to.psqlSchema}"
export NEWBIN="${cfg.pg-upgrade-to}/bin"
export NEWBIN="${cfg.pg-upgrade-to}/bin" export OLDDATA="${config.services.postgresql.dataDir}"
export OLDBIN="${cfg.pg-upgrade-from}/bin"
export OLDDATA="${config.services.postgresql.dataDir}" install -d -m 0700 -o postgres -g postgres "$NEWDATA"
export OLDBIN="${config.services.postgresql.package}/bin" cd "$NEWDATA"
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
install -d -m 0700 -o postgres -g postgres "$NEWDATA" sudo -u postgres $NEWBIN/pg_upgrade \
cd "$NEWDATA" --old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA" --old-bindir $OLDBIN --new-bindir $NEWBIN \
"$@"
sudo -u postgres $NEWBIN/pg_upgrade \ ''
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \ );
--old-bindir $OLDBIN --new-bindir $NEWBIN \
"$@"
''
);
}; };
} }