diff -ruN bind-9.4.1_p1.original-not-compiled/work/bind-9.4.1-P1/contrib/dlz/drivers/dlz_postgres_driver.c bind-9.4.1_p1.patched-not-compiled/work/bind-9.4.1-P1/contrib/dlz/drivers/dlz_postgres_driver.c
--- bind-9.4.1_p1.original-not-compiled/work/bind-9.4.1-P1/contrib/dlz/drivers/dlz_postgres_driver.c	2005-10-26 08:57:23.000000000 +0400
+++ bind-9.4.1_p1.patched-not-compiled/work/bind-9.4.1-P1/contrib/dlz/drivers/dlz_postgres_driver.c	2008-04-08 02:18:31.000000000 +0400
@@ -51,6 +51,8 @@
  */
 
 #ifdef DLZ_POSTGRES
+#define CUT_TEMP_MSGS
+#define PRIVATE_ZONE_OPTIMIZE
 
 #include <config.h>
 #include <stdio.h>
@@ -296,11 +298,43 @@
 	unsigned int dlz_thread_num = 1+(int) (1000.0*rand()/(RAND_MAX+1.0));
 
 	REQUIRE(*rs == NULL);
+#ifdef PRIVATE_ZONE_OPTIMIZE
+    
+#define _10_IN_ADDR_ARPA    "10.in-addr.arpa"
+#define _168_IN_ADDR_ARPA   "168.192.in-addr.arpa"
+#define _10_LEN             15
+#define _168_LEN            20
+
+    uint8_t octs[4];
+    char conv_host[15];
+    bzero(conv_host, sizeof(conv_host));
+    if(!memcmp(zone + strlen(zone) - _10_LEN, _10_IN_ADDR_ARPA, _10_LEN))
+    {
+        if(sscanf(zone, "%hhu.%hhu.%hhu.%hhu.", &octs[0], &octs[1], &octs[2], &octs[3]) == 4)
+        {
+            sprintf(conv_host, "%hhu.%hhu.%hhu", octs[0], octs[1], octs[2]);            
+            record = conv_host;
+            zone = _10_IN_ADDR_ARPA;
+        }
+    }
+    else if(!memcmp(zone + strlen(zone) - _168_LEN, _168_IN_ADDR_ARPA, _168_LEN))
+    {
+        if(sscanf(zone, "%hhu.%hhu.%hhu.%hhu.", &octs[0], &octs[1], &octs[2], &octs[3]) == 4)
+        {
+            sprintf(conv_host, "%hhu.%hhu", octs[0], octs[1]);
+            record = conv_host;
+            zone = _168_IN_ADDR_ARPA;
+        }
+    }
 
+#endif
+
+#ifndef CUT_TEMP_MSGS
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d Getting DBI", dlz_thread_num);
+#endif
 
 	/* get db instance / connection */
 #ifdef ISC_PLATFORM_USETHREADS
@@ -318,11 +352,13 @@
 
 #endif /* ISC_PLATFORM_USETHREADS */
 
+#ifndef CUT_TEMP_MSGS
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d Got DBI - checking query", dlz_thread_num);
 
+#endif
 	/* if DBI is null, can't do anything else */
 	if (dbi == NULL) {
 		result = ISC_R_FAILURE;
@@ -391,10 +427,12 @@
 		goto cleanup;
 	}
 
+#ifndef CUT_TEMP_MSGS
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d checked query", dlz_thread_num);
+#endif
 
 	/*
 	 * was a zone string passed?  If so, make it safe for use in
@@ -410,10 +448,12 @@
 		dbi->zone = NULL;
 	}
 
+#ifndef CUT_TEMP_MSGS    
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d did zone", dlz_thread_num);
+#endif
 
 	/*
 	 * was a record string passed?  If so, make it safe for use in
@@ -430,10 +470,12 @@
 	}
 
 
+#ifndef CUT_TEMP_MSGS    
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d did record", dlz_thread_num);
+#endif
 
 	/*
 	 * was a client string passed?  If so, make it safe for use in
@@ -449,10 +491,12 @@
 		dbi->client = NULL;
 	}
 
+#ifndef CUT_TEMP_MSGS
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 	DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d did client", dlz_thread_num);
+#endif
 
 	/*
 	 * what type of query are we going to run?
@@ -486,10 +530,12 @@
 		goto cleanup;
 	}
 
+#ifndef CUT_TEMP_MSGS
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d built query", dlz_thread_num);
+#endif
 
 	/* if the querystring is null, Bummer, outta RAM.  UPGRADE TIME!!!   */
 	if (querystring  == NULL) {
@@ -497,10 +543,12 @@
 		goto cleanup;
 	}
 
+#ifndef CUT_TEMP_MSGS
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d query is '%s'", dlz_thread_num, querystring);
+#endif
 
 	/*
 	 * output the full query string during debug so we can see
@@ -512,11 +560,13 @@
 
 	/* attempt query up to 3 times. */
 	for (j=0; j < 3; j++) {
+#ifndef CUT_TEMP_MSGS
 		/* temporary logging message */
 		isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 			      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 			      "%d executing query for %d time",
 			      dlz_thread_num, j);
+#endif
 		/* try to get result set */
 		*rs = PQexec((PGconn *)dbi->dbconn, querystring );
 		result = ISC_R_SUCCESS;
@@ -525,11 +575,13 @@
 		 * attempts.
 		 */
 		for (i=0; *rs == NULL && i < 3; i++) {
+#ifndef CUT_TEMP_MSGS
 			/* temporary logging message */
 			isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 				      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 				      "%d resetting connection",
 				      dlz_thread_num);
+#endif
 			result = ISC_R_FAILURE;
 			PQreset((PGconn *) dbi->dbconn);
 			/* connection ok, break inner loop */
@@ -538,18 +590,23 @@
 		}
 		/* result set ok, break outter loop */
 		if (PQresultStatus(*rs) == PGRES_TUPLES_OK) {
+#ifndef CUT_TEMP_MSGS
 			/* temporary logging message */
 			isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 				      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 				      "%d rs ok", dlz_thread_num);
+#endif
 			break;
 		} else {
 			/* we got a result set object, but it's not right. */
+#ifndef CUT_TEMP_MSGS
 			/* temporary logging message */
 			isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 				      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 				      "%d clearing rs", dlz_thread_num);
+#endif
 			PQclear(*rs);	/* get rid of it */
+            *rs = NULL;
 			/* in case this was the last attempt */
 			result = ISC_R_FAILURE;
 		}
@@ -558,10 +615,12 @@
  cleanup:
 	/* it's always good to cleanup after yourself */
 
+#ifndef CUT_TEMP_MSGS
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d cleaning up", dlz_thread_num);
+#endif
 
 	/* if we couldn't even allocate DBI, just return NULL */
 	if (dbi == NULL)
@@ -581,10 +640,12 @@
 
 #ifdef ISC_PLATFORM_USETHREADS
 
+#ifndef CUT_TEMP_MSGS
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d unlocking mutex", dlz_thread_num);
+#endif
 
 	/* release the lock so another thread can use this dbi */
 	isc_mutex_unlock(&dbi->instance_lock);
@@ -595,10 +656,12 @@
 	if (querystring  != NULL)
 		isc_mem_free(ns_g_mctx, querystring );
 
+#ifndef CUT_TEMP_MSGS
 	/* temporary logging message */
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
 		      DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
 		      "%d returning", dlz_thread_num);
+#endif
 
 	/* return result */
 	return result;
