Skip to content

postgres

Whether to enable Add PostgreSQL process. .

Type: boolean

Default:

false

Example:

true

Declared by:

The PostgreSQL package to use. Use this to override the default with a specific version.

Type: package

Default:

pkgs.postgresql

Example:

pkgs.postgresql_15

Declared by:

Create a database named like current user on startup. Only applies when initialDatabases is an empty list.

Type: boolean

Default:

true

Declared by:

Additional PostgreSQL extensions to install.

The available extensions are:

  • age
  • anonymizer
  • apache_datasketches
  • callPackage
  • citus
  • cstore_fdw
  • h3-pg
  • hypopg
  • ip4r
  • jsonb_deep_sum
  • lantern
  • omnigres
  • periods
  • pg-gvm
  • pg-semver
  • pg_auto_failover
  • pg_background
  • pg_bigm
  • pg_byteamagic
  • pg_cron
  • pg_csv
  • pg_ed25519
  • pg_embedding
  • pg_graphql
  • pg_hint_plan
  • pg_hll
  • pg_ivm
  • pg_libversion
  • pg_net
  • pg_partman
  • pg_rational
  • pg_relusage
  • pg_repack
  • pg_roaringbitmap
  • pg_safeupdate
  • pg_search
  • pg_similarity
  • pg_squeeze
  • pg_tle
  • pg_topn
  • pg_uuidv7
  • pgaudit
  • pgddl
  • pgjwt
  • pgmq
  • pgroonga
  • pgrouting
  • pgsodium
  • pgsql-http
  • pgtap
  • pgvecto-rs
  • pgvector
  • pgvectorscale
  • pgx_ulid
  • plperl
  • plpgsql_check
  • plpython3
  • plr
  • pltcl
  • plv8
  • pointcloud
  • postgis
  • repmgr
  • rum
  • smlar
  • sqlite_fdw
  • system_stats
  • tds_fdw
  • temporal_tables
  • timescaledb
  • timescaledb-apache
  • timescaledb_toolkit
  • tsja
  • vectorchord
  • wal2json

Type: null or (function that evaluates to a(n) list of package)

Default:

null

Example:

extensions: [
extensions.pg_cron
extensions.postgis
extensions.timescaledb
];

Declared by:

The contents of a custom pg_hba.conf file to copy into the postgres installation. This allows for custom connection rules that you want to establish on the server.

Type: null or string

Default:

null

Example:

builtins.readFile ./my-custom/directory/to/pg_hba.conf

Declared by:

Additional arguments passed to initdb during data dir initialisation.

Type: list of strings concatenated with “\n”

Default:

[
"--locale=C"
"--encoding=UTF8"
]

Example:

[
"--data-checksums"
"--allow-group-access"
]

Declared by:

List of database names and their initial schemas that should be used to create databases on the first startup of Postgres. The schema attribute is optional: If not specified, an empty database is created.

Type: list of (submodule)

Default:

[ ]

Example:

[
{
name = "foodatabase";
schema = ./foodatabase.sql;
}
{ name = "bardatabase"; }
]

Declared by:

services.postgres.initialDatabases.*.initialSQL

Section titled “services.postgres.initialDatabases.*.initialSQL”

SQL commands to run on this specific database during it’s initialization. Multiple SQL expressions can be separated by semicolons.

Type: null or string

Default:

null

Example:

CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT);
INSERT INTO users (name) VALUES ('admin');
CREATE EXTENSION IF NOT EXISTS pg_uuidv7;

Declared by:

The name of the database to create.

Type: string

Declared by:

Password of the database owner role. Requires user to be set.

Type: null or string

Default:

null

Declared by:

services.postgres.initialDatabases.*.schema

Section titled “services.postgres.initialDatabases.*.schema”

The initial schema of the database; if null (the default), an empty database is created.

Type: null or absolute path

Default:

null

Declared by:

Username of owner of the database. If set, a role with this name is created and the database is owned by it. If null, the default $USER is used.

Type: null or string

Default:

null

Declared by:

Initial SQL commands to run during database initialization. This can be multiple SQL expressions separated by a semi-colon. Use initialScript for server-wide setup, such as creating roles or configuring global settings. For database-specific initialization, use initialSQL within initialDatabases. initialScript is executed after the initialDatabases setup is done.

Type: null or string

Default:

null

Example:

CREATE ROLE postgres SUPERUSER;
CREATE ROLE bar;

Declared by:

A comma-separated list of TCP/IP address(es) on which the server should listen for connections.

By default, the server only accepts connections over unix sockets.

This option is parsed to set the PGHOST environment variable.

Special values:

  • ‘*’ to listen on all available network interfaces.
  • ‘0.0.0.0’ to listen on all available IPv4 network interfaces.
  • ‘::’ to listen on all available IPv6 network interfaces.
  • ‘localhost’ to listen only on the loopback interface.
  • ‘’ (empty string) disables TCP/IP connections and listens only on the unix socket.

Type: string

Default:

""

Example:

"127.0.0.1"

Declared by:

The TCP port to accept connections.

Type: 16 bit unsigned integer; between 0 and 65535 (both inclusive)

Default:

5432

Declared by:

PostgreSQL configuration. Refer to https://www.postgresql.org/docs/11/config-setting.html#CONFIG-SETTING-CONFIGURATION-FILE for an overview of postgresql.conf.

String values will automatically be enclosed in single quotes. Single quotes will be escaped with two single quotes as described by the upstream documentation linked above.

Type: attribute set of (boolean or floating point number or signed integer or string)

Default:

{ }

Example:

{
log_connections = true;
log_statement = "all";
logging_collector = true
log_disconnections = true
log_destination = lib.mkForce "syslog";
}

Declared by: