BUG #19950: pg_terminate_backend rejects a positive bigint timeout as negative

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: imchifan(at)163(dot)com
Subject: BUG #19950: pg_terminate_backend rejects a positive bigint timeout as negative
Date: 2026-11-25 17:34:05
Message-ID: 19950-6fa401d3ca2abf26@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19950
Logged by: Qifan Liu
Email address: imchifan(at)163(dot)com
PostgreSQL version: 19.0
Operating system: Linux/amd64
Description:

Hello,

pg_terminate_backend() accepts a bigint timeout, but values above the signed
32-bit range are narrowed and can be rejected as negative. For example, run
the following as a superuser:

\set ON_ERROR_STOP on

CREATE TEMP TABLE timeout_result (
returned_value boolean,
error_state text,
error_message text
);

DO $do$
DECLARE
result boolean;
BEGIN
BEGIN
result := pg_terminate_backend(2147483647, 2147483648::bigint);
INSERT INTO timeout_result VALUES (result, NULL, NULL);
EXCEPTION WHEN OTHERS THEN
INSERT INTO timeout_result VALUES (NULL, SQLSTATE, SQLERRM);
END;
END
$do$;

SELECT * FROM timeout_result;

This prints:

returned_value | error_state | error_message
----------------+-------------+--------------------------------
| 22003 | "timeout" must not be negative
(1 row)

2147483648 is positive and is within the bigint range declared by the
function's SQL interface, so it must not produce the diagnostic that the
timeout is negative. Since PID 2147483647 is not a PostgreSQL backend PID,
the call should instead report that no signal was sent.

The implementation appears to store the bigint argument in an int before
checking whether it is negative.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2026-11-25 17:38:01 BUG #19951: levenshtein_less_equal returns 0 when exact distance is 1 with a negative cost
Previous Message PG Bug reporting form 2026-11-25 17:30:01 BUG #19949: pg_partition_tree() returns dropped partition from cached OID list