pgsqldns is a DNS server. It accepts iterative DNS queries from hosts around the Internet, and responds with information derived from a set of PostgreSQL tables.
Normally pgsqldns would be set up by the pgsqldns-conf program, but that program doesn't exist yet.
pgsqldns runs chrooted in the directory specified by the $ROOT environment variable, under the uid and gid specified by the $UID and $GID environment variables.
pgsqldns listens for incoming UDP packets addressed to port 53 of $IP. It does not listen for TCP queries.
pgsqldns connects to a PostgreSQL server as specified by $PGHOST, $PGPORT, $PGUSERNAME, $PGPASSWORD, and $PGDATABASE. After connecting, it executes any commands found in $SQL_INITIALIZE.
It loads in the nameserver names and IPs from NS0 through NS9. Each such nameserver must consist of a fully qualified domain name, a colon, and its IP. The TTL for the additional A records is read from $NS_IP_TTL, and the TTL for the NS name records is read from $NS_NAME_TTL. Both values default to 65536.
pgsqldns serves out an automatically generated SOA record for each domain listed in the tables. The TTL, refresh, retry, expire, minimum, and mailbox values for this SOA are read from $SOA_TTL, $SOA_REFRESH, $SOA_RETRY, $SOA_EXPIRE, $SOA_MINIMUM, and $SOA_MAILBOX, which default to 2560, 4096, 256, 65536, 2560, and "hostmaster". If the mailbox name is not qualified when the SOA record is generated, the domain name is appended to it. The serial number is always set to the current UNIX epoch time.
The schema for pgsqldns is described here.
See also the documentation for djbdns, in particular the documentation for tinydns, with which this program shares many features.