pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Arctic Toucan <arctic_toucan@hotmail.com>
To: pgsql-admin@postgresql.org
Subject: Is it safe to reset relfrozenxid without using vacuum?
Date: Tue, 18 Nov 2008 10:40:26 -0500
Message-ID: <BAY126-W258E8EA30779618A479BFE9C120@phx.gbl> (raw)


I have a heavily partitioned DW type database that has over 5,000 tables in it. Data is only ever inserted, read and then truncated after some period of time. Once the table is truncated, the constraints are changed and the table is reused. This works well until Postgres hits the autovacuum_freeze_max_age, which I currently have set @ 1billion). Since these tables are only ever inserted to and truncated, they are not normally vacuumed(which is what I want, since data is typically going to be truncated before needing to be vacuumed). 
Unfortunately, since truncate does not change the relfrozenxid, once the autovacuum_freeze_max_age is reached, suddenly all tables in the schema need vacuuming at once. When this occurs, the autovacuum process gives priority to vacuuming all the tables(2TB+ of data), and query performance degenerates. More significantly, as new data comes into emptied partition tables they are not analyzed in a timely fashion and very poor query plans result. The DB remains in this vacuuming state for up to 3 weeks. 
 
What I would like to do, is just vacuum the table when the truncate code is executed(This is currently done using PGSql functions), but I can't issue the vacuum call from within a transaction. Given that, I was wondering if it is "safe" to update pg_class directly for the table being truncated with a query like:
 
UPDATE pg_class SET relfrozenxid = ( select relfrozenxid from pg_class where age(relfrozenxid) in (select min(age(relfrozenxid)) from pg_class where relkind = 'r') limit 1) WHERE relname = '<table being truncated>';
 
Is there a better way of doing this? 
 
For that matter, would it be reasonable to have the relfrozenxid reset on a successful truncate?
 
I am running Postgres 8.2.4
 
Regards...Mark Sherwood 
_________________________________________________________________

view thread (6+ messages)  latest in thread

Message-ID: <BAY126-W258E8EA30779618A479BFE9C120@phx.gbl>
Permalink:  ../BAY126-W258E8EA30779618A479BFE9C120@phx.gbl/
Also on:    postgresql.org/message-id/BAY126-W258E8EA30779618A479BFE9C120@phx.gbl

 · 

reply

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-admin@postgresql.org
  Cc: arctic_toucan@hotmail.com
  Subject: Re: Is it safe to reset relfrozenxid without using vacuum?
  In-Reply-To: <BAY126-W258E8EA30779618A479BFE9C120@phx.gbl>
  References: <BAY126-W258E8EA30779618A479BFE9C120@phx.gbl>

* 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