Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1Z4i-0000bw-46 for pgsql-hackers@arkaria.postgresql.org; Tue, 23 May 2023 20:57:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q1Z4f-0002qU-UH for pgsql-hackers@arkaria.postgresql.org; Tue, 23 May 2023 20:57:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1Z4f-0002qK-Kg for pgsql-hackers@lists.postgresql.org; Tue, 23 May 2023 20:57:41 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q1Z4Z-001jVP-TK for pgsql-hackers@lists.postgresql.org; Tue, 23 May 2023 20:57:40 +0000 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-96fe88cd2fcso12646666b.1 for ; Tue, 23 May 2023 13:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1684875454; x=1687467454; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ebX/rmIUEuN63cUxbp7za9vAa3gby1h0B5NpcZtefWg=; b=Pisd0qhCASrErZt1E7ssdQoFmiMiyytG618pjl944EQVImReNhPD7uq1MfGdyTspgx 6Ox6qUvd8jX0PQ0xCqqBc5LCFvslEz6XA7V1BPKrXZOTQP7EFA/3RV+NAH6eo0UVcaL2 HFlrEKZRbuGSdqd2bqCLTQr234slMTha7L9pLvqS4pIwH6mDcHsb/sNio6H8L8kAuTKN GIMA4ggIXxfCSalxb7FR6sTpC74a++1t/ybgA7Yt2PxroNK3lR6bP1hJYdnJZh41/JBp NmOegGVHEdh+e5x1+170d0AvHY2Jv3J+tr7hi2lhdjIkvwSwFvt4pvYEsD9R12cx2V7D 0p2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684875454; x=1687467454; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ebX/rmIUEuN63cUxbp7za9vAa3gby1h0B5NpcZtefWg=; b=RuY0/b4Q+PJheXlS8be13ZxEOK2Hz+1+f7AHYjiUI5C4KsO/ipOi/LgYTzrkl48yd1 deR//eNNJU9CIxmPHXVHJJhrQWhcws5W0VLQ3vzc6hBwNKKZ5Gg+d/NrtJpRat/LitPz tHE/SdqkNLFu9tT4jEZOj/KSuo7VS0eGaDoNH0wyGcE5nJ0TzJz5jc308aZODOh31ZTo TnbUgEMItVbjRwtx0cphSC5Xx7vkgPh+3jld6a5+U0yu+BVDtH9lBSf7NNOcEM8XJ6H3 ukqnOIr2Vt+7uYnYe2rsEl6HFvi0zgeU1DUewH/yYeNARfVZ5KYfXEVkxatqd/NK0u0/ y1eQ== X-Gm-Message-State: AC+VfDwwZKMoCfr9V1qnPFk2Nz+cuea4SHHqmgyRSuZ95pFcaV9R3uu3 IDGR38i21JgTP+qCHaaeF5KY0PNNe9PBRGQjlqWgH9r5V0cL9HtLfmH27SEQpoaV2qhC80JT8FG GkDzcfQYlxV9Go5731uTFL+5ZNp9PE4i0eJ36TS5/8LcpyDEVMWN/yJOCsw+iXvKY54CuhrS5mZ J4dzqEnZCEDPdxmIojWgOLF6cPpaV6d8zrBpSYGfszxMd4AlVby4WSuEGfYi4d7JphdA== X-Google-Smtp-Source: ACHHUZ648nrQlUypliVlWR7VJrSyEnxeuSPw1CygMP+yK5p0L44DCOAPI3mT9LGG8c0UyhISCQCC4g== X-Received: by 2002:a17:907:749:b0:966:3310:50ae with SMTP id xc9-20020a170907074900b00966331050aemr12170958ejb.47.1684875454210; Tue, 23 May 2023 13:57:34 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-225-239.bb.vodafone.cz. [86.49.225.239]) by smtp.gmail.com with ESMTPSA id f25-20020a170906825900b0096f6647b5e8sm4952494ejx.64.2023.05.23.13.57.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 May 2023 13:57:33 -0700 (PDT) Message-ID: Date: Tue, 23 May 2023 22:57:31 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: memory leak in trigger handling (since PG12) Content-Language: en-US To: Tom Lane Cc: PostgreSQL Hackers References: <222a3442-7f7d-246c-ed9b-a76209d19239@enterprisedb.com> <960113.1684859980@sss.pgh.pa.us> From: Tomas Vondra In-Reply-To: <960113.1684859980@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 5/23/23 18:39, Tom Lane wrote: > Tomas Vondra writes: >> it seems there's a fairly annoying memory leak in trigger code, >> introduced by >> ... >> Attached is a patch, restoring the pre-12 behavior for me. > >> While looking for other places allocating stuff in ExecutorState (for >> the UPDATE case) and leaving it there, I found two more cases: > >> 1) copy_plpgsql_datums > >> 2) make_expanded_record_from_tupdesc >> make_expanded_record_from_exprecord > >> All of this is calls from plpgsql_exec_trigger. > > Not sure about the expanded-record case, but both of your other two > fixes feel like poor substitutes for pushing the memory into a > shorter-lived context. In particular I'm quite surprised that > plpgsql isn't already allocating that workspace in the "procedure" > memory context. > I don't disagree, but which memory context should this use and when/where should we switch to it? I haven't seen any obvious memory context candidate in the code calling ExecGetAllUpdatedCols, so I guess we'd have to pass it from above. Is that a good idea for backbranches ... regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company