---
title: "Rails 7.2 brings SQL queries count to template rendering logs"
description:
  "Rails 7.2 simplifies debugging database queries by adding query count
  information to the application logs."
canonical_url: "https://www.bigbinary.com/blog/rails-8-adds-sql-queries-count-to-template-rendering-logs"
markdown_url: "https://www.bigbinary.com/blog/rails-8-adds-sql-queries-count-to-template-rendering-logs.md"
---

# Rails 7.2 brings SQL queries count to template rendering logs

Rails 7.2 simplifies debugging database queries by adding query count
information to the application logs.

- Author: Navaneeth D
- Published: August 20, 2024
- Categories: Rails, Rails 7.2

For Rails developers, debugging database queries is a frequent task. Whether
it's addressing the notorious N+1 query problem or fine-tuning caching
strategies, developers often find themselves diving into logs to scrutinize SQL
query counts.

Traditionally, this involved manually inspecting the logs and counting the
number of queries. Needless to say, this becomes tedious and error-prone for
actions generating a significant number of queries in the order of tens or
hundreds.

Thankfully, Rails 7.2 introduces a helpful improvement by enhancing the log
output to include the query count alongside existing information.

![sql-query-count-in-template-log](https://www.bigbinary.com/blog/images/images_used_in_blog/2024/rails-8-adds-sql-queries-count-to-template-rendering-logs/sql-query-count-in-template-log.gif)

The improved log output now includes the query count within the ActiveRecord
section. It shows `3 queries, 1 cached`, indicating that three database queries
were executed, with one being served from the cache.

This seemingly small addition allows for quick identification of query volume
and potential optimization areas. You can easily see if caching is working
effectively and if the number of queries aligns with expectations, saving
developers valuable time and effort.

Check [this pull request](https://github.com/rails/rails/pull/51457) for more
details:

## Links

- [Human page](https://www.bigbinary.com/blog/rails-8-adds-sql-queries-count-to-template-rendering-logs)
