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 1wwAsH-001nr7-1N for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Aug 2026 03:52:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wwAsF-00DT0h-0R for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Aug 2026 03:52:28 +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 1wwAsE-00DT0Z-2i for pgsql-hackers@lists.postgresql.org; Tue, 18 Aug 2026 03:52:27 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wwAsD-00000001K0t-0vEh for pgsql-hackers@postgresql.org; Tue, 18 Aug 2026 03:52:27 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-38e07ebd263so2883074a91.1 for ; Mon, 17 Aug 2026 20:52:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787025143; x=1787629943; darn=postgresql.org; h=to:date:message-id:subject:mime-version:content-type:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=GX/RgjEDQooTLpSg2TgWY9lgCzE/dzMp1vTuMaxo2qA=; b=GjTU42CgAhexmGve1N8YLuzPVJLxFD1JtfpEd2scSbvPmHgfCUfHrDskezu3xwFb86 YS4eBjmqh5h/4EFKkEhIOOL9/m/NOQOBPeW0JM0CJwZV6RBftWKPmEBgxO77Rmg27cyQ VlXjWqBqFwrAtwyxpP394zzaLkP4bALn/YAsOgov+x8H/yLcIqMPb0EtZ7zj4ECzeW7P KJwG232fG8gxXnyQfr4fD++aWBOVZM3Di5jApM3ijnYJXXpr+q6t5jCoxYpSzLciYnag sEDGk4c+yrVnSPhVGMm3zg9LcM9zma/uzlcAhNV8gzf7sczzdajgGbgo+V1Y3tVMdyBC 5Apg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787025143; x=1787629943; h=to:date:message-id:subject:mime-version:content-type:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GX/RgjEDQooTLpSg2TgWY9lgCzE/dzMp1vTuMaxo2qA=; b=UcelQuHWAsPYHrzxF3TdpnI4UgFuq204aUO/tEIqk4/xVXNQ6BT18w+nKIC7ExkoN2 t446RmLNrtjoqzQAWnhgydIUJ7IVzCsn7j3DT2XBqGY9t1CHMGLOsYTYI5/sZg2Yj2nk uH2D26dMwEszwXGamhSAx9g5WdH9EcAP1ssjPts86UW3vAqX5NXN3m+qCrmw1mfMB8LT l426u4zF8we+yLVruSrrrJVgkEXA+yGYRXyn5m+tfKuFTXed5l30Vg+JNDc4N1Xl8wSK 3Tl9mo92sDq01PwKUp24xM0aJWhGtim3glngha21GX2AzXOCSLV/nmjJ3kSPimducIv2 4DaA== X-Gm-Message-State: AOJu0YyZGxKAKcFZUkG/HLGvmCDvxI7Jt5t5stZlGu7DvOnGhGtPVY1L OPc67c+L6My2vTT+LYcJmnd8yv4Bn8LJJDpX6A9PIkax+pwYUI1o6aAck13uoQ== X-Gm-Gg: AR+sD105nL0vL5Hp4mR5l1n2aT9HnClQ80e4thYHTxWUA5oayYH1MI4uw9gcFXqK14L TxKgWQrSiaR64VgoSHXXx3gUAlr4xZi+OEmyr59RMM2ama8lW7SWWDajxLEGuNBOZKrbz0dSheB uKVifdqkpBLeqj9/eZG2LcuJZTnRJSfJwBTm4JYL+NsySeMWfCcIAb+nXQ558U9Df/S86rihDPz QQqB+Mqm1g0jmRxZ8qOQ2vUq3uL2tKx5Fg3FyVWZdEbSpg9+ksv6AjcYwug7dFSdILSbF4yhpdI AzPssvtIz7fU+xvSnwC8AlfYbSjxRYv7FUxu33ZyKQrtL48kj8Hj5a+Omu+vFq4w8fnzxon0euU evgPuWyjiC7d8QxV+1Sugx9iiNqynSNhhRvK+0GWX88d2hlyWbQHT7o2TINPtrAd4Cro8t1+W3c cp9MSCyKQL+3UxiQydtqQhZb40GFzk4KPmjeX5lluXHiqDQ1uc6Lt3+RiXw5C23b7Qwj5j8A== X-Received: by 2002:a17:90b:224e:b0:38e:6a44:671b with SMTP id 98e67ed59e1d1-3933b506db9mr25950047a91.0.1787025143381; Mon, 17 Aug 2026 20:52:23 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.125]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39531fba7e8sm6856983a91.11.2026.08.17.20.52.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Aug 2026 20:52:22 -0700 (PDT) From: Chao Li Content-Type: multipart/mixed; boundary="Apple-Mail=_5EBE4929-EA2A-497D-A0B0-09EACF1939AE" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Fix a relcache reference leak in reorderbuffer.c Message-Id: <7DD65D03-3B5A-43B2-99AD-8E6AF5372BAB@gmail.com> Date: Tue, 18 Aug 2026 11:51:48 +0800 To: PostgreSQL-development X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_5EBE4929-EA2A-497D-A0B0-09EACF1939AE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, While working on a feature patch that I=E2=80=99m going to post soon, I = noticed a small issue in reorderbuffer.c. In the = REORDER_BUFFER_CHANGE_TRUNCATE branch of ReorderBufferProcessTXN(), some = opened relations might be skipped without being closed, leading to = leaked relcache references. The relevant code is: ``` relations =3D palloc0_array(Relation, nrelids); for (i =3D 0; i < nrelids; i++) { Oid relid =3D = change->data.truncate.relids[i]; Relation rel; rel =3D RelationIdGetRelation(relid); if (!RelationIsValid(rel)) elog(ERROR, "could not open = relation with OID %u", relid); if (!RelationIsLogicallyLogged(rel)) continue; <=3D=3D=3D=3D=3D it = should close rel before skipping it relations[nrelations++] =3D rel; } /* Apply the truncate. */ ReorderBufferApplyTruncate(rb, txn, nrelations, = relations, change, = streaming); for (i =3D 0; i < nrelations; i++) RelationClose(relations[i]); ``` In the loop, each relation that is appended to relations is closed after = the loop. However, when RelationIsLogicallyLogged(rel) returns false, = the relation is skipped without being closed, causing the leak. The attached patch makes a small fix to close the relation before = continuing. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_5EBE4929-EA2A-497D-A0B0-09EACF1939AE Content-Disposition: attachment; filename=v1-0001-Fix-relcache-reference-leak-when-decoding-TRUNCAT.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0001-Fix-relcache-reference-leak-when-decoding-TRUNCAT.patch" Content-Transfer-Encoding: quoted-printable =46rom=2030a53ee7a12f42181615a61e625596f6dd00014c=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Tue,=2018=20Aug=202026=2011:37:54=20+0800=0ASubject:=20[PATCH=20= v1]=20Fix=20relcache=20reference=20leak=20when=20decoding=20TRUNCATE=0A=0A= ReorderBufferProcessTXN()=20opens=20every=20relation=20referenced=20by=20= a=0ATRUNCATE=20change.=20When=20RelationIsLogicallyLogged()=20returns=20= false,=0Ait=20skips=20the=20relation=20without=20releasing=20the=20= reference=20acquired=0Aby=20RelationIdGetRelation().=0A=0AClose=20the=20= relation=20before=20continuing.=0A=0AAuthor:=20Chao=20Li=20= =0A---=0A=20= src/backend/replication/logical/reorderbuffer.c=20|=203=20+++=0A=201=20= file=20changed,=203=20insertions(+)=0A=0Adiff=20--git=20= a/src/backend/replication/logical/reorderbuffer.c=20= b/src/backend/replication/logical/reorderbuffer.c=0Aindex=20= 6aed6346366..b34ec5f2145=20100644=0A---=20= a/src/backend/replication/logical/reorderbuffer.c=0A+++=20= b/src/backend/replication/logical/reorderbuffer.c=0A@@=20-2492,7=20= +2492,10=20@@=20ReorderBufferProcessTXN(ReorderBuffer=20*rb,=20= ReorderBufferTXN=20*txn,=0A=20=09=09=09=09=09=09=09=09elog(ERROR,=20= "could=20not=20open=20relation=20with=20OID=20%u",=20relid);=0A=20=0A=20=09= =09=09=09=09=09=09if=20(!RelationIsLogicallyLogged(rel))=0A+=09=09=09=09=09= =09=09{=0A+=09=09=09=09=09=09=09=09RelationClose(rel);=0A=20=09=09=09=09=09= =09=09=09continue;=0A+=09=09=09=09=09=09=09}=0A=20=0A=20=09=09=09=09=09=09= =09relations[nrelations++]=20=3D=20rel;=0A=20=09=09=09=09=09=09}=0A--=20=0A= 2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_5EBE4929-EA2A-497D-A0B0-09EACF1939AE--