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 1q1sYR-0000PO-GT for pgsql-hackers@arkaria.postgresql.org; Wed, 24 May 2023 17:45:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q1sYQ-0005IL-Bp for pgsql-hackers@arkaria.postgresql.org; Wed, 24 May 2023 17:45:42 +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 1q1sYQ-0005FG-1r for pgsql-hackers@lists.postgresql.org; Wed, 24 May 2023 17:45:42 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q1sYM-001ug4-1D for pgsql-hackers@lists.postgresql.org; Wed, 24 May 2023 17:45:41 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-96f7bf29550so177848066b.3 for ; Wed, 24 May 2023 10:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1684950337; x=1687542337; 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=sT7FJAlJoJ3E0q+1bI99SSRHQ/KCs7UwrRyiYsWEt/E=; b=LNuyvZW7CGO+7hMtqEsNg22zvGxh9oWVtqT2SCbOyVhZwCeSVy7dPr8D4/EpGJBkFo ZJEb2iCCtm3GHNYpQ8cZ2FD5gFs0UEZUGwz6uTPAmI333KwAJ41y2cfp4tDVt61zr/gg 7EmYYtUtmDrw8dM3Fc7TeYzu/+vlERq+s+pYxdheTdhp3C9YHwz82vC3nL7pNH4adifd 2tF1UVTvbkuvX1KgLE2o7xyLobDzBUaa5cDqVoO87XCs0ffyFXDfKaFeybXZtPyXZnQG 71+Y81O4Ey0dyiPzi8ZAB+8M95R4qq8VvSvhQYbmZQYdb7SIKWv+Jf77FNnrWSUAKje/ QZ9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684950337; x=1687542337; 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=sT7FJAlJoJ3E0q+1bI99SSRHQ/KCs7UwrRyiYsWEt/E=; b=UfIuGgErc3mMZgV3Dl9ZT1WYI/+Z7jlPawJIvF+6PTm2fgo6mSUIiTHKvaRg9KPqv2 26DiSoiscpTZMToUk2Tx1kbFzHUVMpT230Z04+K967qIAXuWpAYtBVEeIbeqlp28DQKC sIr5fz0vMlmFJ1U4v6tdl+oBSpCutSbk65DE8KYrihukOmFC+3NyXqzr/gPpPHNBnky9 6F64a+Y+/PnwFZHygaBgSNiEnLU4uVKojMkiws0JZ7IHnRelzDJmazCZexCbPuWpFtie QadwGh5fSlypMIylEkcqQMIv1+aiJA+ODq1qe64DIcgKuYJz4qLJYVrjuBxUUIpZoMYd 8Bvw== X-Gm-Message-State: AC+VfDyNhdpqZ1NcXLBrCXWXrZOJwQYeV8vbr4GGvMKHujJmeydIvtJR X7YqxvmdTPX7MSEEUG1vOqN5AOYFs2YqEDdOgdRPXb/4gsja8h7TYjXX08uaFVnfLC5PFgfZZ7u L56yxACXj3q4kjftM9+v5xu0r+riCE9L/o4e35ex03cJBQ1Tg41Sj6f3FfLfU345s30SdB9yNsF CyS1jIi8ysJz1i/s0MKBpeab3Fv4D8c/+MYjU13ylH3SG874FE6QNEL0S28E0yzdCYyw== X-Google-Smtp-Source: ACHHUZ5sXnUcYZEHEYY6uhM4ZWD6t5PZ057MaRasxVvTF1YLl0XBX974F/8w9ss+G2qt7QE3V5gsWQ== X-Received: by 2002:a17:906:ef07:b0:971:5a79:29ff with SMTP id f7-20020a170906ef0700b009715a7929ffmr5769078ejs.48.1684950336915; Wed, 24 May 2023 10:45:36 -0700 (PDT) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id lj17-20020a170906f9d100b00965d294e633sm6137133ejb.58.2023.05.24.10.45.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 10:45:36 -0700 (PDT) Message-ID: <9ed6f2b5-0c5e-e708-2c7f-3581c4b80ed6@enterprisedb.com> Date: Wed, 24 May 2023 19:45:34 +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> <1137299.1684942630@sss.pgh.pa.us> From: Tomas Vondra In-Reply-To: <1137299.1684942630@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/24/23 17:37, Tom Lane wrote: > Tomas Vondra writes: >> 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. > > Can you show a test case in which this happens? I added some > instrumentation and verified at least within our regression tests, > copy_plpgsql_datums' CurrentMemoryContext is always plpgsql's > "SPI Proc" context, so I do not see how there can be a query-lifespan > leak there, nor how your 0003 would fix it if there is. > Interesting. I tried to reproduce it, but without success, and it passes even with an assert on the context name. The only explanation I have is that the gdb script I used might have been a bit broken - it used conditional breakpoints like this one: break AllocSetAlloc if strcmp(((MemoryContext) $rdi)->name, \ "ExecutorState") == 0 commands bt cont end but I just noticed gdb sometimes complains about this: Error in testing breakpoint condition: '__strcmp_avx2' has unknown return type; cast the call to its declared return type The breakpoint still fires all the commands, which is pretty surprising behavior, but that might explain why I saw copy_plpgsql_data as another culprit. And I suspect the make_expanded_record calls might be caused by the same thing. I'll check deeper tomorrow, when I get access to the original script etc. We can ignore these cases until then. Sorry for the confusion :-/ regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company