Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x4daB-007I9O-2c for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Sep 2026 12:08:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x4daA-005Lyl-2Y for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Sep 2026 12:08:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3pnU-0054Dv-2h for pgsql-bugs@lists.postgresql.org; Tue, 08 Sep 2026 06:59:13 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x3pnP-00000003X3g-3x6r for pgsql-bugs@lists.postgresql.org; Tue, 08 Sep 2026 06:59:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=a48YWNcQZ5qBZJ76t2MZmknHsRCtEkMoraMJx4V9Xok=; b=6sl92CJr80WPzIBocFCb07wQdm LD5Wv5DQ7Qe/ncOoH4q4V8j3JljWkrOCGy6B8rCuEeizu3MzM+RDesivrMqwY7twi7U+cp59/lv00 EVwXZJzX+QtN/p86OMLLgNiYvGu2LmoPUnnxMiUcwxjNmA7PIuSat50/M1ov+l7R9834Bq4OEEP4r IMDta54Tv3kRcXYoFm2S0Qi//2jxvVFXrPvO/60+EQT/sxRg0mjEIM3naDAwJU+Q3DgTvfwLc3Q4D xyiKWMyspTggnsn9Hr8TtvGYMV6TeJ2jeh01SEcx0G859qwUmxU3r5CMg5cfsKqady6f9WEt8JC3j lEhy+emA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3pnM-00DoZY-36 for pgsql-bugs@lists.postgresql.org; Tue, 08 Sep 2026 06:59:06 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x3pnL-00000001U73-22i9 for pgsql-bugs@lists.postgresql.org; Tue, 08 Sep 2026 06:59:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19680: FK integrity bypassed by session timezone (orphan rows) To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 303677365@qq.com Reply-To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Date: Tue, 08 Sep 2026 06:58:16 +0000 Message-ID: <19680-4ff463d4a8e2b961@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19680 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 18.6 Operating system: x86_64 Description: =20 PG permits creating foreign keys between types whose equality operator is timezone-dependent (timestamp =3D timestamptz, and date =3D timestamptz). T= he RI reverse check (the scan for referencing rows when deleting/updating the PK row) converts the PK value into the FK column's type using the current session's TimeZone. As a result, the same FK constraint answers differently depending on the session's time zone, and a referencing row becomes invisible to the check: CREATE TABLE tzpk(ts timestamp PRIMARY KEY); CREATE TABLE tzfk(id int, tstz timestamptz REFERENCES tzpk(ts)); SET timezone TO 'UTC'; INSERT INTO tzpk VALUES ('2024-06-15 00:00:00'); INSERT INTO tzfk VALUES (1, '2024-06-15 00:00:00'); -- valid reference under UTC SET timezone TO 'Asia/Tokyo'; DELETE FROM tzpk; -- SUCCEEDS =E2=80= =94 no error! SET timezone TO 'UTC'; SELECT count(*) FROM tzfk; -- 1 (orphan row: violates the FK) SELECT EXISTS (SELECT 1 FROM tzpk WHERE tzfk.tstz =3D tzpk.ts) FROM tzfk; = -- false INSERT INTO tzpk VALUES ('2024-06-15 00:00:00'); -- the "deleted" PK can even be re-created Control: under the same time zone, the identical DELETE is correctly rejected (ERROR: update or delete on table "tzpk" violates foreign key constraint). Only the time-zone switch is needed to bypass the constraint. Silent referential-integrity violation with no error, no log, and no way to detect it afterwards except querying across time-zone contexts. Any deployment that (a) has such a cross-type FK and (b) has sessions with differing TimeZone settings (extremely common: connection pools per region, psql defaults vs app-server settings) can accumulate orphans. The FK constraint's guarantee is void for these type pairs.