From 9392ad597a0ab2885ed926677b4ffcfd82318aa2 Mon Sep 17 00:00:00 2001 From: DerGrumpf Date: Mon, 16 Feb 2026 16:01:14 +0100 Subject: [PATCH] Added: Postgres 15; RPi Optimized --- hosts/cyper-pi-1/configuration.nix | 4 ++ hosts/cyper-pi-1/postgres.nix | 65 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 hosts/cyper-pi-1/postgres.nix diff --git a/hosts/cyper-pi-1/configuration.nix b/hosts/cyper-pi-1/configuration.nix index 366433d..2da3329 100644 --- a/hosts/cyper-pi-1/configuration.nix +++ b/hosts/cyper-pi-1/configuration.nix @@ -4,6 +4,10 @@ }: { + import = [ + ./postgres.nix + ]; + # Any RPi 4 specific customizations go here networking = { hostName = lib.mkForce "cyper-pi-1"; diff --git a/hosts/cyper-pi-1/postgres.nix b/hosts/cyper-pi-1/postgres.nix new file mode 100644 index 0000000..f6f1198 --- /dev/null +++ b/hosts/cyper-pi-1/postgres.nix @@ -0,0 +1,65 @@ +{ + pkgs, + ... +}: + +{ + services.postgresql = { + enable = true; + package = pkgs.postgresql_15; + port = 5432; + + # Initial database setup + initialScript = pkgs.writeText "backend-init-script" '' + CREATE USER postgres WITH SUPERUSER PASSWORD 'postgres'; + ''; + + # Raspberry Pi 4 optimized settings (2GB RAM assumed) + settings = { + # Memory settings (RPi 4 has limited RAM) + shared_buffers = "128MB"; + effective_cache_size = "512MB"; + maintenance_work_mem = "32MB"; + work_mem = "2MB"; + wal_buffers = "4MB"; + + # Connection settings + max_connections = 20; + + # Performance tuning for ARM/RPi + random_page_cost = 2.0; + effective_io_concurrency = 100; + + # WAL settings (conservative for SD card) + wal_level = "replica"; + checkpoint_timeout = "15min"; + checkpoint_completion_target = 0.7; + min_wal_size = "1GB"; + max_wal_size = "4GB"; + + # Query planning + default_statistics_target = 50; + + # Logging + log_min_duration_statement = 1000; + log_duration = false; + + # ARM/RPi specific + cpu_index_tuple_cost = 0.1; + cpu_operator_cost = 0.05; + }; + }; + + # Enable the PostgreSQL service to start on boot + systemd.services.postgresql.wantedBy = [ "multi-user.target" ]; + + # Create mount point for external USB storage (optional, for better performance) + # Uncomment if using the USB 3 storage we configured earlier + # systemd.tmpfiles.rules = [ + # "d /mnt/nix-storage/postgresql 0700 postgres postgres" + # ]; + + # environment.etc."postgresql/postgresql.conf".text = '' + # data_directory = '/mnt/nix-storage/postgresql' + # ''; +}