Unix Technical Forum

Heavy write activity on first vacuum of fresh TOAST data

This is a discussion on Heavy write activity on first vacuum of fresh TOAST data within the Pgsql Performance forums, part of the PostgreSQL category; --> >>> On Thu, Dec 13, 2007 at 10:11 AM, in message <1197562283.4255.1829.camel@ebony.site>, Simon Riggs <simon@2ndquadrant.com> wrote: > On Thu, ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

 

LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 04-19-2008, 11:43 AM
Kevin Grittner
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of freshTOAST data

>>> On Thu, Dec 13, 2007 at 10:11 AM, in message
<1197562283.4255.1829.camel@ebony.site>, Simon Riggs <simon@2ndquadrant.com>
wrote:
> On Thu, 2007-12-13 at 09:46 -0600, Kevin Grittner wrote:
>
>> The data was inserted through a Java program using a prepared
>> statement with no indexes on the table. The primary key was then
>> added, and now I've started a vacuum. The new table wound up being
>> the first big table vacuumed, and I noticed something odd. Even
>> though there have been no rollbacks, updates, or deletes on this
>> table, the vacuum is writing as much as it is reading while dealing
>> with the TOAST data.

>
> Writing hint bits. Annoying isn't it? :-(


Is there anything in the documentation that mentions this pattern
of activity? Since I started clearing the WAL file tails before
compression, it has surprised me how much WAL file activity there
is from the nightly vacuum. I had assumed that some part of this
was freezing old tuples, but that didn't seem to exactly match the
pattern of activity. If the hint bit changes are written to the
WAL, I think this explains it.

Maybe this too arcane for the docs, but I'm not so sure.
Effectively, it means that every new tuple which has much of a
lifespan has to be written at least three times, if I'm
understanding you: once during the database transaction which
creates it, once in the first subsequent vacuum of that table to
flag that it was committed, and again when it reaches the freeze
threshold to prevent transaction number wraparound.

That last one could be sort of a surprise for someone at some
point after, say, restoring from pg_dump, couldn't it? Would it
make any kind of sense for a person to do the first vacuum after
a bulk load using the FREEZE keyword (or the more recent
equivalent setting)?

-Kevin



---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 04-19-2008, 11:43 AM
Simon Riggs
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of fresh TOASTdata

On Thu, 2007-12-13 at 11:46 -0600, Kevin Grittner wrote:
> >>> On Thu, Dec 13, 2007 at 10:11 AM, in message

> <1197562283.4255.1829.camel@ebony.site>, Simon Riggs <simon@2ndquadrant.com>
> wrote:
> > On Thu, 2007-12-13 at 09:46 -0600, Kevin Grittner wrote:
> >
> >> The data was inserted through a Java program using a prepared
> >> statement with no indexes on the table. The primary key was then
> >> added, and now I've started a vacuum. The new table wound up being
> >> the first big table vacuumed, and I noticed something odd. Even
> >> though there have been no rollbacks, updates, or deletes on this
> >> table, the vacuum is writing as much as it is reading while dealing
> >> with the TOAST data.

> >
> > Writing hint bits. Annoying isn't it? :-(

>
> Is there anything in the documentation that mentions this pattern
> of activity? Since I started clearing the WAL file tails before
> compression, it has surprised me how much WAL file activity there
> is from the nightly vacuum. I had assumed that some part of this
> was freezing old tuples, but that didn't seem to exactly match the
> pattern of activity. If the hint bit changes are written to the
> WAL, I think this explains it.


They're not.

--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 04-19-2008, 11:43 AM
Tom Lane
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of fresh TOAST data

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> Simon Riggs wrote:
>> We might be able to have bgwriter set hint bits on dirty blocks,


> I don't think that works, because the bgwriter has no access to the
> catalogs, therefore it cannot examine the page contents. To bgwriter,
> pages are opaque.


Another issue is that this'd require bgwriter to access the clog SLRU
area. I seem to remember worrying that that could lead to low-level
deadlocks, though I cannot recall the exact case at the moment.
Even without that, it would increase contention for SLRU, which we
probably don't want.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 04-19-2008, 11:43 AM
Simon Riggs
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of fresh TOASTdata

On Thu, 2007-12-13 at 13:52 -0500, Tom Lane wrote:
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> > Simon Riggs wrote:
> >> We might be able to have bgwriter set hint bits on dirty blocks,

>
> > I don't think that works, because the bgwriter has no access to the
> > catalogs, therefore it cannot examine the page contents. To bgwriter,
> > pages are opaque.

>
> Another issue is that this'd require bgwriter to access the clog SLRU
> area. I seem to remember worrying that that could lead to low-level
> deadlocks, though I cannot recall the exact case at the moment.
> Even without that, it would increase contention for SLRU, which we
> probably don't want.


I was trying to highlight the problems, not advocate that as an
approach, sorry if I wasn't clear enough. Even if you solved the
problems both of you have mentioned I don't think the dynamic behaviour
will be useful enough to merit the effort of trying. I'm definitely not
going to be spending any time on this. Fish are frying elsewhere.

--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 04-19-2008, 11:43 AM
Kevin Grittner
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of freshTOAST data

>>> On Thu, Dec 13, 2007 at 12:12 PM, in message
<1197569564.4255.1855.camel@ebony.site>, Simon Riggs <simon@2ndquadrant.com>
wrote:
> On Thu, 2007-12-13 at 11:46 -0600, Kevin Grittner wrote:
>> If the hint bit changes are written to the WAL ...

>
> They're not.


So one would expect a write-intensive initial vacuum after a
PITR-style recovery?

What impact would lack of the hint bits have until a vacuum?

-Kevin




---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 04-19-2008, 11:43 AM
Simon Riggs
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of fresh TOASTdata

On Thu, 2007-12-13 at 15:19 -0600, Kevin Grittner wrote:
> >>> On Thu, Dec 13, 2007 at 12:12 PM, in message

> <1197569564.4255.1855.camel@ebony.site>, Simon Riggs <simon@2ndquadrant.com>
> wrote:
> > On Thu, 2007-12-13 at 11:46 -0600, Kevin Grittner wrote:
> >> If the hint bit changes are written to the WAL ...

> >
> > They're not.

>
> So one would expect a write-intensive initial vacuum after a
> PITR-style recovery?


Very perceptive. I was just thinking about that myself. An interesting
issue when running with full_page_writes off.

> What impact would lack of the hint bits have until a vacuum?


Vacuum isn't important here. Its the first idiot to read the data that
gets hit.

--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com


---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 04-19-2008, 11:43 AM
Kevin Grittner
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of freshTOAST data

>>> On Thu, Dec 13, 2007 at 3:40 PM, in message
<1197582010.4255.1912.camel@ebony.site>, Simon Riggs <simon@2ndquadrant.com>
wrote:
> On Thu, 2007-12-13 at 15:19 -0600, Kevin Grittner wrote:
>> >>> On Thu, Dec 13, 2007 at 12:12 PM, in message

>> <1197569564.4255.1855.camel@ebony.site>, Simon Riggs <simon@2ndquadrant.com>
>> wrote:
>> > On Thu, 2007-12-13 at 11:46 -0600, Kevin Grittner wrote:
>> >> If the hint bit changes are written to the WAL ...
>> >
>> > They're not.

>>
>> So one would expect a write-intensive initial vacuum after a
>> PITR-style recovery?

>
> Very perceptive. I was just thinking about that myself. An interesting
> issue when running with full_page_writes off.
>
>> What impact would lack of the hint bits have until a vacuum?

>
> Vacuum isn't important here. Its the first idiot to read the data that
> gets hit.


OK, I want to understand this well enough to recognize it when I
see it. (As always, I appreciate the helpful answers here.)

Assuming no data is toasted, after a bulk INSERT or COPY into the
database, a subsequent SELECT COUNT(*) would figure out the correct
hint bits and rewrite all rows during execution of the SELECT
statement?

The same is true following a PITR-style recovery?

Toasted data would not be rewritten unless accessed (whether that
be for selection criteria, sort order, results, or whatever)?

A database VACUUM is going to run into every page not previously
accessed and make all hint bits correct?

Would a VACUUM FREEZE of a bulk-loaded table do one write for both
the hint bits and the transaction ID? (I know that hackers
generally prefer that people leave the transaction IDs unfrozen
for a long time to aid in debugging problems, but that seems less
useful in a large table which has just been bulk-loaded, true?)

-Kevin



---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 04-19-2008, 11:43 AM
Russell Smith
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of fresh TOASTdata

Simon Riggs wrote:
> On Thu, 2007-12-13 at 15:19 -0600, Kevin Grittner wrote:
>
>> What impact would lack of the hint bits have until a vacuum?
>>

>
> Vacuum isn't important here. Its the first idiot to read the data that
> gets hit.
>
>

Given vacuum must then touch every page, is there a win in only setting
hint bits on pages where vacuum has to do some other work on the page?
As vacuum is causing significant IO load for data that may not be
accessed for some time.

The question becomes what is the impact of not setting hint bits? Is it
better or worse than the IO caused by vacuum?

Regards

Russell Smith

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 04-19-2008, 11:43 AM
Tom Lane
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of fresh TOAST data

Russell Smith <mr-russ@pws.com.au> writes:
> Given vacuum must then touch every page, is there a win in only setting
> hint bits on pages where vacuum has to do some other work on the page?
> As vacuum is causing significant IO load for data that may not be
> accessed for some time.


Well, if vacuum doesn't do it then some other poor sod will have to.

My feeling is that vacuum's purpose in life is to offload maintenance
cycles from foreground queries, so we should be happy to have it setting
all the hint bits. If Kevin doesn't like the resultant I/O load then he
should use the vacuum_cost_delay parameters to dial down vacuum speed.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 04-19-2008, 11:43 AM
Kevin Grittner
 
Posts: n/a
Default Re: Heavy write activity on first vacuum of freshTOAST data

>>> On Fri, Dec 14, 2007 at 1:42 AM, in message <29185.1197618162@sss.pgh.pa.us>,
Tom Lane <tgl@sss.pgh.pa.us> wrote:

> My feeling is that vacuum's purpose in life is to offload maintenance
> cycles from foreground queries, so we should be happy to have it setting
> all the hint bits.


Absolutely.

> If Kevin doesn't like the resultant I/O load then he
> should use the vacuum_cost_delay parameters to dial down vacuum speed.


It's not that I don't like it -- I'm often called upon to diagnose
issues, and understanding the dynamics of things like this helps me
interpret what I'm seeing. No complaint here.

-Kevin




---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:59 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com