Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pHQX6-0001ol-FN for pgsql-general@arkaria.postgresql.org; Mon, 16 Jan 2023 14:32:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pHQX4-0007B0-A7 for pgsql-general@arkaria.postgresql.org; Mon, 16 Jan 2023 14:32:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pHQX3-0007Ar-W5 for pgsql-general@lists.postgresql.org; Mon, 16 Jan 2023 14:32:17 +0000 Received: from mout-u-204.mailbox.org ([80.241.59.204]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pHQX1-00009P-IZ for pgsql-general@lists.postgresql.org; Mon, 16 Jan 2023 14:32:17 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4NwZGw0zGbz9sQ3; Mon, 16 Jan 2023 15:32:08 +0100 (CET) Date: Mon, 16 Jan 2023 15:32:07 +0100 (CET) From: Erik Wienhold To: Fred Habash , pgsql-general@lists.postgresql.org Message-ID: <519914442.284548.1673879527496@office.mailbox.org> In-Reply-To: References: Subject: Re: Why is a Read-only Table Gets Autovacuumed "to prevent wraparound" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 16/01/2023 13:48 CET Fred Habash wrote: > > This is a puzzle I have not been able to crack yet. > > We have a single-page table with 28 rows that is purely read-only. There = isn't > a way in postgres to make a table RO, but I say this with confidence beca= use >=C2=A0pg_stat_user_tables has always showed 0 updates/deletes/inserts. > > Furthermore, the schema app developers know, for certain, this table does= not > get changed at all. Only way to ensure that is to have database users other than the table owne= rs or superusers connect from your app. Then you can GRANT the absolute neces= sary privileges like SELECT for read-only access. > We installed scripts that run every few minutes that do a 'select *' and = over > a period of days, we have not seen a change. > > We disabled autovacuum on this table '{autovacuum_enabled=3Dfalse}'. But, > despite the fact that this table is read-only (by design) and autovac id = is > disabled, it got autovac'd twice in less than=C2=A010 days and on both oc= casions, > pg_stat_activity showed the worker with 'to prevent wraparound'. This exp= lains > why autovac did not honor the disabled status. > > But why is this table autovac'd=C2=A0at all? Wraparound protection is always performed even if autovacuum is disabled: https://www.postgresql.org/docs/current/routine-vacuuming.html#VACUUM-FOR-W= RAPAROUND > I have a hypothesis, but I need it validated and may be indicate if it is > scientifically plausible. It goes like this ... > > 1. Application initiates a T1 transaction > 2. App. reads multiple tables to get product metadata and this small tabl= e is > one of them. > 3. At some point, app. locks a row on one of the tables (not the small on= e). > 4. Client app. keeps session 'idle in transaction' while it refreshes a > webpage to render the data. > 4. Once the client app verifies the web app has rendered the data correct= ly, > it comes back to the database to finish the transaction. > > So, even if the small table is never changed, it is part of a transaction= to > be queried. Will this use-case cause the table to qualify for an aggressi= ve > autovac to prevent wraparound. > > If not, why else is a table with zero DML changes ever gets=C2=A0autovac'= d? -- Erik