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 1wLahI-001sth-1f for pgsql-hackers@arkaria.postgresql.org; Sat, 09 May 2026 05:57:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wLahH-00CNy4-1V for pgsql-hackers@arkaria.postgresql.org; Sat, 09 May 2026 05:57:55 +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 1wLahH-00CNxv-0W for pgsql-hackers@lists.postgresql.org; Sat, 09 May 2026 05:57:55 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wLahE-00000001Lze-451H for pgsql-hackers@postgresql.org; Sat, 09 May 2026 05:57:54 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-82f8b60e54dso2001056b3a.2 for ; Fri, 08 May 2026 22:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778306270; x=1778911070; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=gVesjhjImIdrl5FxTgIj6j6XLTrgphs0XQS1buJXMQg=; b=HnAiCWIzHAFDcl5Vj2jgDSfe9LePWwmXSInRzV0Wq8sHoRXlAlEh0iUhEbPh4envgL n3xLwwsyY2P7XinGb2ygqiFXUSymHw5kJ69olxGvad3frDreKRgq7/hXNVsaH88STDrX jNamlqSTs/JNiu/wvv1cAFPRzJ9+i3bdWtREuHy6nQe19HIHfH39zfO2wYVNPSOX9AIi +XzWWa10WjdFgV2NLRFpTEUPhp6g7SXbEZMjE9+9ttflPSOnxGVh3lhbIgi0Nq2C7TLd J1b7pD4ytNE0GznrgNEKOZMVQa0NCAL0FZ7W1v4J8toryox0Bidae5sZWxWuKra4GaRh NYcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778306270; x=1778911070; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gVesjhjImIdrl5FxTgIj6j6XLTrgphs0XQS1buJXMQg=; b=ZV5sl8Q0+3aGl0okYgz5dKm0903D9zaTs/9mS7LL42qRLFyM0KjL/23aqtLnyWI3n/ MnQ4xhEvlxm04ET0uqdeB4ztrfPgJYnMOV88toGXcUrGrCQBDqnYKLzRTjSZ3i62LX1F dtmoew2lrBU/GTjHdn7XaaIc6IF8Ydb+12L3EmJfWCdGS5vxpXQHdmHYqlZb9xL94mD9 vAdjZHMDDm+qlno+WCqciGd/CaBsbgT+A/f4rw3zRn7zY+4YFBl8DkppL/RLHgSaN6+H Nq/SdvA26yLoDahKd+NwnqsnwhbmxCxWbJf+f6OV49zi9DJHYiNhpt7gSaXMbG5yuM0k xYmw== X-Forwarded-Encrypted: i=1; AFNElJ+IXy700iHaILRtFp3qZhZ2t3mqNLnQ6xCdZ/Lrv9nqllKUuycet0Ck02FZDNqmU9pjRff9w0ASvfvmyOZ+@postgresql.org X-Gm-Message-State: AOJu0YyTCsWoo1/LlKXPhYb3v37O/Ak83AvWkfoi/UPouV0Kvs5Ag/J1 RC9UdFUhtDph6W0XtHj9sqwMcFYQ1zfYBkhNxVAE9vFB1PA3GjLlcQyJ X-Gm-Gg: Acq92OElhL75D1hgY/HOekRw9+iWPUOSJicmJ0FnWcEieG0rqXVufhjDyGrNYV5pzCe NrKiy3fAwdo815HvRCppTsk0n1HUWMG82MflNloskS7C2l2eu7kYdUnxHdoSaa8I0HJQXC32Jqw iBBcqOOil/TeV/4LpuDQONcqipCXA8fVWG4GTGcCsuJLxx/gjQ9eLiTauUqBVOtXRtJopxsLdT/ t1vKnCw48mJGrsrlg84ONNIY2qNDHQgqGhxl9VOaUcma+CmNibxSd3E+82zK4jqmPQoNCjjSpek 7FIQPTnGpAR1p1lm6iibp4mvIO30mdYngC7/m9kkrrganm0s79ej5ly+1HYh4CRq3jmVRHT0CN6 LCVZw4wMRV3hAqmXBqzC/00Fs/OWSZzqFsHeaSrXEahQPy7q93mZMMHt9FGQshIDFrjDDSLWwzt bO+mIM8vtpiGEHTcN2n3ikTI9Bh5va6Zw= X-Received: by 2002:a05:6a00:4b12:b0:824:374a:1407 with SMTP id d2e1a72fcca58-83e3994878bmr1168752b3a.16.1778306270177; Fri, 08 May 2026 22:57:50 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-839679c861esm17717090b3a.30.2026.05.08.22.57.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 May 2026 22:57:49 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Call EndCopyFrom() after initial table sync in logical replication From: Chao Li In-Reply-To: Date: Sat, 9 May 2026 13:57:10 +0800 Cc: Fujii Masao , cca5507 , PostgreSQL-development Content-Transfer-Encoding: quoted-printable Message-Id: <140BF04C-441C-451A-80E7-2C0BD585FBFA@gmail.com> References: To: Shinya Kato X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On May 9, 2026, at 02:05, Shinya Kato wrote: >=20 >=20 >=20 > On Fri, May 8, 2026, 14:10 Chao Li wrote: >=20 > I don=E2=80=99t think this is a serious leak. In this path, pstate and = attnamelist are allocated in CurTransactionContext, and the transaction = is committed immediately after copy_table() finishes, so that memory is = reclaimed at transaction end. Explicitly freeing them would be mostly = for code readability, not to fix a memory leak. So, I am okay to not = free them. >=20 > I agree that no additional memory cleanup is=E3=80=80needed here. >=20 >=20 > While tracing the code, I noticed another issue that is probably more = worth addressing. copy_table() currently does: > ``` > copybuf =3D makeStringInfo(); > ``` >=20 > But copybuf is only used by copy_read_data(), and there it's really = just acting as a small state holder for data, len, and cursor, rather = than as a normal growable StringInfo. That means we do not need to = allocate a StringInfo object or its backing buffer at all. >=20 > It would be cleaner to use a plain StringInfoData and simply = reinitialize or zero it in copy_table(). See the attached diff for the = proposed change. >=20 > David Rowley has made several cleanup changes in this area to prefer = stack-allocated StringInfoData, for example = a63bbc811d41b3567eb37fe2636e660a852dbbf2. This change seems consistent = with that direction. >=20 > Thanks for the suggestion. >=20 > The copybuf change looks worthwhile, but perhaps it=E2=80=99s better = discussed in a separate thread. >=20 Sound fair. Let me post it to a separate thread. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/