Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fNnpc-0001Mm-Kp for pgsql-hackers@arkaria.postgresql.org; Tue, 29 May 2018 23:15:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fNnpb-0000jV-0j for pgsql-hackers@arkaria.postgresql.org; Tue, 29 May 2018 23:15:07 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fNnpa-0000j0-MA for pgsql-hackers@lists.postgresql.org; Tue, 29 May 2018 23:15:06 +0000 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fNnpW-0002WY-Go for pgsql-hackers@postgresql.org; Tue, 29 May 2018 23:15:05 +0000 Received: by mail-qt0-x242.google.com with SMTP id h2-v6so20949790qtp.7 for ; Tue, 29 May 2018 16:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=3pGCMY0X8sCcTZJQgOF8Q/+XxfERdecuwlkBJskZvwg=; b=WO80YrhagEYbidO+qoZZY+V6eFzYMqctgP/92xcZ7taJ8bW9cNOzQP3e9HKcfX8Y/C rvZ2By1bOb6H3sAmA3TA6Vu1ZvDFfHrk0fPRps7UNZDfYUOuFYMS1UBbJwsE3OdvjCNd hbpIuoVB5q1yDzfOHTtK1NBI9ky840Q+dqJ4ruHTqhiIwFtad75d5VO9tMG4ebn1egKQ yotDS/iQMG7VZOg2+3JPMJopZLNcxwT9PLkVfPH1/XRMOHSWaTTUCkLJBCtjO10UTLLj VAd6x6BGZrBXKTNug4ZXLfrw8MSp1hLMxOAQSsi8jVF9PcSVdxmYewqXuE+L4Vvemia0 VCIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=3pGCMY0X8sCcTZJQgOF8Q/+XxfERdecuwlkBJskZvwg=; b=XL39+oLgBK4KNC7OGYjmlsPoXWkhsReuMGVK+lNp2zfrUKC3SmBJDSHkzPtq+ROlxH pMpF7S4SdWQaUy1vYprFe3DL3sHUCTF37HQ7sp5KTFtIRtu9o2J7fetJmI+uVJTqAJIk bhLxT2xg30OsS6VcpKONp0XvxxsLD5uNNjRL/f8QomCEeBBrj/VFMq6nuYMmM2GQ6UT5 UrJ5daRDpKNfnGF8S7Vhnl0C4K7mVqk2APSXfw3Wrrp55pWrE9T4rMpmk1CIyjGh8C3y GwZdvgEA011jmgcoCZ2emkHMOH2ZCqZLIvM9KbmMl19FSKKdDPW5hE+7MwSE6mv16nLN OlBA== X-Gm-Message-State: APt69E2sCOX+1AFJlNmXRauyU7C7bycPVZCpcF5FvKwFdWQhSY4wqiso pvwBsL9X/jigy1yT0AhQ6yrPfQ== X-Google-Smtp-Source: ADUXVKIp0PDw3/qYo427KIKFvJVyYOzVokiYldf0Tbz2dhxnxlHQRTCAzzxA26Jd07elYNslirQW9Q== X-Received: by 2002:ac8:3517:: with SMTP id y23-v6mr376865qtb.143.1527635701203; Tue, 29 May 2018 16:15:01 -0700 (PDT) Received: from alvin.alvh.no-ip.org ([191.126.227.221]) by smtp.gmail.com with ESMTPSA id m4-v6sm213216qke.69.2018.05.29.16.14.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 16:15:00 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id A744C60D; Tue, 29 May 2018 19:14:51 -0400 (-04) Date: Tue, 29 May 2018 19:14:51 -0400 From: Alvaro Herrera To: Andres Freund Cc: Tom Lane , "Nasby, Jim" , "pgsql-hackers@postgresql.org" , Maxim Boguk , Peter Geoghegan , Jeremy Finzel Subject: Re: found xmin from before relfrozenxid on pg_catalog.pg_authid Message-ID: <20180529231451.z4ncmiqctmdcj3tl@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="qlqgzazgx37xhqcz" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180528195206.6vqxcdhvfurlyhda@alap3.anarazel.de> User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --qlqgzazgx37xhqcz Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit I added an Assert(DatabasePath != NULL) to RelationCacheInitFilePreInvalidate() and didn't see a single crash when running the tests. I thought that adding a "VACUUM FREEZE pg_class" in the recovery tests (where there is a standby) ought to do it, but it doesn't. What's the deal there? Here are some proposed changes. Some of these comment edits are WIP :-) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --qlqgzazgx37xhqcz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fixup.patch" diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index 0d6100fb08..8a8620943f 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -872,6 +872,8 @@ ProcessCommittedInvalidationMessages(SharedInvalidationMessage *msgs, int nmsgs, bool RelcacheInitFileInval, Oid dbid, Oid tsid) { + Assert(InRecovery); + if (nmsgs <= 0) return; @@ -884,12 +886,13 @@ ProcessCommittedInvalidationMessages(SharedInvalidationMessage *msgs, dbid); /* - * RelationCacheInitFilePreInvalidate, when the invalidation message - * is for a specific database, requires DatabasePath to be set, but we - * should not use SetDatabasePath during recovery, since it is - * intended to be used only once by normal backends. Hence, a quick - * hack: set DatabasePath directly then unset after use. + * When the invalidation message is for a specific database, + * RelationCacheInitFilePreInvalidate requires DatabasePath to be set, + * but we're not allowed to use SetDatabasePath during recovery (since + * it is intended to be used by normal backends). Hence, a quick hack: + * set DatabasePath directly then unset after use. */ + Assert(!DatabasePath); /* don't clobber an existing value */ if (OidIsValid(dbid)) DatabasePath = GetDatabasePath(dbid, tsid); diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index aa4427724d..71b2212cbd 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1934,6 +1934,11 @@ RelationIdGetRelation(Oid relationId) RelationClearRelation(rd, true); /* + * Normal entries are valid by now -- except nailed ones when + * loaded before relcache initialization. There isn't enough + * infrastructure yet to do pg_class lookups, but we need their + * rd_rel entries to be updated, so we let these through. + */ * Normally entries need to be valid here, but before the relcache * has been initialized, not enough infrastructure exists to * perform pg_class lookups. The structure of such entries doesn't @@ -2346,8 +2351,7 @@ RelationClearRelation(Relation relation, bool rebuild) RelationCloseSmgr(relation); /* - * Treat nailed-in system relations separately, they always need to be - * accessible, so we can't blow them away. + * We cannot blow away nailed-in relations, so treat them especially. */ if (relation->rd_isnailed) { @@ -5942,7 +5946,8 @@ write_relcache_init_file(bool shared) * wrote out was up-to-date.) * * This mustn't run concurrently with the code that unlinks an init file - * and sends SI messages, so grab a serialization lock for the duration. + * and sends SI messages (see RelationCacheInitFilePreInvalidate), so grab + * a serialization lock for the duration. */ LWLockAcquire(RelCacheInitLock, LW_EXCLUSIVE); @@ -6061,6 +6066,10 @@ RelationHasUnloggedIndex(Relation rel) * changed one or more of the relation cache entries that are kept in the * local init file. * + * When DatabasePath is set, both the init file for that database and the + * shared (global) init files are to be removed; otherwise only the latter is. + * This is useful during recovery (XXX really?) + * * To be safe against concurrent inspection or rewriting of the init file, * we must take RelCacheInitLock, then remove the old init file, then send * the SI messages that include relcache inval for such relations, and then @@ -6180,9 +6189,9 @@ unlink_initfile(const char *initfilename, int elevel) { if (unlink(initfilename) < 0) { - /* It might not be there, but log any error other than ENOENT */ + /* It might not be there, but report any error other than ENOENT */ if (errno != ENOENT) - ereport(ERROR, + ereport(elevel, (errcode_for_file_access(), errmsg("could not remove cache file \"%s\": %m", initfilename))); --qlqgzazgx37xhqcz--