A team wants DNS zones stored in a database instead of flat files — so the provisioning system can write records via SQL, a web UI can read them, and replication piggybacks on the existing MariaDB primary/replica pair. This article is the install procedure for PowerDNS Authoritative with the gmysql backend on Ubuntu: schema, config, first zone, and verification. The deliverable is a working pdns_server answering queries from rows in MariaDB.
How to verify
Before installing, check what already listens on port 53 and whether MariaDB is reachable from this host. Mixing PowerDNS with BIND on the same listener is a classic foot-gun.
ss -lunp | grep ':53\b'
ss -ltnp | grep ':3306\b'
mysql -u root -p -e "SHOW DATABASES" | grep pdns
dpkg -l | grep -E 'pdns-server|pdns-backend|bind9'
systemctl status systemd-resolved
If port 53 is taken by systemd-resolved, disable its stub listener. If MariaDB is on a different host, confirm the firewall and the user grant.
What’s happening
PowerDNS Authoritative is a database-backed nameserver. Every zone, record, and metadata row lives in MariaDB tables (domains, records, domainmetadata, cryptokeys, etc.). The pdns_server daemon connects on startup, caches the data, and answers DNS queries by reading from MariaDB. Replication between primary and secondary nameservers can happen two ways:
- DNS-native replication — primary PowerDNS does AXFR/IXFR to secondary PowerDNS instances, just like BIND. Schemas can differ across the pair.
- Database-level replication — MariaDB primary/replica streams binlogs to the secondary host’s database, and each PowerDNS reads its local copy. Faster and avoids per-zone NOTIFY plumbing, but the topology is now MariaDB-shaped.
Both work in production. The choice depends on whether the team is more comfortable with DNS or database operations.
The schema is documented in /usr/share/doc/pdns-backend-mysql/schema.mysql.sql. Key tables:
domains— one row per zone. Holds the SOA timing, type (NATIVE,MASTER,SLAVE), and the master IP for slave zones.records— one row per RR. Joined todomainsbydomain_id. Holds name, type, content, TTL, prio.domainmetadata— per-zone settings (TSIG keys, axfr-source, presigned flag).cryptokeys— DNSSEC keys when using the built-in signer.
The procedure
-
Install MariaDB and PowerDNS. On Ubuntu, the
pdns-serverandpdns-backend-mysqlpackages are in the main archive:sudo apt update sudo apt install -y mariadb-server pdns-server pdns-backend-mysql pdns-tools sudo systemctl status mariadb pdns -
Create the database and user. Use a long random password and store it in a secret manager — it ends up in plain text in
/etc/powerdns/pdns.d/:CREATE DATABASE pdns CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'; CREATE USER 'pdns'@'localhost' IDENTIFIED BY 'a-long-random-password'; GRANT ALL ON pdns.* TO 'pdns'@'localhost'; FLUSH PRIVILEGES; -
Load the schema. The package ships the SQL file:
sudo mysql pdns < /usr/share/doc/pdns-backend-mysql/schema.mysql.sql mysql -u pdns -p pdns -e "SHOW TABLES" -
Configure PowerDNS for the gmysql backend. Drop a file in
/etc/powerdns/pdns.d/:# /etc/powerdns/pdns.d/gmysql.conf launch=gmysql gmysql-host=127.0.0.1 gmysql-port=3306 gmysql-dbname=pdns gmysql-user=pdns gmysql-password=a-long-random-password gmysql-dnssec=yesAnd in
/etc/powerdns/pdns.conf(top-level):local-address=0.0.0.0 local-port=53 setuid=pdns setgid=pdns security-poll-suffix= default-soa-content=ns1.example.com hostmaster.example.com 0 10800 3600 1209600 3600 default-ttl=3600security-poll-suffix=empty silences the security-poll telemetry — set it explicitly so you do not get a startup warning. -
Restart and check the listener. The default unit is
pdns.serviceon Ubuntu:sudo systemctl restart pdns sudo journalctl -u pdns -n 50 --no-pager ss -lunp | grep ':53\b' -
Add a zone via
pdnsutil. This is the operator-friendly path; the alternative is direct SQL INSERTs:sudo pdnsutil create-zone example.com ns1.example.com sudo pdnsutil add-record example.com www A 203.0.113.10 sudo pdnsutil add-record example.com @ MX '10 mail.example.com.' sudo pdnsutil rectify-zone example.com sudo pdnsutil list-zone example.comrectify-zoneupdates the ordering/NSEC fields PowerDNS uses internally — re-run after bulk SQL inserts. -
Verify with dig. Query the local server, then from another host:
dig @127.0.0.1 example.com SOA +norec dig @127.0.0.1 www.example.com A +norec +short dig @localhost-public-ip example.com NS +norec
Common pitfalls
- Forgetting
pdnsutil rectify-zoneafter SQL writes. Records inserted via SQL bypass the trigger that updatesordername. Without it, AXFR works but NSEC3-signed responses are wrong. - MariaDB connection pool exhaustion. PowerDNS opens one connection per receiver thread. Default
receiver-threads=1is fine for small zones; for high QPS bump it to 2-4 and confirmmax_connectionsin MariaDB has headroom. - Slow first query after restart. The query cache is cold; the first thousand queries hit the database directly. Warm it by replaying a query log against the new instance before swinging traffic.
- Replication lag. If using MariaDB-level replication, the secondary PowerDNS may answer with stale data while the binlog catches up. Use
SHOW REPLICA STATUSto monitorSeconds_Behind_Master, alert at 30s. - API tokens in flat files. The PowerDNS HTTP API is gated by an
api-key=. That string ends up in/etc/powerdns/pdns.d/api.conf— chmod 0640, chownpdns:pdns, and prefer reading from a Vault-rendered template.
In the engagements we run, database-backed PowerDNS is usually chosen because the DNS records are not the source of truth — they are derived from a customer/asset database, and PowerDNS is the projection layer. We codify the schema migration, monitor replication and zone-count growth, and run pdnsutil rectify-all-zones on a schedule so DNSSEC stays consistent. See our managed operations service for the broader operating model.