diff --git a/lib/modules/Mysql.pmod/SqlTable.pike b/lib/modules/Mysql.pmod/SqlTable.pike
index eadfbfaad54aff0217d96f3feba7ccc504d8b054..90df946fd8bbd64c38678acb5844f2e885de9a38 100644
--- a/lib/modules/Mysql.pmod/SqlTable.pike
+++ b/lib/modules/Mysql.pmod/SqlTable.pike
@@ -701,7 +701,7 @@ int conn_insert (Sql.Sql db_conn, mapping(string:mixed)... records)
 //! explicitly instead of being retrieved via @[get_db].
 {
   Sql.mysql conn = db_conn->master_sql;
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (!sizeof (records)) error ("Must give at least one record.\n");
 #endif
   UPDATE_MSG ("%O: insert %O\n",
@@ -722,7 +722,7 @@ int conn_insert_ignore (Sql.Sql db_conn, mapping(string:mixed)... records)
 //! explicitly instead of being retrieved via @[get_db].
 {
   Sql.mysql conn = db_conn->master_sql;
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (!sizeof (records)) error ("Must give at least one record.\n");
 #endif
   UPDATE_MSG ("%O: insert_ignore %O\n",
@@ -746,7 +746,7 @@ int conn_replace (Sql.Sql db_conn, mapping(string:mixed)... records)
 //! explicitly instead of being retrieved via @[get_db].
 {
   Sql.mysql conn = db_conn->master_sql;
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (!sizeof (records)) error ("Must give at least one record.\n");
 #endif
   UPDATE_MSG ("%O: replace %O\n",
@@ -768,7 +768,7 @@ void conn_update (Sql.Sql db_conn, mapping(string:mixed) record,
 //! explicitly instead of being retrieved via @[get_db].
 {
   Sql.mysql conn = db_conn->master_sql;
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (!(<0,1,2>)[clear_other_fields])
     error ("Invalid clear_other_fields flag.\n");
 #endif
@@ -796,7 +796,7 @@ int conn_insert_or_update (Sql.Sql db_conn, mapping(string:mixed) record,
 //! passed explicitly instead of being retrieved via @[get_db].
 {
   Sql.mysql conn = db_conn->master_sql;
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (!(<0,1,2>)[clear_other_fields])
     error ("Invalid clear_other_fields flag.\n");
 #endif
@@ -819,7 +819,7 @@ int conn_insert_or_update (Sql.Sql db_conn, mapping(string:mixed) record,
   string prop_col_value;
 
   if (sizeof (other_fields)) {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     if (!prop_col) error ("Column(s) %s missing in table %O.\n",
 			  String.implode_nicely (indices (other_fields)),
 			  table);
@@ -993,7 +993,7 @@ array conn_select1 (Sql.Sql db_conn, string|array select_expr,
   Sql.mysql_result res = db_conn->master_sql->big_typed_query (
     query + " WHERE (" + where + ") " + (rest || ""), bindings);
 
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (res->num_fields() != 1)
     error ("Result from %O did not contain a single field (got %d fields).\n",
 	   query, res->num_fields());
@@ -1024,7 +1024,7 @@ mapping(string:mixed) conn_get (Sql.Sql db_conn, mixed id,
 {
   Sql.mysql conn = db_conn->master_sql;
 
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (fields && !sizeof (fields)) error ("No fields selected.\n");
 #endif
 
@@ -1046,7 +1046,7 @@ mapping(string:mixed) conn_get (Sql.Sql db_conn, mixed id,
       mapping(string:string) field_map = mkmapping (fields, fields);
       other_fields = field_map - real_cols;
     }
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     if (!prop_col)
       error ("Requested nonexisting column(s) %s.\n",
 	     String.implode_nicely (indices (other_fields ||
@@ -1243,7 +1243,7 @@ class Result
   // Internal function to initialize all the variables from an
   // optional array of requested fields.
   {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     if (fields && !sizeof (fields)) error ("No fields selected.\n");
 #endif
 
@@ -1291,7 +1291,7 @@ class Result
 	mapping(string:string) field_map = mkmapping (fields, fields);
 	other_fields = field_map - real_cols;
       }
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
       if (!prop_col)
 	error ("Requested nonexisting column(s) %s.\n",
 	       String.implode_nicely (indices (other_fields ||
@@ -1324,7 +1324,7 @@ class Result
   // Iterator interface. This is a separate object only to avoid
   // implementing a `! in Result, which would make it behave oddly.
 
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   protected int got_iterator;
 #endif
 
@@ -1332,7 +1332,7 @@ class Result
   //! Returns an iterator for the result. Only one iterator may be
   //! created per @[Result] object.
   {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     if (got_iterator)
       error ("Cannot create more than one iterator for a Result object.\n");
     got_iterator = 1;
@@ -1425,7 +1425,7 @@ protected void add_mysql_value (String.Buffer buf, string col_name, mixed val)
 // A value with zero_type is formatted as "DEFAULT".
 {
   if (stringp (val)) {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     if (col_types[col_name] != "string")
       error ("Got string value %q for %s column `%s`.\n",
 	     val, col_types[col_name], col_name);
@@ -1447,7 +1447,7 @@ protected void add_mysql_value (String.Buffer buf, string col_name, mixed val)
     if (zero_type (val))
       buf->add ("DEFAULT");
     else {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
       if (col_types[col_name] != "int" && !datetime_cols[col_name])
 	error ("Got integer value %O for %s column `%s`.\n",
 	       val, col_types[col_name] || "string", col_name);
@@ -1461,7 +1461,7 @@ protected void add_mysql_value (String.Buffer buf, string col_name, mixed val)
   else if (val == Val.null)
     buf->add ("NULL");
   else {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     if (objectp (val) && functionp (val->den)) {
       // Allow Gmp.mpq for float fields, and for int fields if they
       // have no fractional part.
@@ -1493,7 +1493,7 @@ protected string make_insert_clause (array(mapping(string:mixed)) records)
   // FIXME: Ought to use bindings, but Mysql.mysql doesn't support it
   // yet (as of pike 7.8.191).
 
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (!sizeof (records)) error ("Must give at least one record.\n");
 #endif
 
@@ -1502,7 +1502,7 @@ protected string make_insert_clause (array(mapping(string:mixed)) records)
     mapping(string:mixed) other_fields = rec - real_cols;
 
     if (sizeof (other_fields)) {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
       if (!prop_col) error ("Column(s) %s missing.\n",
 			    String.implode_nicely (indices (other_fields)));
 #endif
@@ -1555,7 +1555,7 @@ protected string make_pk_where (mapping(string:mixed) rec)
 // primary key, or zero if the record doesn't have values for all pk
 // columns. The pk fields are also removed from the rec mapping.
 {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (!sizeof (pk_cols)) error ("There is no primary key in this table.\n");
 #endif
   String.Buffer buf = String.Buffer();
@@ -1575,14 +1575,14 @@ protected string simple_make_pk_where (mixed id)
 // Returns a WHERE expression like "a=1 AND b=2" for matching the
 // primary key. id is like the argument to get().
 {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (!sizeof (pk_cols)) error ("There is no primary key in this table.\n");
 #endif
 
   String.Buffer buf = String.Buffer();
   if (sizeof (pk_cols) == 1) {
     buf->add ("`", pk_cols[0], "`=");
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     if (id == Val.null)
       error ("Cannot use Val.null for primary key column %O.\n",
 	     pk_cols[0]);
@@ -1592,7 +1592,7 @@ protected string simple_make_pk_where (mixed id)
   }
 
   else {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     if (!arrayp (id) || sizeof (id) != sizeof (pk_cols))
       error ("The id must be an array with %d elements.\n", sizeof (pk_cols));
 #endif
@@ -1600,7 +1600,7 @@ protected string simple_make_pk_where (mixed id)
     foreach (pk_cols; int i; string pk_col) {
       if (first) first = 0; else buf->add (" AND ");
       buf->add ("`", pk_cols[0], "`=");
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
       if (id[i] == Val.null)
 	error ("Cannot use Val.null for primary key column %O.\n", pk_col);
 #endif
@@ -1616,7 +1616,7 @@ protected string make_multi_pk_where (array(mixed) ids, int|void negated)
 // Returns a WHERE expression like "foo IN (2,3,17,4711)" for matching
 // a bunch of records by primary key.
 {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
   if (sizeof (pk_cols) != 1)
     error ("The table must have a single column primary key.\n");
 #endif
@@ -1629,7 +1629,7 @@ protected string make_multi_pk_where (array(mixed) ids, int|void negated)
   string optional_not = negated?" NOT ":"";
 
   if ((<"float", "int">)[pk_type]) {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     foreach (ids; int i; mixed id)
       if (!intp (id) && !floatp (id))
 	error ("Expected numeric value for primary key column %O, "
@@ -1642,7 +1642,7 @@ protected string make_multi_pk_where (array(mixed) ids, int|void negated)
   }
 
   else {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     foreach (ids; int i; mixed id)
       if (!stringp (id))
 	error ("Expected string value for primary key column %O, "
@@ -1723,7 +1723,7 @@ protected mapping(string:mixed) update_pack_fields (
   mapping(string:mixed) other_fields = rec - real_cols;
 
   if (sizeof (other_fields)) {
-#ifdef DEBUG
+#ifdef MYSQL_DEBUG
     if (!prop_col) error ("Column(s) %s missing in table %O.\n",
 			  String.implode_nicely (indices (other_fields)),
 			  table);
diff --git a/lib/modules/Parser.pmod/LR.pmod/GrammarParser.pmod b/lib/modules/Parser.pmod/LR.pmod/GrammarParser.pmod
index 548eb1994dcb1a9bbbbfa974db18901913c18945..9c2b388369ce0594de7c059a559d41d666e833ac 100755
--- a/lib/modules/Parser.pmod/LR.pmod/GrammarParser.pmod
+++ b/lib/modules/Parser.pmod/LR.pmod/GrammarParser.pmod
@@ -32,7 +32,7 @@
  * Defines
  */
 
-/* #define DEBUG */
+/* #define LR_DEBUG */
 
 /* Errors during parsing */
 /* Action for rule is missing from master object */
@@ -324,16 +324,16 @@ Parser make_parser(string str, object|void m)
   nonterminal_lookup = ([]);
 
   ErrorHandler eh = ErrorHandler(
-#ifdef DEBUG
+#ifdef LR_DEBUG
 				 1
-#else /* !DEBUG */
+#else /* !LR_DEBUG */
 				 0
-#endif /* DEBUG */
+#endif /* LR_DEBUG */
 				 );
 
-#ifdef DEBUG
+#ifdef LR_DEBUG
   _parser->set_error_handler(eh->report);
-#endif /* DEBUG */
+#endif /* LR_DEBUG */
 
   g->set_error_handler(eh->report);
 
diff --git a/lib/modules/Protocols.pmod/LDAP.pmod/client.pike b/lib/modules/Protocols.pmod/LDAP.pmod/client.pike
index 3e6eff20035bd17db577aa3d0d7ba19da7612bb7..0d2b56dc0b856032f0490b7b0a9e72b01bc05c60 100644
--- a/lib/modules/Protocols.pmod/LDAP.pmod/client.pike
+++ b/lib/modules/Protocols.pmod/LDAP.pmod/client.pike
@@ -118,13 +118,13 @@ protected function(string:string) get_attr_decoder (string attr,
     if (function(string:string) decoder =
 	syntax_decode_fns[attr_descr->syntax_oid])
       return decoder;
-#ifdef DEBUG
+#ifdef LDAP_DEBUG
     else if (!get_constant_name (attr_descr->syntax_oid))
       werror ("Warning: Unknown syntax %O for attribute %O - "
 	      "binary content assumed.\n", attr_descr->syntax_oid, attr);
 #endif
   }
-#ifdef DEBUG
+#ifdef LDAP_DEBUG
   else if (!nowarn && !has_suffix (attr, ";binary") && !has_value (attr, ";binary;"))
     werror ("Warning: Couldn't fetch attribute description for %O - "
 	    "binary content assumed.\n", attr);
@@ -139,13 +139,13 @@ protected function(string:string) get_attr_encoder (string attr)
     if (function(string:string) encoder =
 	syntax_encode_fns[attr_descr->syntax_oid])
       return encoder;
-#ifdef DEBUG
+#ifdef LDAP_DEBUG
     else if (!get_constant_name (attr_descr->syntax_oid))
       werror ("Warning: Unknown syntax %O for attribute %O - "
 	      "binary content assumed.\n", attr_descr->syntax_oid, attr);
 #endif
   }
-#ifdef DEBUG
+#ifdef LDAP_DEBUG
   else if (!has_suffix (attr, ";binary") && !has_value (attr, ";binary;"))
     werror ("Warning: Couldn't fetch attribute description for %O - "
 	    "binary content assumed.\n", attr);
diff --git a/lib/modules/Protocols.pmod/LDAP.pmod/ldap_globals.h b/lib/modules/Protocols.pmod/LDAP.pmod/ldap_globals.h
index e061e35edf29c73c71c41d616b89813991ed43db..4e49ec56c09e247a0c011b7ee2e2f00d1dba199e 100644
--- a/lib/modules/Protocols.pmod/LDAP.pmod/ldap_globals.h
+++ b/lib/modules/Protocols.pmod/LDAP.pmod/ldap_globals.h
@@ -36,7 +36,7 @@
 #define DWRITE_HI(X...)
 #endif
 
-#ifdef DEBUG
+#ifdef LDAP_DEBUG
 #define DO_IF_DEBUG(X...) X
 #else
 #define DO_IF_DEBUG(X...)
diff --git a/lib/modules/Protocols.pmod/LDAP.pmod/module.pmod b/lib/modules/Protocols.pmod/LDAP.pmod/module.pmod
index 419e603972daee1da1dff61ba17be86130dab114..34a88b29d670b7c4cf637a68c8a7084afea45af3 100644
--- a/lib/modules/Protocols.pmod/LDAP.pmod/module.pmod
+++ b/lib/modules/Protocols.pmod/LDAP.pmod/module.pmod
@@ -1260,7 +1260,7 @@ protected void create()
   foreach (incomplete, mapping(string:mixed) descr)
     complete (descr);
 
-#ifdef DEBUG
+#ifdef LDAP_DEBUG
   // To discover duplicate constant names.
   get_constant_name (0);
 #endif
diff --git a/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod b/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod
index b59635e035b2294d607c5b93d2d93905f1b135cc..3b04aba5ecf0d4cd9462993ad366abe963d0e079 100644
--- a/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod
+++ b/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod
@@ -23,7 +23,7 @@
 
 #pike __REAL_VERSION__
 
-// #define DEBUG
+// #define XDEBUG
 
 constant XPORT = 6000;
 
@@ -192,7 +192,7 @@ class Display
   mapping pending_requests; /* Pending requests */
   object pending_actions;   /* Actions awaiting handling */
 
-#ifdef DEBUG
+#ifdef XDEBUG
   mapping debug_requests = ([ ]);
 # define DEBUGREQ(X) ((X)&0xfff)
 #endif
@@ -441,7 +441,7 @@ class Display
 		       errorCode, m->sequenceNumber, m->resourceID,
 		       m->minorCode, m->majorCode);
 		m->errorCode = ._Xlib.error_codes[errorCode];
-#ifdef DEBUG
+#ifdef XDEBUG
 		m->failed_request = debug_requests[DEBUGREQ(m->sequenceNumber)];
 #endif
 #if 0
@@ -839,7 +839,7 @@ class Display
   {
     string data = req->to_string();
     send(data);
-#ifdef DEBUG
+#ifdef XDEBUG
     debug_requests[DEBUGREQ(sequence_number)] = data;
 #endif
     return (sequence_number++)&0xffff; // sequence number is just 2 bytes
diff --git a/lib/modules/SSL.pmod/sslfile.pike b/lib/modules/SSL.pmod/sslfile.pike
index d35e51d206f606900be280e8f7ffb7bb143a8ff8..1fec96affedca2d8b18c582d600bf51a9c28cf49 100644
--- a/lib/modules/SSL.pmod/sslfile.pike
+++ b/lib/modules/SSL.pmod/sslfile.pike
@@ -39,7 +39,7 @@
 //!   destructed timely when dropped.
 //! @endul
 
-// #define DEBUG
+// #define SSLFILE_DEBUG
 // #define SSL3_DEBUG
 // #define SSL3_DEBUG_MORE
 // #define SSL3_DEBUG_TRANSPORT
@@ -217,7 +217,7 @@ protected constant epipe_errnos = (<
 #define SSL_INTERNAL_WRITING (sizeof (write_buffer) ||			\
 			      close_packet_send_state == CLOSE_PACKET_SCHEDULED)
 
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
 
 #if constant (Thread.thread_create)
 
@@ -341,7 +341,7 @@ protected THREAD_T op_thread;
   if (_op_err) throw (_op_err);						\
   } while (0)
 
-#else  // !DEBUG
+#else  // !SSLFILE_DEBUG
 
 #define CHECK_CB_MODE(CUR_THREAD) do {} while (0)
 #define CHECK(IN_CALLBACK, CALLED_FROM_REAL_BACKEND) do {} while (0)
@@ -350,7 +350,7 @@ protected THREAD_T op_thread;
 #define RETURN(RET_VAL) return (RET_VAL)
 #define LEAVE while (0)
 
-#endif	// !DEBUG
+#endif	// !SSLFILE_DEBUG
 
 // stream is assumed to be operational on entry but might be zero
 // afterwards. cb_errno is assumed to be 0 on entry.
@@ -732,7 +732,7 @@ Stdio.File shutdown()
 		    "Abrupt close");
 
     if ((conn->closing & 2) && sizeof (conn->left_over || "")) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
       werror ("Warning: Got buffered data after close in %O: %O%s\n", this,
 	      conn->left_over[..99], sizeof (conn->left_over) > 100 ? "..." : "");
 #endif
@@ -1303,7 +1303,7 @@ void set_alert_callback (function(object,int|object,string:void) alert)
 {
   SSL3_DEBUG_MSG ("SSL.sslfile->set_alert_callback (%O)\n", alert);
   CHECK (0, 0);
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
   if (close_state == STREAM_UNINITIALIZED || !conn)
     error ("Doesn't have any connection.\n");
 #endif
@@ -1343,7 +1343,7 @@ void set_accept_callback (function(void|object,void|mixed:int) accept)
 {
   SSL3_DEBUG_MSG ("SSL.sslfile->set_accept_callback (%O)\n", accept);
   ENTER (0, 0) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
     if (close_state == STREAM_UNINITIALIZED)
       error ("Doesn't have any connection.\n");
 #endif
@@ -1370,7 +1370,7 @@ void set_read_callback (function(void|mixed,void|string:int) read)
 {
   SSL3_DEBUG_MSG ("SSL.sslfile->set_read_callback (%O)\n", read);
   ENTER (0, 0) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
     if (close_state == STREAM_UNINITIALIZED)
       error ("Doesn't have any connection.\n");
 #endif
@@ -1397,7 +1397,7 @@ void set_write_callback (function(void|mixed:int) write)
 {
   SSL3_DEBUG_MSG ("SSL.sslfile->set_write_callback (%O)\n", write);
   ENTER (0, 0) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
     if (close_state == STREAM_UNINITIALIZED)
       error ("Doesn't have any connection.\n");
 #endif
@@ -1425,7 +1425,7 @@ void set_close_callback (function(void|mixed:int) close)
 {
   SSL3_DEBUG_MSG ("SSL.sslfile->set_close_callback (%O)\n", close);
   ENTER (0, 0) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
     if (close_state == STREAM_UNINITIALIZED)
       error ("Doesn't have any connection.\n");
 #endif
@@ -1678,7 +1678,7 @@ protected void update_internal_state (void|int assume_real_backend)
     stream->set_write_callback (install_write_cb && !got_extra_read_call_out &&
 				ssl_write_callback);
 
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
     if (!assume_real_backend && op_thread)
       // Check that we haven't installed callbacks that might start
       // executing in parallell in another thread. That's legitimate
@@ -1790,7 +1790,7 @@ protected int ssl_read_callback (int called_from_real_backend, string input)
       string|int data =
 	close_state == ABRUPT_CLOSE ? -1 : conn->got_data (input);
 
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
       if (got_extra_read_call_out)
 	error ("Got to real read callback with queued extra read call out.\n");
 #endif
@@ -1806,7 +1806,7 @@ protected int ssl_read_callback (int called_from_real_backend, string input)
 	int write_res;
 	if (stringp(data) || (data > 0) ||
 	    ((data < 0) && !conn->handshake_finished)) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
 	  if (!stream)
 	    error ("Got zapped stream in callback.\n");
 #endif
@@ -1822,7 +1822,7 @@ protected int ssl_read_callback (int called_from_real_backend, string input)
 	    SSL3_DEBUG_MSG ("ssl_read_callback: Handshake finished\n");
 	    update_internal_state();
 	    if (called_from_real_backend && accept_callback) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
 	      if (close_state >= NORMAL_CLOSE)
 		error ("Didn't expect the connection to be "
 		       "explicitly closed already.\n");
@@ -1894,7 +1894,7 @@ protected int ssl_read_callback (int called_from_real_backend, string input)
 
     if (alert_cb_called || call_accept_cb + call_read_cb + do_close_stuff > 1) {
       // Need to do a call out to ourselves; see comment above.
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
       if (!alert_cb_called && !called_from_real_backend)
 	error ("Internal confusion.\n");
       if (called_from_real_backend && got_extra_read_call_out < 0)
@@ -1943,7 +1943,7 @@ protected int ssl_read_callback (int called_from_real_backend, string input)
     }
 
     else if (do_close_stuff) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
       if (got_extra_read_call_out)
 	error ("Shouldn't have more to do after close stuff.\n");
 #endif
@@ -2013,7 +2013,7 @@ protected int ssl_write_callback (int called_from_real_backend)
   int ret = 0;
 
   ENTER (1, called_from_real_backend) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
     if (!stream)
       error ("Got zapped stream in callback.\n");
     if (got_extra_read_call_out)
@@ -2135,7 +2135,7 @@ protected int ssl_write_callback (int called_from_real_backend)
 
       if (int err = queue_write()) {
 	if (err > 0) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
 	  if (!conn->closing || close_packet_send_state < CLOSE_PACKET_QUEUED_OR_DONE)
 	    error ("Expected a close to be sent or received\n");
 #endif
@@ -2144,7 +2144,7 @@ protected int ssl_write_callback (int called_from_real_backend)
 	    SSL3_DEBUG_MSG ("ssl_write_callback: "
 			    "Close packet queued but not yet sent\n");
 	  else {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
 	    if (!(conn->closing & 1))
 	      error ("Expected a close packet to be queued or sent.\n");
 #endif
@@ -2210,7 +2210,7 @@ protected int ssl_write_callback (int called_from_real_backend)
 
     if (close_state >= NORMAL_CLOSE &&
 	(close_packet_send_state >= CLOSE_PACKET_QUEUED_OR_DONE || cb_errno)) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
       if (close_packet_send_state == CLOSE_PACKET_MAYBE_IGNORED_WRITE_ERROR)
 	error ("Unexpected close_packet_send_state\n");
 #endif
@@ -2234,7 +2234,7 @@ protected int ssl_close_callback (int called_from_real_backend)
 		  close_packet_send_state + ")" : "");
 
   ENTER (1, called_from_real_backend) {
-#ifdef DEBUG
+#ifdef SSLFILE_DEBUG
     if (!stream)
       error ("Got zapped stream in callback.\n");
     if (got_extra_read_call_out)
diff --git a/lib/modules/Sql.pmod/pgsql.h b/lib/modules/Sql.pmod/pgsql.h
index cf506f48a6f41cb1fc661f6a6fffd02c5ad76047..2699361c10a05631ac38255a254d0e549ea6c180 100644
--- a/lib/modules/Sql.pmod/pgsql.h
+++ b/lib/modules/Sql.pmod/pgsql.h
@@ -42,7 +42,7 @@
 #define MARKERROR	     ">"">"">"">"     // foldeditors from recognising
 #define MARKEND		     "\n}""}"	      // it as a fold
 
-#ifdef DEBUG
+#ifdef PG_DEBUG
 #define PD(X ...)     werror(X)
 #define UNBUFFEREDIO  1		    // Make all IO unbuffered
 #else
diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike
index 85905c132608172c46d7bccd1805d1127ca6dc30..c5bfd44b24921aa41479aa884ac4776c5e646c7a 100644
--- a/lib/modules/Sql.pmod/pgsql.pike
+++ b/lib/modules/Sql.pmod/pgsql.pike
@@ -616,9 +616,9 @@ private void phasedreconnect()
 
 final int _decodemsg(void|state waitforstate)
 {
-#ifdef DEBUG
+#ifdef PG_DEBUG
   { array line;
-#ifdef DEBUGMORE
+#ifdef PG_DEBUGMORE
     line=backtrace();
 #endif
     PD("Waiting for state %O %O\n",waitforstate,line&&line[sizeof(line)-2]);
@@ -797,7 +797,7 @@ final int _decodemsg(void|state waitforstate)
 	msglen-=4+2+4*cols;
 	foreach(a=allocate(cols);int i;)
 	  a[i]=_c.getint32();
-#ifdef DEBUGMORE
+#ifdef PG_DEBUGMORE
 	PD("%O\n",a);
 #endif
 	if(_c.portal)
@@ -825,7 +825,7 @@ final int _decodemsg(void|state waitforstate)
 	  res->formatcode=_c.getint16();	// Currently broken in Postgres
 	  a[i]=res;
 	}
-#ifdef DEBUGMORE
+#ifdef PG_DEBUGMORE
 	PD("%O\n",a);
 #endif
 	if(_c.portal)
@@ -1617,7 +1617,7 @@ final private void sendclose(void|int hold)
   { _c.portal->_portalname = UNDEFINED;
     _c.setportal();
     portalsinflight--;
-#ifdef DEBUGMORE
+#ifdef PG_DEBUGMORE
     PD("Closetrace %O\n",backtrace());
 #endif
     if(!sizeof(portalname))
@@ -2014,7 +2014,7 @@ object big_query(string q,void|mapping(string|int:mixed) bindings,
           plugbuf[1]=_c.plugint32(len);
           PD("Bind portal %s statement %s\n",portalname,preparedname);
           _c.sendcmd(plugbuf);
-#ifdef   DEBUGMORE
+#ifdef   PG_DEBUGMORE
           PD("%O\n",plugbuf);
 #endif
         }
diff --git a/lib/modules/Sql.pmod/pgsql_util.pmod b/lib/modules/Sql.pmod/pgsql_util.pmod
index f9e6cd27fe713affeea0c337f2f4bb964b3820b9..d8d920e0e41003d264e5ab8fc3d7f95cef72fd7d 100644
--- a/lib/modules/Sql.pmod/pgsql_util.pmod
+++ b/lib/modules/Sql.pmod/pgsql_util.pmod
@@ -460,7 +460,7 @@ array(mixed) fetch_row(void|int|string|array(string) buffer)
 	_pgsqlsess._decodemsg();	      // Flush previous portal sequence
       for(;;)
       {
-#ifdef DEBUGMORE
+#ifdef PG_DEBUGMORE
 	PD("buffer: %d	nextportal: %d	lock: %d\n",
 	 buffer,_pgsqlsess._nextportal,!!_qmtxkey);
 #endif