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 1nAbgs-0004rw-7f for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jan 2022 17:57:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nAbgr-0006Ye-40 for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jan 2022 17: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 1nAbgq-0006Xg-Fw for pgsql-bugs@lists.postgresql.org; Thu, 20 Jan 2022 17:57:40 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nAbgm-0006cM-L1 for pgsql-bugs@lists.postgresql.org; Thu, 20 Jan 2022 17:57:40 +0000 Received: by mail-ed1-x530.google.com with SMTP id m4so31959427edb.10 for ; Thu, 20 Jan 2022 09:57:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to; bh=qV1S/qhVv45diuQwiBU4NFrRh8RssevBgqqZV+KGf5g=; b=LdyKWkhma4Are4YXXmVLMtCjBfLljsU/O7QLO9K7Tm0T9QupUkHiyGX81PQFxKzscB gxyLfykMBIvEw6uu+JJRicOgonifW4IvYefuAxwrTcF596oaWJ3YCP8/hVqZpITGE7hB FJ6A8EtiWzlju7z8UqdVXlQt9XF+uw0WvkHtznwsw0c3HPY9WdAdmbd9H/2o2Bg3I8pg JqSxZ0QHwajJrxhmHzGODlHf8wJYyE7JGJVCLCzFtryJFSrxcEBBgkg5hqSGsxcw8yct pWslxB8EEQWkCam0VSx23B+Swtfoc7NJBnpa383Gtzv78PafhuYJU2csCd32BuXqxNT1 ZPSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to; bh=qV1S/qhVv45diuQwiBU4NFrRh8RssevBgqqZV+KGf5g=; b=JR5mE2fOgVMFBFDVPE70b95aNaix4HjayrVWSkHop+FWwK88mitVek/ogsm9oedaWJ cbQq3Dy81HyUvfpoQEUlKgBxgSM75LiR9Wat8S4lfxv8o8mb/6ZUH6PpmiqInk1D2hmA qQHgng7G3nb7MN5f6KKnBWzbU02R6ql1OobtOVFJLiEN4n34FxQEHhjOw4aUVbUHst6B hv6CoAogz/7CXyl30W5XWNP6AV/imXGHkVXIs9xoB4Nzz8i/ql7K8sa5aAneHUgA4oQX euH/SIsJYDBbuOwEMPTK3lA1kgeyy7bOLBblWIF18Ir0fkYgC65VQjJJ1Hwk5T1LbI9f 3mgQ== X-Gm-Message-State: AOAM5317Yni/am+BE255Y9duyaZ+4mae2F/DPuXfITrM1DGpjrbHHDhn J6W3QropXnRkpt+KXv28czmuRnDb7aO5KWngLZHVTVOOmmobMPsuhAjC2eybbi9MSRmQA5IOCrM HuErI/9wZ4S4ySP6U4jYVikr9EqFQB4sCmKy/slwjdnIKCIPdwPtR++Wl3mNjhTbjFwx21blZh0 3w0foaFDqjMxfIn/kY0xXUp10dG+GbZirEAZX/AX9Mv9xt/s1STBLT X-Google-Smtp-Source: ABdhPJyTgC/NEBv2UZQzW0t/r2Cf6MQeYTPx6JUVUV6aPbzHxBECeC32l25n4joXP/IbC8SRPLR7Xw== X-Received: by 2002:a05:6402:27cb:: with SMTP id c11mr175081ede.397.1642701455417; Thu, 20 Jan 2022 09:57:35 -0800 (PST) Received: from [10.137.0.19] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id g9sm1265226ejf.98.2022.01.20.09.57.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jan 2022 09:57:34 -0800 (PST) Content-Type: multipart/mixed; boundary="------------Qfcm60Y0OsU0Ya3cZn4EkaRk" Message-ID: <2615f158-b790-4176-11ad-9711e4fd56c7@enterprisedb.com> Date: Thu, 20 Jan 2022 18:57:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: BUG #17372: Altering statistics during concurrent drop can lead to a server crash Content-Language: en-US To: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form References: <17372-bf3b6e947e35ae77@postgresql.org> From: Tomas Vondra In-Reply-To: <17372-bf3b6e947e35ae77@postgresql.org> 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. --------------Qfcm60Y0OsU0Ya3cZn4EkaRk Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 1/20/22 05:00, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 17372 > Logged by: Alexander Lakhin > Email address: exclusion@gmail.com > PostgreSQL version: 14.1 > Operating system: Ubuntu 20.04 > Description: > > The following script (based on the stats_ext test): > psql -c "CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);" > for i in `seq 100`; do > echo "iteration $i" > ( { for n in `seq 20`; do echo "CREATE STATISTICS ab1_a_b_stats ON a, b FROM > ab1; DROP STATISTICS ab1_a_b_stats;"; done } | psql ) >psql1.log 2>&1 & > ( { for n in `seq 20`; do echo "ALTER STATISTICS ab1_a_b_stats SET > STATISTICS -1;"; done } | psql ) >psql2.log 2>&1 & > > wait > sleep 2 > coredumpctl --no-pager && break > done > Thanks for the report - I've reproduced it using your script (I had to add a short wait before the syscache lookup). The issue is fairly simple, we never check we actually found a tuple in the syscache, i.e. there's no HeapTupleIsValid() call. We check the OID earlier, but the tuple may have disappeared since then. IMO the usual "cache lookup failed" error that we throw in other places in similar cases is good enough. We already fail with other errors (tuple concurrently updated/deleted) here. Patch attached. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --------------Qfcm60Y0OsU0Ya3cZn4EkaRk Content-Type: text/x-patch; charset=UTF-8; name="alter-statistics-fix.patch" Content-Disposition: attachment; filename="alter-statistics-fix.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2NvbW1hbmRzL3N0YXRzY21kcy5jIGIvc3JjL2Jh Y2tlbmQvY29tbWFuZHMvc3RhdHNjbWRzLmMKaW5kZXggZWRjNGM0ODEwNDMuLjU5ZTUzMWI1 NWQ4IDEwMDY0NAotLS0gYS9zcmMvYmFja2VuZC9jb21tYW5kcy9zdGF0c2NtZHMuYworKysg Yi9zcmMvYmFja2VuZC9jb21tYW5kcy9zdGF0c2NtZHMuYwpAQCAtNjc3LDYgKzY3Nyw4IEBA IEFsdGVyU3RhdGlzdGljcyhBbHRlclN0YXRzU3RtdCAqc3RtdCkKIAlyZWwgPSB0YWJsZV9v cGVuKFN0YXRpc3RpY0V4dFJlbGF0aW9uSWQsIFJvd0V4Y2x1c2l2ZUxvY2spOwogCiAJb2xk dHVwID0gU2VhcmNoU3lzQ2FjaGUxKFNUQVRFWFRPSUQsIE9iamVjdElkR2V0RGF0dW0oc3R4 b2lkKSk7CisJaWYgKCFIZWFwVHVwbGVJc1ZhbGlkKG9sZHR1cCkpCisJCWVsb2coRVJST1Is ICJjYWNoZSBsb29rdXAgZmFpbGVkIGZvciBleHRlbmRlZCBzdGF0aXN0aWNzIG9iamVjdCAl dSIsIHN0eG9pZCk7CiAKIAkvKiBNdXN0IGJlIG93bmVyIG9mIHRoZSBleGlzdGluZyBzdGF0 aXN0aWNzIG9iamVjdCAqLwogCWlmICghcGdfc3RhdGlzdGljc19vYmplY3Rfb3duZXJjaGVj ayhzdHhvaWQsIEdldFVzZXJJZCgpKSkK --------------Qfcm60Y0OsU0Ya3cZn4EkaRk--