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 1qbuKf-00DLHQ-PV for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Sep 2023 02:56:25 +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 1qbuKd-00BcbO-Jb for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Sep 2023 02:56:23 +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 1qbuKd-00Bcb4-AK for pgsql-bugs@lists.postgresql.org; Fri, 01 Sep 2023 02:56:23 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qbuKY-002GA7-6L for pgsql-bugs@lists.postgresql.org; Fri, 01 Sep 2023 02:56:22 +0000 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6bd3317144fso1228879a34.1 for ; Thu, 31 Aug 2023 19:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693536976; x=1694141776; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8Bvs7Zpo+gHqBzkzt78w5B3bq3Pf67rd8RfXXkK0Vj4=; b=h+wu6VN4/qjyr6dntE3+zuc1rxV1XiYGSMJrWYe+JLgY9Q4Lo/QEoUbU/GzzD26tgy 5g8BLSqeMxExG57ZimXQS2wXaJBDX5/969cu/l+SCuEFBtxiJJNRo2tNd4As6frL1E94 sdGqjPX8BlVueW81NEoZnZFR7xa6ZLc+4FQEBw4ZW/CxQC2JVfUvF+IPBq0KZXmm+fur TvxZMWcg5AMU/ruzmFijZogwsop8WpQdsT51b/eCSBiF426BiBLnNRwuQ9Ld+v5aQXKD czMjZN+xcse2G0y52juASiNnj2nLTMwGYj+7+DjCWqbGw2MABNztEZS6S/H4iTqMb0ev 0HjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693536976; x=1694141776; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8Bvs7Zpo+gHqBzkzt78w5B3bq3Pf67rd8RfXXkK0Vj4=; b=R5EigLMK1ffpWrelP6VEJxn0zm/GS6aEvRndHKsNj08xsHsuiAY0aoCEuTuIpFAqEj oQhB+npEs5WqTRQXUa3YSs5tQZKdBU53GE3PUdb3ecfRVSWAziBmxmg5PRHNcWInOd+r NhYXyjrGT6G8T05tzBy3rXjXZm204hupivfDD5CCFp0kNcMEU9S4Ti4n87xRPtdw+pzc xrpAmXzgvXuEjnsMrRR3/rI+k/FP7NjZlOG6ULl/W5xTs/K3zGqLQH9GuBRBBZ+eDzbY O+Jz4SWpgYUQ4gCiq65oqNKVOF0+L24aPFpBXzLNAfhywZHaHJy+QoqqBBvg72DHCiy5 Ud0g== X-Gm-Message-State: AOJu0YzOHwNaKveEKJczZ+3qrajHOeVik8Bc/Hn2EHF3OV7O6/09EXrf 1KXE/bFgj1KP3YawIGmA1CE= X-Google-Smtp-Source: AGHT+IFmpYFxYJFZrMt69D47WWT4NZRKKaO2fSKPe9elDDME2as+SI2N9qhjmdqDh4Eto+Kc5dQByQ== X-Received: by 2002:a9d:66c7:0:b0:6bc:bc3e:f40b with SMTP id t7-20020a9d66c7000000b006bcbc3ef40bmr1297989otm.19.1693536976105; Thu, 31 Aug 2023 19:56:16 -0700 (PDT) Received: from nathanxps13 ([2600:1700:48f8:340f:9727:bde9:1c47:1173]) by smtp.gmail.com with ESMTPSA id z14-20020a9d65ce000000b006b871010cb1sm1423790oth.46.2023.08.31.19.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 19:56:15 -0700 (PDT) Date: Thu, 31 Aug 2023 19:56:13 -0700 From: Nathan Bossart To: Michael Paquier Cc: Andres Freund , Jacob Speidel , Will Mortensen , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17973: Reinit of pgstats entry for dropped DB can break autovacuum daemon Message-ID: <20230901025613.GB3097511@nathanxps13> References: <17973-bca1f7d5c14f601e@postgresql.org> <20230614213724.gweo666oxqrugm44@awork3.anarazel.de> <20230614215744.ddeuii7jcojbp3yv@awork3.anarazel.de> <20230614223012.cfyzxyfnt3ggqkt4@awork3.anarazel.de> <20230812004812.4yev47iili57u4hc@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Sep 01, 2023 at 10:08:57AM +0900, Michael Paquier wrote: > On Mon, Aug 14, 2023 at 09:11:50AM +0900, Michael Paquier wrote: >> At the end, after looking again at the patch and the thread, I'm OK >> with pgstat_update_dbstats() doing nothing if we don't have >> MyDatabaseId, because there is nothing to do in this case based on the >> current structure of the database-level stats, but the expectations >> surrounding pgstat_update_dbstats() need some clarifications. Take it >> as a "I'm OK with the logic of the patch, but it can be improved" ;) > > I have spent quite a few eye hours on the patch, and I would like to > apply the attached down to v15 at the beginning of next week, likely > Monday, to take care of the autovacuum scheduler issue. I've spent much less time staring at the patch than you, but it looks logically sound to me. IMO the changes to InitPostgres() are arguably worthwhile on their own. > + /* > + * Now that we rechecked, we are certain to be connected to a database and > + * thus can set MyDatabaseId. > + */ > + MyDatabaseId = dboid; Perhaps we should expand this comment to make it clear that some code depends on this to avoid races with concurrent database drops/renames. One other thing that comes to mind is whether this patch creates the opposite problem for some other code, i.e., it depends on MyDatabaseId being set before the lock is taken. But that seems pretty unlikely, and I'm not aware of anything like that off the top of my head. Also, IIUC we could simply move the recheck to just after the lock aquisition and then check MyProc->databaseId in pgstat_update_dbstats(), but as I mentioned above, the changes to InitPostgres() are kind of nice independently. Plus, it's nice to be able to depend on MyDatabaseId in the same way. In short, LGTM. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com