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 1lNHx0-0003gK-Ra for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Mar 2021 16:26:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lNHwz-00047J-OI for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Mar 2021 16:26:13 +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 1lNHwz-000475-HS for pgsql-hackers@lists.postgresql.org; Fri, 19 Mar 2021 16:26:13 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lNHww-00068B-Ew for pgsql-hackers@lists.postgresql.org; Fri, 19 Mar 2021 16:26:13 +0000 Received: by mail-ej1-x62d.google.com with SMTP id k10so10681639ejg.0 for ; Fri, 19 Mar 2021 09:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=Xgqla2fQ5NpevhHar7fHj2bwJ6Q4R2gnwOH39buWlio=; b=h8jNe0KglsEyN402JM0xqLq2arx/3MW12ZA8NiWp6F0xHfwpMdV3qUa7/GquWJJxTN N7Y+jBdDQ6KkKT3VJlIoGUZYv+ktSBkg5k/Oa4c14EUlZ3g1okwNlh691mW5oDhaWg4F nNVWE2lo0KsM4EyV8tKTCFVVAZYhT/04bTlBLnnyszJUO0eRDtm8SlWCarqqMnjx78ne NKoAbO2Rxrc/puNugQmy9AKdMdhU0GR4UuplmHo8IPanqKi43B7WGeAeb7y7he/Xv0tB Zou6bUG/vGev2hZ93THPuG00/go+vlK3XxeCAzWD32+tIRDyTOjpMiVbvtRiMSh7TrDf BO1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=Xgqla2fQ5NpevhHar7fHj2bwJ6Q4R2gnwOH39buWlio=; b=kCnLTWtlKttn7oJ+JiuItyp2/Y7hn0aRTzqzpgeXAUOQv8tgec3aHDwWhh7FY9OEqg gD6aH+Sj+N2QirIYn18GD/nSxTjnIqMIteYs22eLx0Iia+ym/k0RaZ2vUXC92LB2Lz19 xPwINUMiNt+nGMOc+pTmbmcu4TE/1HHdRpXvvhu+P0CxIfUdVziiWdHOL8zuA+jtHr0H qAxA0X2nA1NwqQWvRDFt6qiXNCe7eG+V7Cro1cUIW/Ak7QZUzdoW9yv7YExsFv5z5x2g c6cDfmPkT1YMeASgXpGBcCh8PU6z/ahwDXXMc5gcWZ3Y+SPbq67F1qCmeaiNjS7r6UWF 1cPA== X-Gm-Message-State: AOAM5323/itTf9rhsxOS9kkz8LBN/9WjWa2o2FbRHcxZNRrlYNHHoayq i++Ni3695jAV35orvgrLfob8Of6n4srP/OZa6RzHCN8iNwoPSKfkUN5TnSRAGkGfl66OPvugxqk dt+WVSxVkHZdrOjK+T9Nl5FHN3B9QmNLJSLI+m+shsGfNp3oOW3o7a12VNKA5dboQNF7ejLOVBk Pld8sxaYTFJQIuAiyJpIGGPgpV/LPZXxFBipmqiiOJpCzfn8jJ7vuJsEU4/S4+YOv78MexReiZm eReotBjNKql+TzETGRljnajk5V3ugEgZPc56Qi71CNOQxtk+np43g== X-Google-Smtp-Source: ABdhPJwHixQHOnP8GVm2M80fz7sXLnsWJ/IB3kPiQJfOa8Ghs4ChNXHJDuagzoDVi7diezaMmtt/ng== X-Received: by 2002:a17:907:9152:: with SMTP id l18mr5216257ejs.376.1616171169153; Fri, 19 Mar 2021 09:26:09 -0700 (PDT) Received: from [10.137.0.4] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id k12sm4418694edr.60.2021.03.19.09.26.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Mar 2021 09:26:08 -0700 (PDT) Subject: Re: cleanup temporary files after crash To: Euler Taveira , Tom Lane Cc: Thomas Munro , Michael Paquier , Euler Taveira , Anastasia Lubennikova , Tomas Vondra , PostgreSQL Hackers References: <4245d284-97b2-4056-96c2-455792d9b564@www.fastmail.com> <8740f056-a7c0-ff12-0a50-de5324a928ee@enterprisedb.com> <822e3a60-56a1-219d-c473-365751c3e108@enterprisedb.com> <54663718-1d87-46f2-a27b-e7edacbfae0d@www.fastmail.com> <1ec33f3d-ea4c-28c8-502c-3eb0a008a6ac@enterprisedb.com> <34226249-c5ba-4780-a1bb-f3433d19716e@www.fastmail.com> <05d307fc-8391-4091-b279-1b3214658f10@www.fastmail.com> <049a2752-fc99-194d-31b2-b15ffa914cd4@enterprisedb.com> <482a6498-7713-e937-c554-7d235c415fba@enterprisedb.com> <112f0847-a71!a-eec2-e561-2d39dc26127a@enterprisedb.com> <4028905.1616122655@sss.pgh.pa.us> <19bc3276-6280-43bd-d868-ab3cb146266a@enter!prisedb.com> <4030089.1616124234@sss.pgh.pa.us> <6eff9861-b059-4eaa-ae70-e5ff877b6448@www.fastmail.com> <70bbfaac-74dd-de9a-b086-8bf43224e1c0@enterprisedb.com> From: Tomas Vondra Message-ID: Date: Fri, 19 Mar 2021 17:26:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <70bbfaac-74dd-de9a-b086-8bf43224e1c0@enterprisedb.com> Content-Type: multipart/mixed; boundary="------------900C5DD08E3C27A664D7E8F5" Content-Language: en-US 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 This is a multi-part message in MIME format. --------------900C5DD08E3C27A664D7E8F5 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 3/19/21 5:23 PM, Tomas Vondra wrote: > ... > > If I replace this with a wait loop in a plpgsql block, that works > perfectly fine (no infinite loops). Tested both on x86_64 and rpi. > For the record, here's the version with plpgsql block, which seems to be working just fine. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --------------900C5DD08E3C27A664D7E8F5 Content-Type: text/x-patch; charset=UTF-8; name="cleanup-tap-plpgsql-block.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="cleanup-tap-plpgsql-block.patch" diff --git a/src/test/recovery/t/022_crash_temp_files.pl b/src/test/recovery/t/022_crash_temp_files.pl index 8044849b73..c5624fe864 100644 --- a/src/test/recovery/t/022_crash_temp_files.pl +++ b/src/test/recovery/t/022_crash_temp_files.pl @@ -79,8 +79,8 @@ my $killme2 = IPC::Run::start( # Insert one tuple and leave the transaction open $killme_stdin2 .= q[ BEGIN; -SELECT $$insert-tuple-to-lock-next-insert$$; INSERT INTO tab_crash (a) VALUES(1); +SELECT $$insert-tuple-to-lock-next-insert$$; ]; pump_until($killme2, \$killme_stdout2, qr/insert-tuple-to-lock-next-insert/m); $killme_stdout2 = ''; @@ -100,6 +100,26 @@ ok(pump_until($killme, \$killme_stdout, qr/in-progress-before-sigkill/m), $killme_stdout = ''; $killme_stderr = ''; +# Wait until the batch insert gets stuck on the lock. +$killme_stdin2 .= q[ +DO $c$ +DECLARE + c INT; +BEGIN + LOOP + SELECT COUNT(*) INTO c FROM pg_locks WHERE pid = ] . $pid . q[ AND NOT granted; + IF c > 0 THEN + EXIT; + END IF; + END LOOP; +END; $c$; +SELECT $$insert-tuple-lock-waiting$$; +]; + +pump_until($killme2, \$killme_stdout2, qr/insert-tuple-lock-waiting/m); +$killme_stdout2 = ''; +$killme_stderr2 = ''; + # Kill with SIGKILL my $ret = TestLib::system_log('pg_ctl', 'kill', 'KILL', $pid); is($ret, 0, 'killed process with KILL'); @@ -147,8 +167,8 @@ $killme2->run(); # Insert one tuple and leave the transaction open $killme_stdin2 .= q[ BEGIN; -SELECT $$insert-tuple-to-lock-next-insert$$; INSERT INTO tab_crash (a) VALUES(1); +SELECT $$insert-tuple-to-lock-next-insert$$; ]; pump_until($killme2, \$killme_stdout2, qr/insert-tuple-to-lock-next-insert/m); $killme_stdout2 = ''; @@ -168,6 +188,26 @@ ok(pump_until($killme, \$killme_stdout, qr/in-progress-before-sigkill/m), $killme_stdout = ''; $killme_stderr = ''; +# Wait until the batch insert gets stuck on the lock. +$killme_stdin2 .= q[ +DO $c$ +DECLARE + c INT; +BEGIN + LOOP + SELECT COUNT(*) INTO c FROM pg_locks WHERE pid = ] . $pid . q[ AND NOT granted; + IF c > 0 THEN + EXIT; + END IF; + END LOOP; +END; $c$; +SELECT $$insert-tuple-lock-waiting$$; +]; + +pump_until($killme2, \$killme_stdout2, qr/insert-tuple-lock-waiting/m); +$killme_stdout2 = ''; +$killme_stderr2 = ''; + # Kill with SIGKILL $ret = TestLib::system_log('pg_ctl', 'kill', 'KILL', $pid); is($ret, 0, 'killed process with KILL'); --------------900C5DD08E3C27A664D7E8F5--