From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Abhishek Bhola <abhishek.bhola@japannext.co.jp>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Why are data files getting modified?
Date: Wed, 09 Feb 2022 16:14:05 +0100
Message-ID: <a256d775a579976d7895248fed6f5ca101a4d4a4.camel@cybertec.at> (raw)
In-Reply-To: <CAEDsCziKEg2QPjymV4z_znaB8nR8=2pFwW534kQtrpui7hYRbw@mail.gmail.com>
References: <CAEDsCziKEg2QPjymV4z_znaB8nR8=2pFwW534kQtrpui7hYRbw@mail.gmail.com>
On Wed, 2022-02-09 at 17:29 +0900, Abhishek Bhola wrote:
> I have a table with monthly partitions, starting from 2011.
> Each partition has about 2-3 billion rows and is about 40TB of data in total.
> I am running a select query to \copy the data into csv files for each month.
>
> I see there is an AUTOVACUUM job started on all the partitions that have been
> read (on which select has run). I am assuming the reason why Postgres is
> autovacuuming these large partitions is this:
>
> db=# SELECT c.relname as table_name, c.relkind as type, age(c.relfrozenxid) as age,
> c.relfrozenxid FROM pg_class AS c WHERE age(c.relfrozenxid) <> 2147483647 ORDER BY 3 DESC LIMIT 20;
> table_name | type | age | relfrozenxid
> ---------------------------+------+-----------+--------------
> hist_omx_orderaudit201506 | r | 201463508 | 319891
> hist_omx_orderaudit201509 | r | 201418497 | 364902
> hist_omx_orderaudit201205 | r | 201142042 | 641357
>
> autovacuum_freeze_max_age
> ---------------------------
> 200000000
> (1 row)
>
> Am I wrong in my understanding why this autovacuum is getting triggered?
>
> However, my main question is that why do the data files in the tablespace, corresponding
> to these partition tables (that have been read or selected recently), or the ones
> autovacuumed recently have a latest timestamp?
>
> There was no insert or update on these partitions, so why do I see an updated timestamp?
> Does autovacuum change something on the datafiles?
Yes, autovacuum will freeze old rows in the table, which modifies the data files.
To keep this to a minimum, you can run VACUUM (FREEZE) on a partition as soon
as you know that its data won't get modified any more.
Still, I wouldn't be sure that the file modification timestamp won't change
any more after that. But that should be pretty irrelevant; at any rate, no
substantial data modifications will occur after that.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: laurenz.albe@cybertec.at, abhishek.bhola@japannext.co.jp
Subject: Re: Why are data files getting modified?
In-Reply-To: <a256d775a579976d7895248fed6f5ca101a4d4a4.camel@cybertec.at>
References: <CAEDsCziKEg2QPjymV4z_znaB8nR8=2pFwW534kQtrpui7hYRbw@mail.gmail.com> <a256d775a579976d7895248fed6f5ca101a4d4a4.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox