database.url (DNZ_DATABASE_URL):
DNZ works the same on all three; only where the data is kept changes. It creates and upgrades its
own tables at startup, so give it an empty database and a user that may create tables in it.
Run one DNZ server per database. Each server keeps the zones in memory and reloads them when they
change through it, so two servers sharing a database wouldn’t see each other’s changes. For more
DNS servers, use replication: secondaries keep their own database.
Postgres
1
Create the database
2
Point DNZ at it
dnz.toml:3
Check and start
database: Postgres at postgres://dnz:***@db.internal:5432/dnz. Start DNZ; it creates its
tables and logs the same line.- TLS: add
?sslmode=require, or?sslmode=verify-full&sslrootcert=/etc/dnz/db-ca.pemto check the server’s certificate. - Unix socket:
postgres://dnz@localhost/dnz?host=/var/run/postgresql. - DNZ creates a case-insensitive ICU collation named
nocase. Standard Postgres builds have ICU, including the Docker images and managed services.
MySQL
1
Create the database
2
Point DNZ at it
3
Check and start
database: MySQL at mysql://dnz:***@db.internal:3306/dnz. Start DNZ; it creates its tables.- TLS: add
?ssl-mode=required, or?ssl-mode=verify_identity&ssl-ca=/etc/dnz/db-ca.pem. - DNZ’s connections use
ANSI_QUOTES,PIPES_AS_CONCATandNO_BACKSLASH_ESCAPES, set per connection; the server’s ownsql_modecan stay as it is. Tables are InnoDB withutf8mb4.
Connections and files
- Characters such as
@,:or/in the password go percent-encoded:p%40ssforp@ss. - DNZ keeps up to 16 connections to Postgres or MySQL open.
- The password never shows up in
dnz config show,dnz config checkor the log. - Files DNZ keeps besides the database, the GeoIP database and the local dnz-proxy’s state, go in
database.data_dir(DNZ_DATA_DIR). With SQLite that’s the database file’s folder. With Postgres or MySQL it’s the working directory:/var/lib/dnzwith the systemd unit,/datain the Docker image. - The dashboard’s Server tab shows which database DNZ uses and how big it is.
Docker with Postgres
Save this asdocker-compose.yml:
docker-compose.yml
Move an existing install from SQLite
dnz db migrate-from-sqlite copies a SQLite install into an empty Postgres or MySQL database. It
copies every table in an order that keeps the foreign keys intact, sets the id sequences past the
copied ids, and compares the row counts at the end.
- systemd
- Docker
/etc/dnz/dnz.env and start DNZ:/etc/dnz/dnz.env
- Without
--to, the target isdatabase.url/DNZ_DATABASE_URL. - The target must have no users or zones yet. The rows are copied in one transaction, so a copy that fails leaves the target empty to try again.
- The SQLite file is first brought up to this version’s schema, as starting this version of DNZ on
it would, and otherwise left alone. Going back is a matter of pointing
DNZ_DATABASE_URLat it again.