2023-10-06 18:05:38 +02:00
|
|
|
{ config, pkgs, lib, ... }: let
|
2023-07-12 01:58:28 +02:00
|
|
|
cfg = config.services.postgresql;
|
|
|
|
in {
|
2022-06-21 01:47:36 +02:00
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2022-06-22 20:16:57 +02:00
|
|
|
enableTCPIP = true;
|
|
|
|
authentication = pkgs.lib.mkOverride 10 ''
|
|
|
|
local all all trust
|
|
|
|
host all all 127.0.0.1/32 trust
|
|
|
|
host all all ::1/128 trust
|
|
|
|
'';
|
2023-07-12 01:58:28 +02:00
|
|
|
settings = {
|
2024-01-23 05:31:06 +01:00
|
|
|
# Source: https://pgtune.leopard.in.ua/
|
|
|
|
# DB Version: 15
|
|
|
|
# OS Type: linux
|
|
|
|
# DB Type: mixed
|
|
|
|
# Total Memory (RAM): 12 GB
|
|
|
|
# CPUs num: 12
|
|
|
|
# Connections num: 150
|
|
|
|
# Data Storage: hdd
|
|
|
|
|
2023-07-12 01:58:28 +02:00
|
|
|
max_connections = 150;
|
2024-01-23 05:31:06 +01:00
|
|
|
shared_buffers = "3GB";
|
|
|
|
effective_cache_size = "9GB";
|
|
|
|
maintenance_work_mem = "768MB";
|
|
|
|
checkpoint_completion_target = 0.9;
|
|
|
|
wal_buffers = "16MB";
|
|
|
|
default_statistics_target = 100;
|
|
|
|
random_page_cost = 4;
|
|
|
|
effective_io_concurrency = 2;
|
|
|
|
work_mem = "2621kB";
|
|
|
|
min_wal_size = "1GB";
|
|
|
|
max_wal_size = "4GB";
|
|
|
|
max_worker_processes = 12;
|
|
|
|
max_parallel_workers_per_gather = 4;
|
|
|
|
max_parallel_workers = 12;
|
|
|
|
max_parallel_maintenance_workers = 4;
|
2023-07-12 01:58:28 +02:00
|
|
|
};
|
2022-06-21 01:47:36 +02:00
|
|
|
};
|
|
|
|
|
2022-11-08 14:20:33 +01:00
|
|
|
services.postgresqlBackup = {
|
|
|
|
enable = true;
|
2024-01-23 05:24:47 +01:00
|
|
|
location = "/data/backup/postgres";
|
2022-11-08 14:20:33 +01:00
|
|
|
backupAll = true;
|
|
|
|
};
|
2023-02-25 19:06:06 +01:00
|
|
|
|
2023-07-12 01:58:28 +02:00
|
|
|
systemd.services.postgresqlBackup = {
|
2024-01-23 05:24:47 +01:00
|
|
|
requires = [ "postgresql.service" ];
|
2023-07-12 01:58:28 +02:00
|
|
|
};
|
|
|
|
|
2024-11-18 15:18:52 +01:00
|
|
|
systemd.services.postgresql.serviceConfig.ReadWritePaths = [ cfg.dataDir ];
|
2023-07-12 01:58:28 +02:00
|
|
|
|
2023-02-25 19:06:06 +01:00
|
|
|
environment.systemPackages = [ config.services.postgresql.package ];
|
2022-06-21 01:47:36 +02:00
|
|
|
}
|