title: How to print sql query from Django as Debug is False
body: <p>From doc <a href="https://docs.djangoproject.com/en/3.2/faq/models/" rel="nofollow noreferrer">how can I see the raw SQL queries Django is running?</a></p>
  <p>I can get sql executed by:</p>
  <pre><code>from django.db import connection
  connection.queries
  </code></pre>
  <p>But it's only available while <code>Debug == True</code></p>
  <p>How to print sql as <code>Debug == False</code>?</p>
  <p>Thanks</p>
  <blockquote>
  <p>Update</p>
  </blockquote>
  <p>I want something like this:</p>
  <pre><code>from django.db import connection
  from django.db import reset_queries
  
  reset_queries()  # Clears the query.
  with transaction.atomic():
      r = Amodel.objects.create(
          ...
      )
  
      Bmodel.objects.filter(id__in=handle_ids_).update(status=4)
  
  # Prints the sql executed in this transaction block.
  logger.info(&quot;[sql_execute]: {}&quot;.format(connection.queries))
  
  
  </code></pre>