Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-29 · container image postgres:17
SQLSTATE 57014 means the statement was cancelled. With the message canceling statement due to statement timeout, the cause is the statement_timeout setting: any statement that runs longer is stopped and the transaction is aborted.
The value can come from the session, the role, the database or postgresql.conf. SHOW statement_timeout; shows the value in effect. The three runs below show where the limit came from and how each case was fixed.
01A role-level timeout stops a long report
The DBA ran ALTER ROLE lab_a SET statement_timeout = '1s'. A report that counts 50 million rows failed with 57014. In the session, SHOW statement_timeout returned 1s, and pg_db_role_setting showed {statement_timeout=1s} for lab_a.
For that one job, BEGIN; SET LOCAL statement_timeout = '60s'; ... COMMIT; let the count finish (50000000). After COMMIT, SHOW statement_timeout was 1s again, so the role setting stays in force for everything else.
Setup
ALTER ROLE lab_a SET statement_timeout = '1s';ALTER ROLESELECT count(*) AS n FROM generate_series(1, 50000000);ERROR: 57014: canceling statement due to statement timeoutSHOW statement_timeout; statement_timeout
-------------------
1s
(1 row)SELECT r.rolname, s.setconfig FROM pg_db_role_setting s JOIN pg_roles r ON r.oid = s.setrole WHERE r.rolname = 'lab_a'; rolname | setconfig
---------+------------------------
lab_a | {statement_timeout=1s}
(1 row)SET LOCAL lasts only until the end of the transaction. Use it to give one batch job more time without raising the limit for the whole role.
BEGIN;
SET LOCAL statement_timeout = '60s';
SELECT count(*) AS n FROM generate_series(1, 50000000);
COMMIT;
SHOW statement_timeout;BEGIN
SET
n
----------
50000000
(1 row)
COMMIT
statement_timeout
-------------------
1s
(1 row)02SET statement_timeout = 5 means 5 milliseconds
SET statement_timeout = 5 followed by a 5-million-row count failed with 57014. SHOW statement_timeout returned 5ms: a number without a unit is milliseconds, not seconds.
With SET statement_timeout = '5s', SHOW returned 5s and the count returned 5000000.
SET statement_timeout = 5;
SELECT count(*) AS n FROM generate_series(1, 5000000);SET
ERROR: 57014: canceling statement due to statement timeoutSET statement_timeout = 5;
SHOW statement_timeout;SET
statement_timeout
-------------------
5ms
(1 row)SET statement_timeout = '5s';
SHOW statement_timeout;
SELECT count(*) AS n FROM generate_series(1, 5000000);SET
statement_timeout
-------------------
5s
(1 row)
n
---------
5000000
(1 row)03Slow query with no usable index (Seq Scan)
members has 2 million rows. With a 100ms timeout, WHERE lower(email) = '...' failed with 57014. EXPLAIN showed Parallel Seq Scan on members with the filter on lower(email): every row was read.
After CREATE INDEX members_lower_email_idx ON members (lower(email)), the plan became Index Scan using members_lower_email_idx and the same query returned id 1999999 within the same 100ms limit.
Setup
CREATE TABLE members (id int PRIMARY KEY, email text NOT NULL);
INSERT INTO members SELECT g, 'User' || g || '@Example.com' FROM generate_series(1, 2000000) g;
ANALYZE members;CREATE TABLE
INSERT 0 2000000
ANALYZESET statement_timeout = '100ms';
SELECT id FROM members WHERE lower(email) = 'user1999999@example.com';SET
ERROR: 57014: canceling statement due to statement timeoutEXPLAIN (COSTS OFF) SELECT id FROM members WHERE lower(email) = 'user1999999@example.com'; QUERY PLAN
------------------------------------------------------------------
Gather
Workers Planned: 2
-> Parallel Seq Scan on members
Filter: (lower(email) = 'user1999999@example.com'::text)
(4 rows)CREATE INDEX members_lower_email_idx ON members (lower(email));
ANALYZE members;CREATE INDEX
ANALYZEAn index on email alone does not help a filter on lower(email); the index has to be on the same expression.
SET statement_timeout = '100ms';
EXPLAIN (COSTS OFF) SELECT id FROM members WHERE lower(email) = 'user1999999@example.com';
SELECT id FROM members WHERE lower(email) = 'user1999999@example.com';SET
QUERY PLAN
----------------------------------------------------------------
Index Scan using members_lower_email_idx on members
Index Cond: (lower(email) = 'user1999999@example.com'::text)
(2 rows)
id
---------
1999999
(1 row)FAQ
How do I fix canceling statement due to statement timeout?
Find where the limit comes from with SHOW statement_timeout, then either make the query faster (an index in the third case) or give that job more time with SET LOCAL statement_timeout (first case).
Where is statement_timeout set for my user?
Role settings are in pg_db_role_setting. In the first case it showed {statement_timeout=1s} for lab_a.
Is statement_timeout in seconds or milliseconds?
A bare number is milliseconds. SET statement_timeout = 5 showed 5ms; write '5s' for seconds.
How do I raise the timeout for one query only?
Wrap it in a transaction with SET LOCAL statement_timeout = '60s'. In the first case the setting went back to 1s after COMMIT.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12