The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

As an Amazon Associate I earn from qualifying purchases.
Scripts / handy tips
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 build bind9 sdb pgsql from ports
Author: ardya 
Date:   10-08-08 05:52

For those interested in running bind9 using binds sdb database interface with a postgresql database, here's how I managed to do it using the bind94 port.

All of this was done on freebsd version 7.0-RELEASE-p3, postgresql74-client, bind 9.4.2-P2

First you need to install the postgresql-client port, I used version 7.4 as my pgsql server is that version.

I had to add an entry into /etc/make.conf so the bind build would find the pgsql libs:

.if ${.CURDIR:M*/bind94*}

cd /usr/ports/dns/bind94

Run make config, I chose to replace the systems bind installation. run make, then kill it when you see configure starting to run.

Now the fun begins :)
cp work/bind-9.4.2-P2/contrib/sdb/pgsql/pgsqldb.* work/bind-9.4.2-P2/bin/named
vi work/bind-9.4.2-P2/bin/named/pgsql.c:

#include <pgsql/libpq-fe.h>
#include "/usr/local/include/libpq-fe.h"

Comment out the include and add the above one.
vi work/bind-9.4.2-P2/bin/named/

DBDRIVER_OBJS = pgsqldb.@O@
DBDRIVER_SRCS = pgsqldb.c

Fill in the values as shown above.
vi work/bind-9.4.2-P2/bin/named/main.c:

Three entries have to be made here, type /xx then hit enter, the first you'll see is
/* #include "xxdb.h" */
Underneath that add
#include "pgsqldb.h"
Rerun the xx search and the next line will show
/* xxdb_init(); */
Underneath that add
Rerun the xx search again and the next line will show
/* xxdb_clear(); */
Underneath that add

Save and exit vi, run make then make install, test the installation for database connectivity. Voila. If the build itself fails due to not finding either the pgsql include or lib, double check your edits as shown above. Note I didn't run make clean in the case where you may need to review the above edited files for any troubleshooting.

Configuring zones in named.conf, and postgres server itself falls outside the scope of this document. The basic format of a zone entry that uses pgsql for zone data is:

zone "blah" in {type master;database "pgsql dbname tablename dbhost dbuser password";notify no;};

pgsql defines the sdb database interface type
dbname is the name of the database that holds the zone tables
table is the table name that holds that zones data (one table per zone)
dbhost is the hostname or IP of the pgsql server
dbuser is the database user that has, preferrably, read only access to the database in question
password is the dbusers password

Included in the bind source code in /usr/ports/dns/bind94/work/bind-9.4.2-P2/contrib/sdb/pgsql/ is the source code for aq program called zonetodb, it takes zone files and inputs them into the database for you.

Table schemas require at east these 4 columns:
name | text |
ttl | integer |
rdtype | text |
rdata | text |

name column holds the hostname, or
ttl is time to live
rdtype is the record type, SOA/A/AAAA/PTR/NS/TXT/CNAME etc
rdata is the IP if A/AAAA, fqdn if PTR/NS/MX/CNAME, text string for TXT, and SOA gets special treatment, primary ns fqdn email.address serial_num and 4 various cache and ttl values as shown in a normal bind zone file.

More documentation available in /usr/ports/dns/bind94/work/bind-9.4.2-P2/doc/misc/sdb

I read freebsd-questions listmail, and can be found on IRC on EFNets #freebsdhelp.

Reply To This Message
 Re: build bind9 sdb pgsql from ports
Author: ardya 
Date:   28-08-08 14:56

Well thanks to pfloyd and wxs, a port was created and committed for this:

Thanks guys, its working great.

Reply To This Message
 Re: build bind9 sdb pgsql from ports
Author: Dan 
Date:   28-08-08 15:19

Close: dns/bind9-sdb-postgresql

Or as I prefer to say:


Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 

 User Login
 User Name:
 Remember my login:
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum