Tracing a session or statement across the group
After you collect the facts in Before you start: what to collect, trace an affected session to the member cluster and instance that ran its work. In a database cluster group for Aurora, you troubleshoot a member cluster as you troubleshoot any Aurora DB cluster. The added step links a routed session to the member cluster session behind it. Lock and transaction state is on the writer of the member cluster that holds the rows, and the routing layer doesn't show it. Then use the symptom pages in Troubleshooting database cluster groups for Aurora. If every routed session is stuck, not only one, see Troubleshooting an unreachable member cluster or a stall instead.
Tracing is read-only. Ending a session is a separate step that you choose to run. To find a slow statement, end a statement or a session, or read lock waits, see Troubleshooting slow queries, long-running statements, and lock waits.
The global connection ID
The routing layer gives each client connection a global connection ID. It's a 32-bit identifier that is unique across the group, and it names both the connection and the part of the routing layer that holds it. It's always a positive integer, so a client that stores it in a signed integer field accepts it unchanged. A routed session has at most one member cluster session on each member cluster that it has reached, and later statements to that member cluster reuse it. That member cluster session carries the global connection ID, so you can match the two. You can also start from a /* tid=... */ trace ID, or from a long transaction or lock wait on a member cluster.
At the routing endpoint, SELECT CONNECTION_ID() returns your own session's global connection ID, the same value as the ID column of dbclustergroup_sys.router_processlist. For another session, read the ID from that column. On the member cluster, a session that the routing layer opened carries the following two connection attributes, which you read in performance_schema.session_connect_attrs.
| Attribute | Value |
|---|---|
_rds_connection_source |
The connection source of the session |
_rds_router_connection_id |
The session's global connection ID, which is the ID column of router_processlist |
For a session that the routing layer opened, _rds_connection_source reads ROUTER. The routing layer sets no other value. A direct session has no such attribute.
These attributes require performance_schema to be turned on for each member cluster's instances. To check, run SELECT @@performance_schema on each instance endpoint (direct). It's a static parameter that you set in the DB parameter group, and it takes effect after a restart. For more information, see Parameter groups for Amazon Aurora. If it's turned off, match sessions by user and by the /* tid=... */ comment instead, and note that you can't join a routed session to its member cluster session by ID. Classify sessions by _rds_connection_source, not by host, because a session that the routing layer opened shows a local host. The service's own sessions run as rdsadmin, event_scheduler, and rds_aurora_* users. To run the trace, use a member cluster user with SELECT on performance_schema and the PROCESS privilege.
Tracing a session
Before you begin
-
Make sure that you can reach every instance endpoint of every member cluster. Session and statement views are per instance, and the cluster endpoint reaches only the writer.
-
Use a member cluster user that can read other users' sessions and statements, as described in The global connection ID.
To trace a session across the group
-
At the routing endpoint, read the routed session in the routing layer's process list by its global connection ID. The process list shows the sessions on every part of the routing layer that answers. A part that doesn't answer adds no rows, and the result carries a warning: run
SHOW WARNINGSto see it. If a session that you expect is missing, rely on the member cluster side, which lists every routed session, and don't treat the session as ended. To see the sessions of other router users, you needdbclustergroup_process_admin. -
List every instance of every member cluster. At the routing endpoint, read the whole
dbclustergroup_sys.member_cluster_mappingstable, with no filter. Then, with the AWS CLI, list the instances and instance endpoints of each member cluster withdescribe-db-instances, as for any Aurora DB cluster.# Runs at: AWS CLI, once for each member cluster. aws rds describe-db-instances --regionREGION\ --filters Name=db-cluster-id,Values=MEMBER_CLUSTER_ID\ --query 'DBInstances[].[DBInstanceIdentifier,Endpoint.Address]' --output text -
On each instance endpoint (direct), in one pass, look for the member cluster session that carries the global connection ID. Record when the pass starts and ends, because sessions are short-lived, and rows that you read far apart can come from sessions that never existed at the same time. Label each row with its member cluster and instance, and leave out the row of your own session. A match names the instance and the member cluster session's ID, command, and current statement. If you start from a trace ID, search the statement history instead. If an instance can't be read, continue with the others and note which instances you didn't read. If nothing matches, the session might have ended, or it might not have reached that member cluster.
-
On the instance where you found the session (direct), run the standard flow for the symptom: its statements, its plan, and its waits. Map cluster names back to router names with
dbclustergroup_sys.data_mappings. -
If the session waits or blocks, on the member cluster's writer (direct), build the blocking chain, and match each end to its global connection ID. A blocker with no global connection ID is a direct connection, such as a schema tool. For the statements, see Lock waits and long transactions on a member cluster.
-
Choose what to do from Choosing what to do. To end a session, use the following statements.
Step 1. At the routing endpoint, read the routed session by its global connection ID, which you can also take from your application's log. Get your own session's ID with SELECT CONNECTION_ID(), or another session's from the ID column of router_processlist. Then filter with the number as a literal. An expression in a filter on the system tables is refused: WHERE id = CONNECTION_ID() returns ERROR 1235: Only literal values are allowed. No expressions, subqueries, or variables.
-- Runs at: routing endpoint. Your own session's global connection ID. SELECT CONNECTION_ID(); -- Runs at: routing endpoint. The session, with the ID as a literal, for example 4711. SELECT * FROM dbclustergroup_sys.router_processlist WHERE id =ROUTER_CONNECTION_ID;
Step 3. On each instance endpoint (direct), find the member cluster session by its connection attribute. The attribute value is a string, so quote the ID.
SELECT @@hostname AS instance, t.PROCESSLIST_ID AS member_pid, t.PROCESSLIST_COMMAND AS command, t.PROCESSLIST_TIME AS seconds, LEFT(t.PROCESSLIST_INFO, 200) AS current_sql FROM performance_schema.session_connect_attrs a JOIN performance_schema.threads t ON t.PROCESSLIST_ID = a.PROCESSLIST_ID WHERE a.ATTR_NAME = '_rds_router_connection_id' AND a.ATTR_VALUE = 'ROUTER_CONNECTION_ID';
To list every session on an instance with its connection source and global connection ID, join performance_schema.threads to the connection attributes with a left join. A session with no attributes is a direct connection.
-- Runs at: each instance endpoint (direct). SELECT @@hostname AS instance, t.PROCESSLIST_ID AS member_pid, t.PROCESSLIST_USER AS user, src.ATTR_VALUE AS connection_source, rid.ATTR_VALUE AS router_connection_id, LEFT(t.PROCESSLIST_INFO, 120) AS current_sql FROM performance_schema.threads t LEFT JOIN performance_schema.session_connect_attrs src ON src.PROCESSLIST_ID = t.PROCESSLIST_ID AND src.ATTR_NAME = '_rds_connection_source' LEFT JOIN performance_schema.session_connect_attrs rid ON rid.PROCESSLIST_ID = t.PROCESSLIST_ID AND rid.ATTR_NAME = '_rds_router_connection_id' WHERE t.TYPE = 'FOREGROUND' AND t.PROCESSLIST_ID IS NOT NULL;
For a trace ID, search performance_schema.events_statements_current and performance_schema.events_statements_history on each instance for SQL_TEXT LIKE '/* tid=. The trace comment is only on the member cluster side: TRACE_ID%'router_processlist doesn't show it, and statement digests drop it. One trace ID can cover more than one member cluster statement. A BEGIN, and the session settings that the routing layer replays, share the trace ID of the statement that they come with. For a long transaction, start from the oldest trx_started in information_schema.innodb_trx on each writer.
The first 12 hexadecimal digits of a trace ID are the time that the statement was created, in milliseconds since the Unix epoch, in UTC. To read that time, run the following statement on a member cluster (direct).
-- Runs at: a member cluster (direct). SELECT TIMESTAMP('1970-01-01 00:00:00') + INTERVAL CONV(SUBSTRING('TRACE_ID', 1, 12), 16, 10) DIV 1000 SECOND AS created_utc;
Step 5. On the member cluster's writer (direct), build the blocking chain from performance_schema.data_lock_waits. Join each end to _rds_router_connection_id, and read each ID in router_processlist at the routing endpoint, one literal ID per statement. The chain query is in Lock waits and long transactions on a member cluster.
Step 6. To cancel the running statement or end the session with KILL at the routing endpoint, see A long-running statement or an idle session holds locks.
From a member cluster session back to the routing endpoint. Read the session's _rds_router_connection_id on the member cluster, and then read that ID in router_processlist. Measure transaction age only from trx_started, because the time columns restart with every statement.
For the columns of the routing layer's process list, see Process list table: router_processlist and System tables for database cluster groups for Aurora.
Choosing what to do
The following table maps what the trace found to an action and the page that covers it.
| Finding | Action | Page |
|---|---|---|
| The session runs a slow statement | Tune the statement on that instance, on a direct connection | A query is slow |
| A long transaction holds locks that others wait on | Fix the application so that it commits or rolls back, or end the session | A long-running statement or an idle session holds locks |
| The blocker has no global connection ID | It's a direct connection, such as a schema tool. Handle it on the member cluster | Rolling out schema changes |
| Every routed session is stuck | Find out whether one member cluster or the routing layer causes the stall | Every client stalls or slows down |
Related pages
The following pages cover related tasks and reference.