Transaction traces: Database queries page

In New Relic APM, transaction traces can contain database query data. Use the Database queries page to analyze a slow transaction or change database query collection settings.

Access to this feature depends on your subscription level.

Find Database queries

If database query data is associated with your selected transaction trace, the Database queries page will be visible from the Transaction trace details page.

If you expect to see database data for a transaction trace but don't see it, you may need to change the Database query settings.

APM - Transaction trace - Database queries tab
From rpm.newrelic.com, select APM > (selected app) > Transactions > (selected transaction trace) > Database queries: When you select a transaction trace with associated database query data, you can select the Database queries page to see query details.

Use Database queries

Use the Database queries page to analyze and troubleshoot a slow transaction. For example:

  1. You notice on the APM Overview page that a transaction is abnormally slow.
  2. You select a transaction trace to get more details about that transaction.
  3. If the trace has associated database data, you select the Database queries page to examine the slow queries in the trace, and use them as the basis to troubleshoot and improve your app's performance.

Other functions include:

If you want to... Do this...
View hidden queries

By default, New Relic hides queries that take less than five milliseconds. To view these hidden queries, select the Show fast queries checkbox.

View stack traces

To view stack traces associated with a database query, click the database [database icon] icon (in the table's Total duration column).

Configure database query settings

You can change database query settings in the same way you change other transaction trace settings; for example, via configuring the New Relic agent or, for some agents, via the UI.

Common database query setting changes include:

  • Disabling database query collection
  • Collecting raw query data instead of obfuscated
  • Changing the stack trace threshold
  • Turning on query explain plan collection

Use database queries to improve performance

Here are some tips to improve your app's database performance:

Use database queries Comments
Time Look for queries where the TOTAL DURATION contributes large amounts of time to the overall transaction time. This indicates a good place to try to enhance your database query with an index or some other optimization.
Duplicate queries Look for queries that repeatedly query the same kind of information; for example, multiple queries to look up individual account IDs. Try rewriting the query to INCLUDE the specific values (account IDs 1, 2, 10, 14, 17, etc.) so that a single query can get all the relevant items.
Database overhead

Look at the structure of your queries to see if there are opportunities to combine different types of information into a single call; for example, querying for the account ID, name, etc. This is useful, for example, if your database center is in a different geographical location, because this will reduce overhead.

The amount of time for your database request and response may be very fast. However, by combining requests into fewer calls, you can reduce that time even more.

MySQL

From your app's main APM Overview page, compare the database time on the main chart to other processing time. Sudden spikes or larger amounts of database time compared to other processing times may indicate problems.

Find other slow queries

The Trace details page is useful for examining a specific transaction's details. To see all of your application's slowest queries in one place, use the Slow queries feature.

For more help

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.