Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-30 · container image postgres:17
idle_in_transaction_session_timeout ends any session that has started a transaction and then sends nothing for longer than the limit. The error arrives as FATAL on the next statement, the connection is closed, and the open transaction is rolled back.
In the test the limit was 1 second, the session ran BEGIN and an UPDATE, waited 2 seconds, and then sent COMMIT.
01BEGIN, UPDATE, then waiting before COMMIT
Session A set the limit to 1s, ran BEGIN and UPDATE stock SET qty = qty - 1, and then did nothing while session B slept for 2 seconds. When A sent COMMIT, it got FATAL: 25P03 and psql reported that the connection was lost.
The UPDATE was not saved: qty was still 100. With COMMIT right after the UPDATE, the same 2-second wait did no harm, and the next query in session A showed qty 99.
Setup
CREATE TABLE stock (item_id int PRIMARY KEY, qty int);
INSERT INTO stock VALUES (1, 100);CREATE TABLE
INSERT 0 1SET idle_in_transaction_session_timeout = '1s';
BEGIN;
UPDATE stock SET qty = qty - 1 WHERE item_id = 1;SET
BEGIN
UPDATE 1SELECT pg_sleep(2); pg_sleep
----------
(1 row)COMMIT;FATAL: 25P03: terminating connection due to idle-in-transaction timeout
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lostSELECT item_id, qty FROM stock; item_id | qty
---------+-----
1 | 100
(1 row)Do slow work (user input, API calls, file processing) outside the transaction, and keep BEGIN ... COMMIT short. The application must also reconnect after this error, because the session is gone.
SET idle_in_transaction_session_timeout = '1s';
BEGIN;
UPDATE stock SET qty = qty - 1 WHERE item_id = 1;
COMMIT;SET
BEGIN
UPDATE 1
COMMITSELECT pg_sleep(2); pg_sleep
----------
(1 row)SELECT item_id, qty FROM stock; item_id | qty
---------+-----
1 | 99
(1 row)FAQ
What does terminating connection due to idle-in-transaction timeout mean?
Your session opened a transaction and then sent nothing for longer than idle_in_transaction_session_timeout. The server closed the session and rolled back that transaction.
Is my data saved after 25P03?
No. In the test the UPDATE in the timed-out transaction was rolled back (qty stayed 100).
How do I check the current setting?
Run SHOW idle_in_transaction_session_timeout;. In the test it was set for the session with SET idle_in_transaction_session_timeout = '1s';.
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