Table of Contents
Defined in /modules/blocks/postgresql.nix.
This block sets up a PostgreSQL database.
Compared to the upstream nixpkgs module, this module also sets up:
Enabling TCP/IP login and also accepting password authentication from localhost with shb.postgresql.enableTCPIP.
Enhance the ensure* upstream option by setting up a database’s password from a password file with shb.postgresql.ensures.
Debug logging with auto_explain and pg_stat_statements with shb.postgresql.debug.
Ensure a database and user exists:
shb.postgresql.ensures = [
{
username = "firefly-iii";
database = "firefly-iii";
}
];
Also set up the database password from a file path:
shb.postgresql.ensures = [
{
username = "firefly-iii";
database = "firefly-iii";
passwordFile = "/run/secrets/firefly-iii_db_password";
}
];
This block can be backed up using the database backup contract.
Contract integration tests are defined in /test/contracts/databasebackup.nix.
{
my.backup.provider."postgresql" = {
request = config.shb.postgresql.databasebackup;
settings = {
// Specific options for the backup provider.
};
};
}
Specific integration tests are defined in /test/blocks/postgresql.nix.
shb.postgresql.enableTCPIP
Enable TCP/IP connection on given port.
Type: boolean
Default:
false
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.databasebackup
Backup configuration.
Type: submodule
Default:
{ }
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.databasebackup.request
Request part of the database backup contract.
Options set by the requester module enforcing how to backup files.
Type: submodule
Default:
""
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.databasebackup.request.backupCmd
Command that produces the database dump on stdout.
Type: string
Default:
''
''${pkgs.postgresql}/bin/pg_dumpall | ''${pkgs.gzip}/bin/gzip --rsyncable
''
Example:
${pkgs.postgresql}/bin/pg_dumpall | ${pkgs.gzip}/bin/gzip --rsyncable
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.databasebackup.request.backupName
Name of the backup in the repository.
Type: string
Default:
"postgres.sql"
Example:
"postgresql.sql"
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.databasebackup.request.restoreCmd
Command that reads the database dump on stdin and restores the database.
Type: string
Default:
''
''${pkgs.gzip}/bin/gunzip | ''${pkgs.postgresql}/bin/psql postgres
''
Example:
${pkgs.gzip}/bin/gunzip | ${pkgs.postgresql}/bin/psql postgres
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.databasebackup.request.user
Unix user doing the backups.
This should be an admin user having access to all databases.
Type: string
Default:
"postgres"
Example:
"postgres"
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.databasebackup.result
Result part of the database backup contract.
Options set by the provider module that indicates the name of the backup and restore scripts.
Type: submodule
Default:
""
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.databasebackup.result.backupService
Name of service backing up the database.
This script can be ran manually to backup the database:
$ systemctl start backup.service
Type: string
Default:
"backup.service"
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.databasebackup.result.restoreScript
Name of script that can restore the database. One can then list snapshots with:
$ restore snapshots
And restore the database with:
$ restore restore latest
Type: string
Default:
"restore"
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.debug
Enable debugging options.
Currently enables shared_preload_libraries = “auto_explain, pg_stat_statements”
See https://www.postgresql.org/docs/current/pgstatstatements.html
Type: boolean
Default:
false
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.ensures
List of username, database and/or passwords that should be created.
Type: list of (submodule)
Default:
[ ]
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.ensures.*.database
Postgres database.
Type: string
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.ensures.*.passwordFile
Optional password file for the postgres user. If not given, only peer auth is accepted for this user, otherwise password auth is allowed.
Type: null or string
Default:
null
Example:
"/run/secrets/postgresql/password"
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|
shb.postgresql.ensures.*.username
Postgres user name.
Type: string
Declared by:
<selfhostblocks/modules/blocks/postgresql.nix>
|