Index: django/db/__init__.py
===================================================================
--- django/db/__init__.py	(revision 6702)
+++ django/db/__init__.py	(working copy)
@@ -1,6 +1,6 @@
 import os
 from django.conf import settings
-from django.core import signals
+from django.core import signals as core_signals
 from django.core.exceptions import ImproperlyConfigured
 from django.dispatch import dispatcher
 from django.utils.functional import curry
@@ -54,17 +54,11 @@
 
 # Register an event that closes the database connection
 # when a Django request is finished.
-dispatcher.connect(connection.close, signal=signals.request_finished)
+dispatcher.connect(connection.close, signal=core_signals.request_finished)
 
-# Register an event that resets connection.queries
-# when a Django request is started.
-def reset_queries():
-    connection.queries = []
-dispatcher.connect(reset_queries, signal=signals.request_started)
-
 # Register an event that rolls back the connection
 # when a Django request has an exception.
 def _rollback_on_exception():
     from django.db import transaction
     transaction.rollback_unless_managed()
-dispatcher.connect(_rollback_on_exception, signal=signals.got_request_exception)
+dispatcher.connect(_rollback_on_exception, signal=core_signals.got_request_exception)
Index: django/db/signals.py
===================================================================
--- django/db/signals.py	(revision 0)
+++ django/db/signals.py	(revision 0)
@@ -0,0 +1 @@
+query_execute = object()
Index: django/db/backends/util.py
===================================================================
--- django/db/backends/util.py	(revision 6702)
+++ django/db/backends/util.py	(working copy)
@@ -1,4 +1,6 @@
 import datetime
+from django.db import signals
+from django.dispatch import dispatcher
 import md5
 from time import time
 
@@ -7,7 +9,7 @@
 except ImportError:
     from django.utils import _decimal as decimal    # for Python 2.3
 
-class CursorDebugWrapper(object):
+class CursorSignalWrapper(object):
     def __init__(self, cursor, db):
         self.cursor = cursor
         self.db = db # Instance of a BaseDatabaseWrapper subclass
@@ -18,11 +20,7 @@
             return self.cursor.execute(sql, params)
         finally:
             stop = time()
-            sql = self.db.ops.last_executed_query(self.cursor, sql, params)
-            self.db.queries.append({
-                'sql': sql,
-                'time': "%.3f" % (stop - start),
-            })
+            dispatcher.send(signal=signals.query_execute, sender=self, sql=sql, params=params, time=stop-start)
 
     def executemany(self, sql, param_list):
         start = time()
@@ -30,10 +28,9 @@
             return self.cursor.executemany(sql, param_list)
         finally:
             stop = time()
-            self.db.queries.append({
-                'sql': '%s times: %s' % (len(param_list), sql),
-                'time': "%.3f" % (stop - start),
-            })
+            # XXX: Should this be a special signal that only gets called once for efficiency?
+            for params in param_list:
+                dispatcher.send(signal=signals.query_execute, sender=self, sql=sql, params=params, time=stop-start)
 
     def __getattr__(self, attr):
         if attr in self.__dict__:
@@ -41,6 +38,7 @@
         else:
             return getattr(self.cursor, attr)
 
+
 ###############################################
 # Converters from database (string) to Python #
 ###############################################
Index: django/db/backends/__init__.py
===================================================================
--- django/db/backends/__init__.py	(revision 6702)
+++ django/db/backends/__init__.py	(working copy)
@@ -12,7 +12,6 @@
     ops = None
     def __init__(self, **kwargs):
         self.connection = None
-        self.queries = []
         self.options = kwargs
 
     def _commit(self):
@@ -31,14 +30,10 @@
     def cursor(self):
         from django.conf import settings
         cursor = self._cursor(settings)
-        if settings.DEBUG:
-            return self.make_debug_cursor(cursor)
+        from django.db.backends import util
+        cursor = util.CursorSignalWrapper(cursor, self)
         return cursor
 
-    def make_debug_cursor(self, cursor):
-        from django.db.backends import util
-        return util.CursorDebugWrapper(cursor, self)
-
 class BaseDatabaseFeatures(object):
     allows_group_by_ordinal = True
     allows_unique_and_pk = True
Index: django/core/context_processors.py
===================================================================
--- django/core/context_processors.py	(revision 6702)
+++ django/core/context_processors.py	(working copy)
@@ -33,8 +33,6 @@
     context_extras = {}
     if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
         context_extras['debug'] = True
-        from django.db import connection
-        context_extras['sql_queries'] = connection.queries
     return context_extras
 
 def i18n(request):
Index: tests/modeltests/select_related/models.py
===================================================================
--- tests/modeltests/select_related/models.py	(revision 6702)
+++ tests/modeltests/select_related/models.py	(working copy)
@@ -7,7 +7,8 @@
 the select-related behavior will traverse.
 """
 
-from django.db import models
+from django.db import models, signals
+from django.dispatch import dispatcher
 
 # Who remembers high school biology?
 
@@ -75,14 +76,24 @@
         obj.save()
         parent = obj
 
+class QueryCounter(object):
+    counter = 0
+
+    @staticmethod
+    def add():
+        QueryCounter.counter += 1
+        
+    @staticmethod
+    def clear():
+        QueryCounter.counter = 0
+
+
+def track_query(sender, *args, **kwargs):
+    QueryCounter.add()
+dispatcher.connect(track_query, signal=signals.query_execute, weak=False)
+
 __test__ = {'API_TESTS':"""
 
-# Set up.
-# The test runner sets settings.DEBUG to False, but we want to gather queries
-# so we'll set it to True here and reset it at the end of the test suite.
->>> from django.conf import settings
->>> settings.DEBUG = True
-
 >>> create_tree("Eukaryota Animalia Anthropoda Insecta Diptera Drosophilidae Drosophila melanogaster")
 >>> create_tree("Eukaryota Animalia Chordata Mammalia Primates Hominidae Homo sapiens")
 >>> create_tree("Eukaryota Plantae Magnoliophyta Magnoliopsida Fabales Fabaceae Pisum sativum")
@@ -91,62 +102,59 @@
 >>> from django import db
 
 # Normally, accessing FKs doesn't fill in related objects:
->>> db.reset_queries()
+>>> QueryCounter.clear()
 >>> fly = Species.objects.get(name="melanogaster")
 >>> fly.genus.family.order.klass.phylum.kingdom.domain
 <Domain: Eukaryota>
->>> len(db.connection.queries)
+>>> QueryCounter.counter
 8
 
 # However, a select_related() call will fill in those related objects without any extra queries:
->>> db.reset_queries()
+>>> QueryCounter.clear()
 >>> person = Species.objects.select_related().get(name="sapiens")
 >>> person.genus.family.order.klass.phylum.kingdom.domain
 <Domain: Eukaryota>
->>> len(db.connection.queries)
+>>> QueryCounter.counter
 1
 
 # select_related() also of course applies to entire lists, not just items.
 # Without select_related()
->>> db.reset_queries()
+>>> QueryCounter.clear()
 >>> world = Species.objects.all()
 >>> [o.genus.family for o in world]
 [<Family: Drosophilidae>, <Family: Hominidae>, <Family: Fabaceae>, <Family: Amanitacae>]
->>> len(db.connection.queries)
+>>> QueryCounter.counter
 9
 
 # With select_related():
->>> db.reset_queries()
+>>> QueryCounter.clear()
 >>> world = Species.objects.all().select_related()
 >>> [o.genus.family for o in world]
 [<Family: Drosophilidae>, <Family: Hominidae>, <Family: Fabaceae>, <Family: Amanitacae>]
->>> len(db.connection.queries)
+>>> QueryCounter.counter
 1
 
 # The "depth" argument to select_related() will stop the descent at a particular level:
->>> db.reset_queries()
+>>> QueryCounter.clear()
 >>> pea = Species.objects.select_related(depth=1).get(name="sativum")
 >>> pea.genus.family.order.klass.phylum.kingdom.domain
 <Domain: Eukaryota>
 
 # Notice: one few query than above because of depth=1
->>> len(db.connection.queries)
+>>> QueryCounter.counter
 7
 
->>> db.reset_queries()
+>>> QueryCounter.clear()
 >>> pea = Species.objects.select_related(depth=5).get(name="sativum")
 >>> pea.genus.family.order.klass.phylum.kingdom.domain
 <Domain: Eukaryota>
->>> len(db.connection.queries)
+>>> QueryCounter.counter
 3
 
->>> db.reset_queries()
+>>> QueryCounter.clear()
 >>> world = Species.objects.all().select_related(depth=2)
 >>> [o.genus.family.order for o in world]
 [<Order: Diptera>, <Order: Primates>, <Order: Fabales>, <Order: Agaricales>]
->>> len(db.connection.queries)
+>>> QueryCounter.counter
 5
-
-# Reset DEBUG to where we found it.
->>> settings.DEBUG = False
 """}
