Warning: this backend is largely untested!
PostgreSQL backend with easily configurable SQL statements, allowing you to graft PDNS on any PostgreSQL database of your chosing. Because all database schemas will be different, a generic backend is needed.
To configure this backend, 9 SQL queries need to be specified which are all very similar. 4 queries are needed for regular lookups, 4 for 'fancy records' which are disabled by default, 1 is needed for zonetransfers.
The 4+4 regular queries must return the following 6 fields, in this exact order:
This is the 'right hand side' of a DNS record. For an A record, this is the IP address for example.
TTL of this record, in seconds. Must be a real value, no checking is performed.
For MX records, this should be the priority of the mail exchanger specified.
The ASCII representation of the qtype of this record. Examples are 'A', 'MX', 'SOA', 'AAAA'. Make sure that this field returns an exact answer - PDNS won't recognize 'A ' as 'A'. This can be achieved by using a VARCHAR instead of a CHAR.
Each domain must have a unique domain_id. No two domains may share a domain_id, all records in a domain should have the same. A number.
Actual name of a record. Must not end in a '.' and be fully qualified - it is not relative to the name of the domain!
As said earlier, there are 8 SQL queries for regular lookups. If so called 'MBOXFW' fancy records are not used, four remain:
Default: select content,ttl,prio,type,domain_id,name from records where qtype='%s' and name='%s' This is the most used query, needed for doing 1:1 lookups of qtype/name values. First %s is replaced by the ASCII representation of the qtype of the question, the second by the name.
Default: select content,ttl,prio,type,domain_id,name from records where qtype='%s' and name='%s' and id=%d Used for doing lookups within a domain. First %s is replaced by the qtype, the %d which should appear after the %s by the numeric domain_id.
For doing ANY queries. Also used internally. Default: select content,ttl,prio,type,domain_id,name from records where name='%s' The %s is replaced by the qname of the question.
For doing ANY queries within a domain. Also used internally. Default: select content,ttl,prio,type,domain_id,name from records where name='%s' and domain_id=%d The %s is replaced by the name of the domain, the %d by the numerical domain id.
If PDNS is used with so called 'Fancy Records', the 'MBOXFW' record exists which specifies an email address forwarding instruction, wildcard queries are sometimes needed. This is not enabled by default. A wildcard query is an internal concept - it has no relation to *.domain-type lookups. You can safely leave these queries blank.
Can be left blank. See above for an explanation. Default: select content,ttl,prio,type,domain_id,name from records where qtype='%s' and name like '%s'
Can be left blank. See above for an explanation. Default: select content,ttl,prio,type,domain_id,name from records where qtype='%s' and name like '%s' and domain_id=%d Used for doing lookups within a domain.
For doing wildcard ANY queries. Default: select content,ttl,prio,type,domain_id,name from records where name like '%s'
For doing wildcard ANY queries within a domain. Default: select content,ttl,prio,type,domain_id,name from records where name like '%s' and domain_id=%d
To list an entire zone. Default: select content,ttl,prio,type,domain_id,name from records where domain_id=%d
The default queries correspond to the following database schema:
CREATE TABLE records ( id SERIAL PRIMARY KEY, domain_id INT DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, type VARCHAR(6) DEFAULT NULL, content VARCHAR(255) DEFAULT NULL, ttl INT DEFAULT NULL, prio INT DEFAULT NULL, change_data INT DEFAULT NULL); CREATE INDEX name_index ON records(name); CREATE INDEX nametype_index ON records(name,type); CREATE INDEX domain_id ON records(domain_id); GRANT SELECT ON records TO pdns; GRANT SELECT ON records_id_seq TO pdns;
The queries above are specified in pdns.conf. For example, the basic-query would appear as:
gpgsql-basic-query=select content,ttl,prio,type,domain_id,name from records where qtype='%s' and name='%s'Queries can span multiple lines, like this:
gpgsql-basic-query=select content,ttl,prio,type,domain_id,name from records \ where qtype='%s' and name='%s'Besides the query related settings, the following configuration options are available:
Database name to connect to
Database host to connect to
Password to connect with
PgSQL user to connect as