forked from DGNum/infrastructure
Compare commits
3 commits
ed567cf432
...
0eb813c8bf
Author | SHA1 | Date | |
---|---|---|---|
0eb813c8bf | |||
17a6e085b5 | |||
4e7b3154da |
3 changed files with 59 additions and 21 deletions
|
@ -20,6 +20,7 @@ lib.extra.mkConfig {
|
|||
"nextcloud"
|
||||
"outline"
|
||||
"plausible"
|
||||
"postgresql"
|
||||
"rstudio-server"
|
||||
"satosa"
|
||||
"signald"
|
||||
|
|
34
machines/compute01/postgresql.nix
Normal file
34
machines/compute01/postgresql.nix
Normal 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 ]);
|
||||
};
|
||||
}
|
|
@ -16,6 +16,11 @@ in
|
|||
default = true;
|
||||
};
|
||||
|
||||
pg-upgrade-from = mkOption {
|
||||
type = lib.types.package;
|
||||
default = config.services.postgresql.package;
|
||||
};
|
||||
|
||||
pg-upgrade-to = mkOption {
|
||||
type = lib.types.package;
|
||||
default = pkgs.postgresql_15;
|
||||
|
@ -76,30 +81,28 @@ in
|
|||
mtr
|
||||
tcpdump
|
||||
])
|
||||
++ lib.optional
|
||||
(config.services.postgresql.enable && config.services.postgresql.package != cfg.pg-upgrade-to)
|
||||
(
|
||||
pkgs.writeScriptBin "upgrade-pg-cluster" ''
|
||||
set -eux
|
||||
# XXX it's perhaps advisable to stop all services that depend on postgresql
|
||||
systemctl stop postgresql
|
||||
++ [ config.boot.kernelPackages.perf ]
|
||||
++ lib.optional (config.services.postgresql.enable && cfg.pg-upgrade-from != cfg.pg-upgrade-to) (
|
||||
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/${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}"
|
||||
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"
|
||||
|
||||
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 \
|
||||
"$@"
|
||||
''
|
||||
);
|
||||
sudo -u postgres $NEWBIN/pg_upgrade \
|
||||
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
|
||||
--old-bindir $OLDBIN --new-bindir $NEWBIN \
|
||||
"$@"
|
||||
''
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue