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.94.2) (envelope-from ) id 1qL7ud-002NrP-OU for pgsql-bugs@arkaria.postgresql.org; Sun, 16 Jul 2023 20:00:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qL7ub-000Eju-F0 for pgsql-bugs@arkaria.postgresql.org; Sun, 16 Jul 2023 20:00:09 +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.94.2) (envelope-from ) id 1qL7ub-000Ejm-4U for pgsql-bugs@lists.postgresql.org; Sun, 16 Jul 2023 20:00:09 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qL7uY-000rxI-57 for pgsql-bugs@lists.postgresql.org; Sun, 16 Jul 2023 20:00:08 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4fbc0314a7bso5928174e87.2 for ; Sun, 16 Jul 2023 13:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689537603; x=1692129603; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=irp1Wjm25XKHPhy29zYCxlguFJoxw74tkWbk7bcNIHU=; b=k+5GXlYaMMW9PAp7FEJcqlH2HfWcQfZtbu0ocI0zsCJQnFB3CLXCmcHGDLFWm4zGqx LBG67OB0629Lzf9mXWZnchLEH+BiEDTgVlfM4oMNAmWPfHk0L3UKwq+RAF2Pf/IxA4Mc RWiqVYj7pYBLllUroAuwQnOoFch87AS7HVN0EjKExEWEsMOvafPYYfs4zWpWqx+SXlAB Fy4TjpNLTT9BMS5wmdEBPgwY2HBO7gmw12Ir2qenTS3VUbVtuGN1SoJoOLEGKv+YZsnz hj9YAqAyCrecrbHQT8eHTc65oJgU6Pswghm3cVqaH7MsfPVypWCTTTJLRcHV8WqG4BB1 2OmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689537603; x=1692129603; h=content-transfer-encoding:in-reply-to:from:references: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=irp1Wjm25XKHPhy29zYCxlguFJoxw74tkWbk7bcNIHU=; b=O1zUl0IxSggRokmKLdR18nb8Kg8fuTw5zH6bVHg0b5xoxC51qXd2z4G6JLvDowOg5x w5ZmO4m279aAEDphWjgzRSQJK8g6shDUlYQwt33u1g37B8Jifr31QblFbsp7y6v/kqZP su1XCvfmvsmEXSdh0uuTHTWWc9JfDv9pS0fJzxvKb/xOan478tzQZCi0gZd+OrKzSx8Y GDhS6bBtvCtu7hZPAs/vhvqfNoLQDUrYX8YnRXuSaR9cE5o+6P2yaEGyQoOP2YOTu8wG PYFNHV+2WhjDmlFJpVHbjoc2/OK5leZeuVii3DVKih/6Pn9PLBBB7cPE/fmNFh77G93N ZvmQ== X-Gm-Message-State: ABy/qLb1VNuuMN/i+pohyGGExCXGUj22h5mQHZwMA1GNicGsW40AdlNk wVRSa6zUmijE2y6s/Fclsv0txcTC7QY= X-Google-Smtp-Source: APBJJlGt41QHZxRUr7UZPgpNb6CSn108c5wzqwNTPiM74jsuSdClbpcVI8L8/QhPQXjf5bmfwb14VA== X-Received: by 2002:ac2:504d:0:b0:4fb:897e:21cd with SMTP id a13-20020ac2504d000000b004fb897e21cdmr6135847lfm.67.1689537603381; Sun, 16 Jul 2023 13:00:03 -0700 (PDT) Received: from [1.0.0.7] ([81.23.165.115]) by smtp.gmail.com with ESMTPSA id f14-20020a19ae0e000000b004fd611e5847sm976735lfc.115.2023.07.16.13.00.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 16 Jul 2023 13:00:02 -0700 (PDT) Message-ID: Date: Sun, 16 Jul 2023 23:00:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #18014: Releasing catcache entries makes schema_to_xmlschema() fail when parallel workers are used Content-Language: en-US To: pgsql-bugs@lists.postgresql.org References: <18014-28c81cb79d44295d@postgresql.org> From: Alexander Lakhin In-Reply-To: <18014-28c81cb79d44295d@postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 04.07.2023 14:00, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 18014 > Logged by: Alexander Lakhin > Email address: exclusion@gmail.com > PostgreSQL version: 16beta2 > Operating system: Ubuntu 22.04 > Description: > > Yesterday's test failure on prion: > https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=prion&dt=2023-07-03%2010%3A13%3A03 > made me wonder, what's going on there and whether it's yet another issue > with invalidating relcache (bug #17994). > ( > SELECT schema_to_xmlschema('testxmlschema', false, true, ''); > ERROR: relation with OID 29598 does not exist > CONTEXT: SQL statement "SELECT oid FROM pg_catalog.pg_class WHERE > relnamespace = 29597 AND relkind IN ('r','m','v') AND > pg_catalog.has_table_privilege (oid, 'SELECT') ORDER BY relname;" I investigated this case and would like to share my findings. I added in has_table_privilege_id(), just below      if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(tableoid)))          PG_RETURN_NULL(); the following loop: for (int i = 0; i < 100; i++) {   bool sce = SearchSysCacheExists1(RELOID, ObjectIdGetDatum(tableoid));   if (!sce)     elog(LOG, "has_table_privilege_id(): no syscache entry on iteration %d", i);     break;   } } and discovered that when the reproducing script uses parallel worker(s), the syscache entry disappears during this loop execution. But that's not happening when the query "SELECT oid FROM pg_catalog.pg_class WHERE ..." is executed in a regular backend. AFAICS, the difference is in the LockRelationOid():      res = LockAcquireExtended(&tag, lockmode, false, false, true, &locallock);     /*      * Now that we have the lock, check for invalidation messages, so that we      * will update or flush any stale relcache entry before we try to use it.      * RangeVarGetRelid() specifically relies on us for this.  We can skip      * this in the not-uncommon case that we already had the same type of lock      * being requested, since then no one else could have modified the      * relcache entry in an undesirable way.  (In the case where our own xact      * modifies the rel, the relcache update happens via      * CommandCounterIncrement, not here.)      *      * However, in corner cases where code acts on tables (usually catalogs)      * recursively, we might get here while still processing invalidation      * messages in some outer execution of this function or a sibling.  The      * "cleared" status of the lock tells us whether we really are done      * absorbing relevant inval messages.      */     if (res != LOCKACQUIRE_ALREADY_CLEAR)     {         AcceptInvalidationMessages();         MarkLockClear(locallock);     } when LockRelationOid() is called for pg_class_oid_index inside SearchCatCacheMiss() -> systable_beginscan() -> index_open() -> relation_open(). The parallel worker doesn't have a lock on pg_class_oid_index before executing the query, so it gets the lock and res == LOCKACQUIRE_OK (not LOCKACQUIRE_ALREADY_CLEAR as in a regular backend case), after that it processes invalidation messages (this can make the backend use a newer catalog snapshot), and at the end it does systable_endscan() -> index_close() -> UnlockRelationId() -> LockRelease()... Thus, on a next iteration it gets the lock anew, with the res == LOCKACQUIRE_OK again, and all that ceremony repeated. It's not clear to me, whether this parallel worker behavior is expected and if so, what to fix to avoid the test failure. Best regards, Alexander