PostgreSQL 17.12Lab-verified · 2026-11-30

PostgreSQL error 25P03: terminating connection due to idle-in-transaction timeout

A transaction stayed open and idle longer than idle_in_transaction_session_timeout, so the server ended the session.

PostgreSQL 17.12
25P03: terminating connection due to idle-in-transaction timeout

Jump to a cause

  1. 01BEGIN, UPDATE, then waiting before COMMIT

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
Setuprun as lab_a
CREATE TABLE stock (item_id int PRIMARY KEY, qty int);
INSERT INTO stock VALUES (1, 100);
OUTPUT
CREATE TABLE
INSERT 0 1
Reproduce2 sessions open at the same time (A, B), run in this order
Session Arun as lab_a
SET idle_in_transaction_session_timeout = '1s';
BEGIN;
UPDATE stock SET qty = qty - 1 WHERE item_id = 1;
OUTPUT
SET
BEGIN
UPDATE 1
Session Brun as lab_a
SELECT pg_sleep(2);
OUTPUT
 pg_sleep
----------

(1 row)
Session Arun as lab_a
COMMIT;
OUTPUT
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 lost
Checkrun as lab_a
SELECT item_id, qty FROM stock;
OUTPUT
 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.

After the fix2 sessions open at the same time (A, B), run in this order
Session Arun as lab_a
SET idle_in_transaction_session_timeout = '1s';
BEGIN;
UPDATE stock SET qty = qty - 1 WHERE item_id = 1;
COMMIT;
OUTPUT
SET
BEGIN
UPDATE 1
COMMIT
Session Brun as lab_a
SELECT pg_sleep(2);
OUTPUT
 pg_sleep
----------

(1 row)
Session Arun as lab_a
SELECT item_id, qty FROM stock;
OUTPUT
 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