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 1nHogk-0001m9-Qj for pgsql-general@arkaria.postgresql.org; Wed, 09 Feb 2022 15:15:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nHogj-0007Nf-Q0 for pgsql-general@arkaria.postgresql.org; Wed, 09 Feb 2022 15:15:21 +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 1nHofZ-0000jU-Uz for pgsql-general@lists.postgresql.org; Wed, 09 Feb 2022 15:14:09 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nHofX-0000bt-Dm for pgsql-general@postgresql.org; Wed, 09 Feb 2022 15:14:09 +0000 Received: by mail-ej1-x633.google.com with SMTP id ka4so8166244ejc.11 for ; Wed, 09 Feb 2022 07:14:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=6du0+qCMGawCzZDntaz6s6/pB9r4IztOCUuFPLipzx0=; b=Ak7mUc6qjwP84Ipb4pp0zxwAOD4XC4e6wI1pPchfgtSgcKq6FzwxriM6hp6UoclAOk VJkiKSZKGjpTZIfdWo6duefPFJ5BWK7HU0+V4NPRuClvnudB7pNW6fZCuXIUmBDcbiGd kZ4vBq4HZN6Y8Ad2srlq6nNOD97hVXXz9O5WjGn3TjKa5Xd/R/G4SUwyNCrWnqzIQWqk 5N27Jx4os/qXW7FeGx/ixqGBwU3tUunyEvJw96dKjZ2ithMEiUemmd47gkTe+T0Ym00S ZzYud6dCckRPN9e994K8KTtDW1MKT/iKZ/5LgINGg7lQ/SrdkyAbUFSJSHKRdjzyInFm tH4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=6du0+qCMGawCzZDntaz6s6/pB9r4IztOCUuFPLipzx0=; b=EbUugDjV/1DKe6jDFcOSHFZt51CiSHIMzNWhYE6QwulYNh1iMqLpVWWG778MGxPrdC W9y6ejgFdcPEKIcczFkBJNPkZ1GQy7TNkDVXskq7GKmAhrrhQib7KViwDFztvu1Vf4K8 eIFgcF/qe0eixacfmALnYMW3wCGjsnL/zEpp+88N0mP3nq74cQ7wSAP6bKS7ALKXf4Tn FVCo/lZXLXr3sWs4phZUzAqkQeiSSOwkAwmCpQrBc2w6L2LqJHXc96Y7eV3gv6Y1MMqJ v2Xu5ixWW8KURwKWHwilSMtCriJzzA6jKU/Ru0SXL+o87p64kgLtYy1wUTFPXjszCild 45xg== X-Gm-Message-State: AOAM533YxCKwwOE+j592nlwzlMCSXTdFqINS9ZsgXUgIVpoyb5e0W8yg Zmqtk04QyC2gU/5lG4UoDA28Og== X-Google-Smtp-Source: ABdhPJwILrxfntQnOG6plSZqydiAAmNdwXXo4WWYjuC6B743k+YyLlreT1/BPrsgx2GBjXU5WPHT5g== X-Received: by 2002:a17:906:7a49:: with SMTP id i9mr2441085ejo.562.1644419646414; Wed, 09 Feb 2022 07:14:06 -0800 (PST) Received: from localhost.localdomain ([2001:871:5e:cd6a:dc37:5b3a:6c66:7f20]) by smtp.gmail.com with ESMTPSA id g15sm2310981edz.100.2022.02.09.07.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 07:14:05 -0800 (PST) Message-ID: Subject: Re: Why are data files getting modified? From: Laurenz Albe To: Abhishek Bhola , pgsql-general Date: Wed, 09 Feb 2022 16:14:05 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-2.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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