Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvTPZ-0006uD-Lp for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Sep 2017 19:14:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dvTPZ-0005fg-8a for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Sep 2017 19:14:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dvTNz-0001J4-Cy for pgsql-hackers@postgreSQL.org; Fri, 22 Sep 2017 19:13:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dvTNw-0004bS-JG for pgsql-hackers@postgreSQL.org; Fri, 22 Sep 2017 19:13:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v8MJDADU025024 for ; Fri, 22 Sep 2017 15:13:10 -0400 From: Tom Lane To: pgsql-hackers@postgreSQL.org Subject: Shaky coding for vacuuming partitioned relations MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25022.1506107590.1@sss.pgh.pa.us> Date: Fri, 22 Sep 2017 15:13:10 -0400 Message-ID: <25023.1506107590@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Somebody inserted this into vacuum.c's get_rel_oids(): tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); if (!HeapTupleIsValid(tuple)) elog(ERROR, "cache lookup failed for relation %u", relid); apparently without having read the very verbose comment two lines above, which points out that we're not taking any lock on the target relation. So, if that relation is concurrently being dropped, you're likely to get "cache lookup failed for relation NNNN" rather than anything more user-friendly. A minimum-change fix would be to replace the elog() with an ereport that produces the same "relation does not exist" error you'd have gotten from RangeVarGetRelid, had the concurrent DROP TABLE committed a few microseconds earlier. But that feels like its's band-aiding around the problem. What I'm wondering about is changing the RangeVarGetRelid call to take ShareUpdateExclusiveLock rather than no lock. That would protect the syscache lookup, and it would also make the find_all_inheritors call a lot more meaningful. If we're doing a VACUUM, the ShareUpdateExclusiveLock would be dropped as soon as we close the caller's transaction, and then we'd acquire the same or stronger lock inside vacuum_rel(). So that seems fine. If we're doing an ANALYZE, then the lock would continue to be held and analyze_rel would merely be acquiring it an extra time, so we'd actually be removing a race-condition failure scenario for ANALYZE. This would mean a few more cycles in lock management, but since this only applies to a manual VACUUM or ANALYZE that specifies a table name, I'm not too concerned about that. Thoughts? regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers