Last active
January 4, 2022 14:08
-
-
Save ivan/bebb99c038ec05a2025497adc95092b5 to your computer and use it in GitHub Desktop.
NixOS configuration for deploying pg_prefaulter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { pkgs, config, ... }: | |
| let | |
| pg_prefaulter_config = pkgs.writeTextFile { | |
| name = "pg_prefaulter.toml"; | |
| text = '' | |
| [log] | |
| # level can be set to "DEBUG", "INFO", "WARN", "ERROR", or "FATAL" | |
| level = "DEBUG" | |
| [postgresql] | |
| pgdata = "${config.services.postgresql.dataDir}" | |
| database = "postgres" | |
| host = "/var/run/postgresql" | |
| password = "" | |
| #port = 5432 | |
| user = "postgres" | |
| [postgresql.xlog] | |
| pg_waldump-path = "${config.services.postgresql.package}/bin/pg_waldump" | |
| [run] | |
| pprof.enable = false | |
| log-format = "human" | |
| num-io-threads = 1 | |
| ''; | |
| }; | |
| in | |
| { | |
| # We use pg_prefaulter to prevent PostgreSQL replicas on HDD machines from falling way behind. | |
| # The issue is documented at https://github.com/joyent/pg_prefaulter#background | |
| # but we deploy https://github.com/bschofield/pg_prefaulter (with the posix_fadvise commit) | |
| systemd.services.pg_prefaulter = { | |
| description = "pg_prefaulter"; | |
| serviceConfig = { | |
| # TODO: put pg_prefaulter in nixpkgs | |
| ExecStart = "/var/lib/postgresql/pg_prefaulter/pg_prefaulter run --config ${pg_prefaulter_config}"; | |
| Restart = "always"; | |
| User = "postgres"; | |
| Group = "postgres"; | |
| }; | |
| after = [ "postgresql.service" ]; | |
| wantedBy = [ "multi-user.target" ]; | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment