All Products
Search
Document Center

AnalyticDB:How do I set the timeout period of SQL statements?

Last Updated:Feb 27, 2026

AnalyticDB for PostgreSQL terminates any SQL statement that runs longer than the configured timeout. The default timeout is 3 hours. When a statement exceeds this limit, the system cancels it and returns the following error:

ERROR:  canceling statement due to statement timeoutTime: 10801445.540 ms (03:00:01.446)

To change the timeout, set the statement_timeout parameter. The value is in milliseconds. Setting the value to 0 disables the timeout.

The following sections describe three ways to modify statement_timeout, each with a different scope.

Change the timeout for the current session

Run the following SQL statement to set the timeout for the current database session. The setting reverts when the session ends.

SET statement_timeout = 0;

The valid range for SQL-level commands is 0 to 2147483647 milliseconds.

Change the timeout for a specific user

Run the following SQL statement to set a default timeout for a specific database account. All future sessions started by this user inherit the value.

ALTER ROLE <username> SET statement_timeout TO 600000;

Replace <username> with the database account.

Change the timeout at the instance level

Modify the parameter in the AnalyticDB for PostgreSQL console to apply the timeout to all sessions on the instance.

Important

Instance-level changes affect every session. The console accepts a value of 0 (disabled) or a value in the range of 3,600,000 to 86,400,000 milliseconds (1 hour to 24 hours).

  1. Log on to the AnalyticDB for PostgreSQL console.

  2. In the upper-left corner of the console, select a region.

  3. Find the instance that you want to manage and click the instance ID.

  4. In the left-side navigation pane, click Parameters.

  5. Find the statement_timeout parameter and click the edit icon in the Running Value column.

  6. Enter a new value.

  7. Click OK.

  8. Click Submit Changes in the upper-right corner.

  9. In the confirmation dialog, click OK.