This guide explains how to retrieve full SQL query text (beyond 4096 characters) from Performance Insights on AWS RDS for PostgreSQL using the AWS CLI.
- Performance Insights must be enabled on your RDS instance.
- AWS CLI must be installed and configured (
aws configure
). - You must have permissions for
pi:GetResourceMetrics
andpi:GetDimensionKeyDetails
.
- Region:
eu-central-1
- Time range: Last 30 minutes (dynamically calculated using macOS
date
command)
You can get the required DB_ID
by running:
aws rds describe-db-instances \
--region eu-central-1 \
--query "DBInstances[].{DBInstanceIdentifier:DBInstanceIdentifier,Arn:DbiResourceId}" \
--output table
Or find it in the AWS Console:
- Go to Amazon RDS → Databases → [your instance] → Configuration.
- Look for the Performance Insights identifier, e.g.
db-ABCDEFG1234567XYZ
.
This command fetches the top queries over the past 30 minutes:
aws pi get-resource-metrics \
--service-type RDS \
--identifier DB_ID \
--metric-queries '[{
"Metric": "db.load.avg",
"GroupBy": {
"Group": "db.sql"
}
}]' \
--start-time $(date -u -v-30M +%Y-%m-%dT%H:%M:%SZ) \
--end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
--region eu-central-1
"Dimensions": {
"db.sql.id": "37532328C2F2FD4051A9762DC0095B80003D5FEA",
"db.sql.statement": "select workorderi0_.id as id1_142_, ..."
}
Copy the value of "db.sql.id"
for the next step.
Now use the ID from Step 1 to get the full query text:
aws pi get-dimension-key-details \
--service-type RDS \
--identifier DB_ID \
--group db.sql \
--group-identifier "37532328C2F2FD4051A9762DC0095B80003D5FEA" \
--region eu-central-1
You will get the entire original SQL query, without the 4096-character truncation present in the Performance Insights UI.
db.sql.id
is not the same asdb.sql_tokenized.id
— only use the former for retrieving full query text.- Increasing PostgreSQL’s
track_activity_query_size
helps only withpg_stat_activity
and does not affect Performance Insights output size.