79 lines
2.5 KiB
Nix
79 lines
2.5 KiB
Nix
# AZ-PLT-1 pgbouncer (AZ-NIX-aso), Muster wie AZ-CLD-1/services/pgbouncer.nix —
|
|
# bewusst schlank: nur der TX-Pool fuer die zwei PLT-1-DBs (Session-Pool-DBs
|
|
# wie outline/zammad bleiben bis AZ-NIX-42r auf CLD-1). Listen nur auf
|
|
# Loopback, da PLT-1 (noch) keine Podman-Bridge hat — hostBridgeIP nachziehen,
|
|
# sobald Container (ES 8, ERPNext) kommen.
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}: let
|
|
txPort = config.m3ta.ports.get "pgbouncer-tx";
|
|
pgPort = config.m3ta.ports.get "postgres";
|
|
|
|
# pgbouncer (1.24+ als auch 1.25.2) laedt bei JEDEM TLS-Setup eine CA — auch
|
|
# bei sslmode=prefer/require ohne Verifikation. Ohne explizite Datei faellt
|
|
# es auf die OpenSSL-Default-Verify-Paths zurueck, die hier fehlschlagen:
|
|
# "TLS setup failed: failed to load CA: (null)" -> Startabbruch.
|
|
# (Erkenntnis aus AZ-CLD-1, verifiziert 2026-08-20 gegen 1.24.1 + 1.25.2.)
|
|
caBundle = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
|
|
|
|
mkDatabases = dbs:
|
|
lib.listToAttrs (map (db:
|
|
lib.nameValuePair db "host=127.0.0.1 port=${toString pgPort} dbname=${db}")
|
|
dbs);
|
|
in {
|
|
services.pgbouncer = {
|
|
enable = true;
|
|
settings = {
|
|
pgbouncer = {
|
|
listen_addr = "127.0.0.1";
|
|
listen_port = txPort;
|
|
pool_mode = "transaction";
|
|
|
|
auth_type = "scram-sha-256";
|
|
auth_file = config.age.secrets.pgbouncer-userlist.path;
|
|
|
|
admin_users = "sascha_koenig";
|
|
stats_users = "sascha_koenig";
|
|
|
|
max_client_conn = 300;
|
|
default_pool_size = 10;
|
|
min_pool_size = 2;
|
|
reserve_pool_size = 3;
|
|
reserve_pool_timeout = 3;
|
|
max_prepared_statements = 200;
|
|
|
|
client_tls_sslmode = "prefer";
|
|
client_tls_cert_file = config.age.secrets.pgbouncer-tls-cert.path;
|
|
client_tls_key_file = config.age.secrets.pgbouncer-tls-key.path;
|
|
client_tls_protocols = "secure";
|
|
client_tls_ca_file = caBundle;
|
|
|
|
log_connections = 1;
|
|
log_disconnections = 1;
|
|
server_reset_query = "DISCARD ALL";
|
|
server_check_query = "SELECT 1";
|
|
server_check_delay = 30;
|
|
|
|
server_tls_sslmode = "prefer";
|
|
server_tls_protocols = "secure";
|
|
server_tls_ca_file = caBundle;
|
|
};
|
|
databases = mkDatabases [
|
|
"metabase"
|
|
"az_kpi_raw"
|
|
];
|
|
};
|
|
};
|
|
|
|
systemd.services.pgbouncer = {
|
|
after = ["postgresql.service"];
|
|
requires = ["postgresql.service"];
|
|
};
|
|
|
|
# Kein Firewall-Eintrag noetig: pgbouncer lauscht nur auf 127.0.0.1.
|
|
# Kestra (PRM-1) verbindet direkt auf 5432, siehe ./postgres.nix.
|
|
}
|