View a markdown version of this page

Supported system variables - Amazon Aurora

Supported system variables

Through the routing endpoint of a database cluster group for Aurora, a session's system variables live in two places. One is the session at the routing endpoint, and the other is a member session on each member cluster that the session reaches. When you set or read a variable at the routing endpoint, the routing layer holds it, forwards it to the member sessions, or answers the read itself. For the session variables that the routing layer reads itself, see Routing layer session variables.

Session variables the routing layer holds and forwards

The routing layer applies your session settings to each member session before routed statements run there. The routing layer, not a member cluster, answers a table-less read of a variable from the session state that it tracks. To confirm the value that a member cluster uses, read the variable inside a routed statement, or on the member cluster directly.

Each member cluster keeps its own parameter groups, and group membership doesn't change them. Change global values in each member cluster's parameter group, as described in Parameter groups for Amazon Aurora, and keep them the same across the group. Through the routing endpoint, the routing layer sets sql_mode, time_zone, autocommit, transaction_isolation, auto_increment_increment, character set, and the session timeouts wait_timeout, interactive_timeout, and net_write_timeout on every member session. Member cluster parameter group values for these settings don't apply to routed sessions. The default sql_mode is empty, so routed writes aren't strict: an out-of-range number is stored as the column's limit, and an over-long string is cut, each with a warning. For more information, see Auditing member cluster configuration.

Routing endpoint parameters and session settings

The group's routing endpoint parameters, which you set with the Amazon RDS API, have one value for the whole group and no value for each user or session. They don't change member cluster parameters. On Aurora MySQL, the routing endpoint parameters sql_mode, autocommit, time_zone, and transaction_isolation set the starting value of these variables for every new session, and the routing layer applies them to each member session. A SET in the session overrides them. To give a session its own values, send SET statements after you connect, or in the connection initialization command of your connection pool. For the parameters, see Configuring the routing endpoint.

The routing layer applies your session settings to each member session, and answers some reads itself.

The routing layer buffers your session SET statements and replays them on each member session. The routing layer answers a table-less read, such as SELECT @@max_allowed_packet, and SHOW VARIABLES from the session state that it tracks. The following table shows how each kind of variable behaves.

Kind Variables Table-less read at the routing endpoint
Buffered by the routing layer and replayed on each member session Every session variable that the session sets, such as SET NAMES with a utf8mb4 character set, autocommit, sql_mode, time_zone, transaction_isolation, wait_timeout, innodb_lock_wait_timeout, and optimizer_switch, and user variables The session value that the routing layer tracks. SHOW SESSION VARIABLES lists it
The routing layer's own value version, version_comment, max_connections, lower_case_table_names, performance_schema, and the other variables listed after this table The routing layer's value, which can differ from the member clusters'
Not set by the session Any other variable that the session doesn't set. Each member cluster's own value applies to routed statements NULL. Read the variable inside a routed statement.

On Aurora MySQL, a new session at the routing endpoint starts with the values in the following table. The member clusters' own values for these variables don't apply to routed statements.

Variable Starting value Set by a routing endpoint parameter
autocommit 1 Yes
transaction_isolation REPEATABLE-READ Yes
sql_mode '' (empty) Yes
time_zone +00:00 Yes
auto_increment_increment 1 No
sql_auto_is_null 0 No
completion_type NO_CHAIN No
wait_timeout 28800 No
interactive_timeout 28800 No
net_write_timeout 60 No

When you set the routing endpoint parameter for autocommit, transaction_isolation, sql_mode, or time_zone, a new session starts with that value instead. A change to those parameters applies to new connections. Connections that are already open keep their values. A direct connection to a member cluster uses that member cluster's values, so set the member clusters to match if routed and direct connections must agree. If your application needs other values, set them with SET SESSION on each connection, for example in your driver's session initialization. The routing layer replays the session timeouts that you set, such as wait_timeout and net_write_timeout, on the member sessions, and each member cluster enforces them.

On Aurora MySQL, the routing layer learns about a variable change from the member cluster's reply to a successful statement. If a statement, such as a CALL of a stored procedure, changes a session variable or a user variable and then fails with an error, the routing layer doesn't record that change, so a later read of the variable at the routing endpoint can return the earlier value. After such a failure, set the variables again, or reconnect.

The routing layer replays every session variable that the session sets, not only the ones in the preceding tables. For example, innodb_lock_wait_timeout, optimizer_switch, lock_wait_timeout, and max_execution_time reach each member session that the session uses, and each member cluster enforces them.

On Aurora MySQL, a read of the following variables at the routing endpoint, with @@ or @@GLOBAL., returns the routing layer's own value, not a member cluster's. To read a member cluster's value, read the variable inside a routed statement, in a pinned session, or on the member cluster directly.

  • version and innodb_version return the MySQL version part of the group's minimum engine version. For more information, see Limitations and considerations for database cluster groups for Aurora.

  • max_connections returns a fixed value of 35000, which isn't the connection limit of your group or of a member cluster.

  • lower_case_table_names, performance_schema, read_only, and innodb_read_only return 0, whatever the member clusters' parameter groups set.

  • version_comment, system_time_zone, init_connect, license, socket, character_set_system, hostname, and port return the routing layer's values.

A SELECT @@GLOBAL.variable of autocommit, sql_mode, time_zone, or transaction_isolation returns the value that the session started with. A table-less SELECT @@GLOBAL.variable of a variable that is neither one of these four nor in the preceding list returns error 1235. Read such a variable on the member cluster.

The following table gives a short usage note for the variables that drivers and applications commonly set or read.

Variable or statement At the routing endpoint Usage note
autocommit Tracked by the routing layer With autocommit = 0, the first statement starts a transaction.
SET NAMES, character_set_*, collation_* Buffered and replayed The utf8mb4 character set family only. See Character sets and collations.
sql_mode Buffered and replayed If the session doesn't set sql_mode, the group's sql_mode routing endpoint parameter applies; its default is an empty value, not the member cluster's sql_mode parameter. Set sql_mode in the routing endpoint parameters or in each session, for example to STRICT_TRANS_TABLES.
time_zone Buffered and replayed Set time_zone in each session or in the connection string, so routed and direct connections convert date and time values alike.
SET TRANSACTION ISOLATION LEVEL Applies to the next transaction A transaction through the routing layer runs on one member cluster and offers every isolation level of the engine. Set the level for each transaction with SET TRANSACTION ISOLATION LEVEL before BEGIN. After BEGIN, the statement returns error 1568.
max_execution_time Member cluster enforces it Set it at the start of the session, and the member cluster stops a statement that runs longer.
version Routing layer's own value Returns the MySQL version part of the group's minimum engine version, not each member cluster's. Read each member cluster's EngineVersion from describe-db-clusters.
lower_case_table_names Routing layer's own value Returns 0. The routing layer matches router names in exact letter case and rewrites them to cluster names without changing their case.
max_allowed_packet Routing layer's session state Returns 16777216, the routing layer's value, not the member clusters'. A driver that reads it at connection time gets this answer. As on MySQL, SET SESSION max_allowed_packet returns error 1621.
router_cluster_pin, scaleout_tables_preferred_member Routing layer See Routing layer session variables.

When the session doesn't set time_zone, routed statements use +00:00, or the group's time_zone routing endpoint parameter when you set one. SET SESSION TRANSACTION ISOLATION LEVEL sets transaction_isolation for the session, and the routing layer replays it on every member session that the session reaches.

Statements that change variables

The following cases describe what happens when a statement changes a variable.

  • Per-user defaults. A per-user default isn't available. To give a client its own session values, send the SET statements in its connection initialization command.

  • Global values. The routing layer refuses SET GLOBAL of an engine variable, and assignments to @@GLOBAL., @@PERSIST., and @@PERSIST_ONLY. variables, with error 1235. SET PERSIST and SET PERSIST_ONLY return syntax error 1064. Each member cluster keeps its own parameter groups. Change global values on each member cluster, and keep them the same across the group.

  • SET NAMES with other assignments. You can combine SET NAMES or SET CHARACTER SET with other assignments in one SET statement.

  • Roles. The routing endpoint doesn't support SET ROLE, which returns ERROR 1235 (42000): This statement type is not supported, or SET DEFAULT ROLE, which returns syntax error 1064.

  • Values that a member cluster rejects. For autocommit, sql_mode, time_zone, the character set variables, and the other variables in the starting values table, the routing layer checks the value itself. An invalid value returns the engine's error on the SET. For other variables, the routing layer accepts the SET without sending it, and sends it to the member cluster with the next routed statement. This also applies inside a transaction until its first routed statement. If the member cluster rejects it, for example for an unknown variable name or a value of the wrong type, that statement and every later routed statement return the member cluster's error until you reset the connection (COM_RESET_CONNECTION) or reconnect. In a transaction that already runs on a member cluster, under LOCK TABLES, or in a pinned session, the routing layer sends the SET right away, and the error comes back on the SET. Check a new SET with a routed read, such as a SELECT on one of your tables, before you rely on it.

Examples

The following table-less read returns the routing layer's answer, not the member cluster's.

SELECT @@max_allowed_packet;

The routing layer routes the following read to the member cluster that holds app.orders, so the member cluster evaluates the variable.

SELECT @@sql_mode, id FROM app.orders WHERE id = 1;

The following statements set the time zone for the session, and the isolation level for the next transaction.

SET time_zone = '+00:00'; SET TRANSACTION ISOLATION LEVEL READ COMMITTED; BEGIN;