

# Logs for database cluster groups for Aurora

Use the logs of a database cluster group for Aurora and of each member cluster to see what a routed statement did and follow it to the member cluster that ran it. A group has three kinds of log: the routing layer's logs, the data movement log, and each member cluster's own engine logs. For auditing, see [Auditing access and member cluster configuration](databaseclustergroups-auditing.md).

## Routing layer logs
<a name="databaseclustergroups-logging-routing-layer"></a>

On Aurora MySQL, the [routing layer](databaseclustergroups-architecture.md) writes an error log, an audit log, and a slow query log, and publishes them to Amazon CloudWatch Logs in your AWS account. Each routing layer task writes its own log stream.
+ **Turning them on.** The error log is always written. Turn on the audit log, the slow query log, or both with the [routing endpoint](databaseclustergroups-connecting.md) parameter `enable_cloudwatch_logs_exports`, which accepts `audit` and `slowquery`. Its default is empty, so both are off by default. For more information, see [Creating, modifying, and deleting a database cluster group for Aurora](databaseclustergroups-group-lifecycle.md).
+ **What they record.** `server_audit_events` (default `CONNECT,QUERY`), `server_audit_incl_users`, and `server_audit_excl_users` select what the audit log records. `long_query_time` (default 10 seconds) sets the slow query threshold.
+ **Where they go.** The log groups are `/aws/rds/cluster-group/{{group-identifier}}/error`, `/audit`, and `/slowquery` in your AWS account. The service creates them before the routing layer starts, whatever the value of `enable_cloudwatch_logs_exports`; the audit and slow query log groups get entries only when you turn those logs on.
+ **Retention.** The service sets no retention on these log groups.

`enable_cloudwatch_logs_exports` controls only the routing layer logs. A routed statement also appears in the log of the member cluster that ran it; see [Member cluster logs](#databaseclustergroups-logging-member-clusters).

**Pinned sessions.** Statements in a [pinned session](databaseclustergroups-sessions.md) aren't in the routing layer's slow query log, and aren't in its audit log except the statement that sets the first pin. For the rest, read the member cluster's logs.

## Data movement log
<a name="databaseclustergroups-logging-data-movement"></a>

Each [data movement job](databaseclustergroups-data-movement.md) writes to the log group `/aws/rds/cluster-group/{{group-identifier}}/data-movement` in your AWS account, which the service creates with the routing layer log groups and with no retention. Each line names the job. The log records:
+ when each phase starts or resumes: `PRECHECKS`, `SEEDING`, `CDC_REPLICATION`, and `CUTOVER`
+ whether a [cutover](databaseclustergroups-sql-switch-job.md) was automatic or manual, and whether it succeeded or fell back to `CDC_REPLICATION`; it doesn't record which user started the cutover, and after an interruption the job can start the cutover again, which the log records as a new start
+ a fatal error, as one `INFO` line without the error text; read the `errors` and `cleanup_status` columns of `move_info` (see [move\_info](databaseclustergroups-sysviews-move-info.md)) for the cause and the cleanup
+ the progress of the current phase once a minute while the job runs, in the same form as `move_info`; `progress_details` names `CDC_REPLICATION` as `CDC`

To follow a job, also read its row in `dbclustergroup_data_movement.move_info` at the routing endpoint and the group's Amazon RDS events. See [Reading move status](databaseclustergroups-running-a-move.md#databaseclustergroups-move-monitoring) and [Amazon RDS events for database cluster groups for Aurora](databaseclustergroups-group-events.md).

## Member cluster logs
<a name="databaseclustergroups-logging-member-clusters"></a>

Each [member cluster](databaseclustergroups-member-clusters.md) keeps the standard logs of its engine and publishes them as any Aurora DB cluster does; see [Monitoring Amazon Aurora log files](USER_LogAccess.md). A member cluster doesn't take its log export setting from the group, so set each member cluster's log parameters and log export yourself, with the same values on every member cluster. Joining a group doesn't change a member cluster's log groups, so existing alerts, dashboards, and integrations keep working.

What a member cluster log shows for a routed statement:
+ The statement appears under the member cluster user that has the same name as the [router user](databaseclustergroups-router-users.md).
+ Objects appear by their cluster names. To map them to router names, use `dbclustergroup_sys.data_mappings` (see [data\_mappings](databaseclustergroups-sysviews-data-mappings.md)).
+ The client's connection attributes, such as `_client_name`, `_client_version`, and `program_name`, don't reach the member cluster. A routed session carries attributes that the routing layer sets, such as `_rds_connection_source`, so a tool that groups load by client application or driver doesn't see routed clients. A direct session carries all of its attributes.

## Tracing a routed statement
<a name="databaseclustergroups-logging-tracing"></a>

Use the tracing identifier to find one routed statement in the routing layer's logs and in the logs of the member cluster that ran it. The routing layer puts a `/* tid={{TRACE_ID}} */` comment on every statement that it sends to a member cluster, and the same identifier starts the statement text in the routing layer's audit and slow query logs. One tracing identifier covers one client query, and all the statements that query sends share it. Statements in a [pinned session](databaseclustergroups-sessions.md), statements that the routing layer [answers itself](databaseclustergroups-router-answers.md), and statements on a direct connection carry no tracing identifier.

To get the tracing identifier in your application, run `SELECT dbclustergroup_trace_id();` at the routing endpoint, in the same session, right after the statement that you want to trace. The function takes no arguments and returns one value: the tracing identifier of the session's previous statement, the same value as that statement's `/* tid=... */` comment on the member cluster. It returns `NULL` when the previous statement had no tracing identifier, which is the case in a pinned session, after a statement that the routing layer answered itself, and for the first statement in a session. Every statement gets its own identifier, including the call to the function, so call it once, immediately after the statement that you want to trace, and record the value with the statement's result.

To follow a routed statement, take the tracing identifier from `dbclustergroup_trace_id()` or from its SQL comment and search for it in the routing layer's audit and slow query log groups and in the log groups of the member cluster that ran it, with one Amazon CloudWatch Logs Insights query. If you don't know which member cluster ran it, search every member cluster's log groups; one query spans at most 50 log groups, so split the search for a large group. To follow a session across the group, see [Tracing a session or statement across the group](databaseclustergroups-trace-session.md). For live session state, see [Routing layer metrics and signals](databaseclustergroups-metrics.md#databaseclustergroups-monitoring-the-router).

## Log structure
<a name="databaseclustergroups-logging-structure"></a>

**Routing layer error log.** Aurora MySQL error log format. Each line has, separated by spaces: the UTC time with microseconds, the connection ID, the severity in brackets, the error code in brackets (`MY-` and six digits), the subsystem `Router` in brackets, and the message. It records failed sign-ins, locked accounts, and expired passwords. It also records connections that end during sign-in, for example after a failed TLS handshake. It doesn't record sessions that end after sign-in.

**Routing layer slow query log.** Aurora MySQL slow query log format. Each record starts with four header lines: the UTC time; the user and client IP address with the connection ID; the timing and row counts; and the statement's start time in epoch seconds. The statement follows, starting with its tracing identifier comment. In Amazon CloudWatch Logs, each record is one log event, split at line boundaries only when it is too large for one event. The query time is measured at the routing layer; the lock time and row counts come from the member cluster. The log has no per-phase timing. The host name is empty, because the routing layer doesn't resolve host names. A statement is written when its time is greater than `long_query_time`. Statements in a pinned session aren't written; use the member cluster's slow query log for those.

**Routing layer audit log.** Aurora MySQL Advanced Auditing format: one line per event, with ten comma-separated fields: the time in epoch microseconds, the server host (the group's identifier), the user (the router user, escaped and cut to 96 bytes), the client IP address, the connection ID, the query ID, the operation (`CONNECT`, `FAILED_CONNECT`, `CHANGEUSER`, `DISCONNECT`, or `QUERY`), the database, the statement (starting with its tracing identifier comment), and the return code. The log writes no `TABLE` events, and `server_audit_events` doesn't accept `TABLE`, because the routing layer doesn't know which tables a statement touches. It doesn't record the statements of a pinned session, except the statement that sets the first pin (see [SET router\_cluster\_pin](databaseclustergroups-sql-set-router-cluster-pin.md)); use the member cluster's audit log for those.

The routing layer delivers its audit log to Amazon CloudWatch Logs asynchronously, so entries appear after a short delay. Every routed statement also appears in the audit log of the member cluster that ran it; see [Auditing access and member cluster configuration](databaseclustergroups-auditing.md). For a complete record of the statements that ran, for example for compliance, use the member cluster audit logs; the routing layer audit log adds client sign-ins and the statements that the routing layer answers itself.

**Statement text in the audit and slow query logs.** Each statement is logged up to 64 KiB (65,536 bytes); a statement that is cut ends in `[Truncated...]`. Prepared statements that use the binary protocol are logged with `?` for each value.

**Data movement log.** Each line has, separated by spaces: the UTC time, the level, the component name `data_movement` in brackets, the job ID in brackets in the form `job_id={{ID}}`, and the message. A progress line has the phase and the job progress, in the same form as `move_info`.