如何在New Relic的APM模块中查看完整数据库查询语句?
Hey there! I’ve dealt with this exact issue before when working with New Relic’s PHP APM, so let me break down the steps to get those full query statements visible:
1. Adjust Your New Relic PHP Agent Configuration
The most common reason you’re only seeing simplified <table name> select entries is because the agent limits SQL recording by default. Here’s how to update it:
- Locate your New Relic PHP agent config file (usually
newrelic.ini, or embedded in your mainphp.inifile) - Find the setting
newrelic.transaction_tracer.record_sqland set it to one of these values:raw: Records the full, unmodified SQL query (note: this includes parameter values, so be cautious with sensitive data like passwords or PII)obfuscated: Keeps the full query structure but replaces sensitive parameter values with placeholders (like?), balancing visibility and security
- Save the config file, then restart your web server (Apache/Nginx) and PHP-FPM (if you’re using it) to apply the changes
2. Check the Individual Query Details Page
Even if the list view shows the simplified query, the full version might already be available in the details view:
- On the Databases page, click on the
<table name> selectentry you want to inspect - In the query details page, look for a section labeled Full SQL or Obfuscated SQL (depending on your config) — this should display the complete query structure
3. Verify Transaction Tracer Settings
Make sure transaction tracing is enabled to capture detailed query data:
- In your agent config, confirm
newrelic.transaction_tracer.enabled = true - Adjust
newrelic.transaction_tracer.thresholdif needed (this sets the minimum duration for a transaction to be traced; setting it to a lower value like0.5ensures more queries are captured)
Once you’ve updated the config and restarted your services, give it a few minutes for New Relic to ingest the new data, and you should start seeing full query statements in either the details view or the main list (depending on your settings).
内容的提问来源于stack exchange,提问作者littleibex

