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 1qc5wn-00DoQq-ML for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Sep 2023 15:20:33 +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 1qc5wm-00FUuP-FJ for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Sep 2023 15:20:32 +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 1qc5wm-00FUuE-6p for pgsql-bugs@lists.postgresql.org; Fri, 01 Sep 2023 15:20:31 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qc5wi-002MZ7-I4 for pgsql-bugs@lists.postgresql.org; Fri, 01 Sep 2023 15:20:31 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6bcb5df95c5so1687833a34.1 for ; Fri, 01 Sep 2023 08:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693581626; x=1694186426; 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=OAdTIaLKP9bWK/yg6KQhKur2i6Ahk7V6wnoNmd5p4/8=; b=bafl0gi/9Zc5zr/t8XDnBU5w/+SBdRn4X4TYANW3hTwsNldxlMQjg3Ofmttn6ddiUS ma7deZ9yMjZneA10qNIGzMYVx9bDe0H2i+dJpfO4EG0V9Tm19GNYsutL6n/0nrlsWIJr C7S+d3bfz9ZePmkoMFMm8LKKOwMldgTe9Iuwq3ENTK+FdyjJ+iGQlbA9pRezQajQYsO0 jpy5mgpO3r5C7sOXyyzH424JtucMyeJN0bpkxzKre7nbb4M7a9NfLhrD7b0O6nFw78ls NHLLeu22Ua/++KvSNld/sN5GKnjbn60QjDHYP9YTccF0L8Udf7N+/EhkWoZt0cVqW+od bCeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693581626; x=1694186426; 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=OAdTIaLKP9bWK/yg6KQhKur2i6Ahk7V6wnoNmd5p4/8=; b=SLDiWRSkVrCdOF17hkjcJe6rWXU3Cz+R3du0Us2OAoZ6LdhA0cZ2VW3ZRC0EnokLx4 4uV7kvLm8v+D+lr9I3uxya2RjmWJJBIlzUW/SKGui8HgVAaejyG9WV8Phh4V3aEUQSvT oPtiUb6EDWESjkmiJtEh2zHdpczOmWO84dCgrXlNj4hC2u9NohDkMEW2QeLsu+Isi7sT lrdYmSyL+49IVgnkFK7RgRDM3x0PKEQ628kZ4a0lInRLhNMsmkCmDsrawlz/xSuwYn4I kZNXf9IyCQV1YaJOq8ceudwILlGJGH0Nzipf8fJoPTn/ihEEVGWougfHmm138/ETR9Ac vC/A== X-Gm-Message-State: AOJu0YwjEL7zuZBIL0EhF/mw8aAE+t4fd6cJX08ozPJLx1sC1hGVXMjP nb87kymXuWCRTLmliyHOJ24= X-Google-Smtp-Source: AGHT+IHVWibp8A7lBjfCEb7txT3MpCcbRj8C5pR4YRrzBRfP8Yp05u30F7lsXNQo0p4cckGT3KL1vg== X-Received: by 2002:a05:6830:32aa:b0:6bc:88da:af44 with SMTP id m42-20020a05683032aa00b006bc88daaf44mr2796752ott.6.1693581626540; Fri, 01 Sep 2023 08:20:26 -0700 (PDT) Received: from nathanxps13 ([2600:1700:48f8:340f:ed2c:b641:352b:afe1]) by smtp.gmail.com with ESMTPSA id g23-20020a9d6b17000000b006ba864f5b37sm1887985otp.12.2023.09.01.08.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 08:20:25 -0700 (PDT) Date: Fri, 1 Sep 2023 08:20:24 -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: <20230901152024.GA3175143@nathanxps13> References: <20230614215744.ddeuii7jcojbp3yv@awork3.anarazel.de> <20230614223012.cfyzxyfnt3ggqkt4@awork3.anarazel.de> <20230812004812.4yev47iili57u4hc@awork3.anarazel.de> <20230901025613.GB3097511@nathanxps13> 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 12:31:09PM +0900, Michael Paquier wrote: > On Thu, Aug 31, 2023 at 07:56:13PM -0700, Nathan Bossart wrote: >> On Fri, Sep 01, 2023 at 10:08:57AM +0900, Michael Paquier wrote: >>> + /* >>> + * 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. > > Yeah, this could be a bit more detailed, mentioning the dependency > with the pgstat shutdown callback. How about appending the following > sentence in a second paragraph, say: > "Setting MyDatabaseId after rechecking the existence of the database > matters for instance with the shutdown callback of the shared > statistics, as pgstat_report_stat() will update database statistics > depending on MyDatabaseId." Something along those lines seems fine to me. FWIW this is what I had in my head: It is important that MyDatabaseId only be set once we are sure that the target database can no longer be concurrently dropped or renamed. Some code depends on this. For example, without this guarantee, pgstat_update_dbstats() could create entries for databases that were just dropped, which will lead to problems down the road. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com