Viewing slow query details

The Slow Queries details pane is part of New Relic APM's Databases page. The Slow Queries details pane shows the time the transaction took, the query, and a trace for the query. If slow queries have been recorded, they appear in the Slow Queries section at the bottom of the Databases page.

The agent captures all queries that exceed the transaction trace explain plan threshold. The agent aggregates similar statements together but only keeps the details for the worst of each similar statement. Every minute, the agent sends several samples to the New Relic service. These represent the worst performing query statements during that minute.

Access to this feature depends on your subscription level.

View the Slow Queries page

The Slow Queries feature samples the worst performing database queries on your site. Along with the query, New Relic collects the context and diagnostic information you need to fix your database performance issues. Slow Queries are part of the Databases page.

If slow queries have been recorded, they appear in the Slow Queries section at the bottom of the Databases page. In addition, if your APM agent supports host and instance level details, you can view both the query details and the specific instance where the query was executed

To view information on a slow query:

  1. From the New Relic menu bar, select APM > (selected app) > Monitoring > Databases.
  2. From the Slow Queries table, select any row to view the query details.

If there are no slow queries to report, the Slow Queries table will not be visible.

APM Databases - Slow query trace
APM > (selected app) > Monitoring > Databases > (selected query transaction): Here is an example of the details window for an individual query.

Slow Queries metrics

The Slow Queries list contains the following metrics:

Metric Description
Response time The average response time for the statements sampled.
Sample count The number of slow queries identified in the sample.

Select an individual slow query to view details for that query:

Metric Description
Start time When the stack trace began collecting the data shown.
Max time The maximum time for all similar query statements in the sample.
Action The action or process invoking the query.
Query

The query that is being reported as slow. Depending on your configuration, some parts of the query may be obfuscated.

Stack trace Where in the code the statement was called.

New Relic collects the explain plan whenever possible. In MySQL, New Relic provides a query analysis, which explains what happened in your query and what you might do to speed it up. Other databases display an explain plan.

Defining your query obfuscation preferences

To define your query obfuscation preferences:

  1. From the New Relic menu bar, select APM > (selected app) > Settings > Application.
  2. Select fa-ellipsis-hShow advanced settings (on the right side of the page).
  3. Select your choices in the Transaction tracing settings for slow queries.

For the PHP agent, use the slow_sql setting.

If you use the Java agent with high security mode, see the slow_query_whitelist setting.

Slow query troubleshooting

If you do not see slow queries in the New Relic user interface, make sure:

Access to this feature depends on your subscription level.

Checklist Notes
Is your New Relic account a paid account type?
Is the Slow Query feature is enabled in your agent configuration?

To check your configuration:

  1. From the New Relic menu bar, select Applications > (selected app) > Settings > Application.
  2. Verify that the Slow Query checkbox option is selected.

For the PHP agent, use the slow_sql setting.

If you use the Java agent with high security mode, see the slow_query_whitelist setting.

Is the transaction trace explain plan threshold lower than the execution time of your queries?

To check your threshold:

  1. From the New Relic menu bar, select APM > (selected app) > Settings > Application.
  2. Select fa-ellipsis-hShow advanced settings (on the right side of the page).
  3. Verify the Transaction tracing settings for slow queries.

For more help

Additional documentation resources include:

Join the discussion about New Relic APM in the New Relic Online Technical Community! The Technical Community is a public platform to discuss and troubleshoot your New Relic toolset.

If you need additional help, get support at support.newrelic.com.