Re: Thousands of schemas and ANALYZE goes out of memory

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: Hugo <hugo(dot)tech(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Thousands of schemas and ANALYZE goes out of memory
Date: 2012-10-04 23:14:31
Message-ID: 7110.1349392471@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeff Janes <jeff(dot)janes(at)gmail(dot)com> writes:
> For the record, the culprit that causes "analyze;" of a database with
> a large number of small objects to be quadratic in time is
> "get_tabstat_entry" and it is not fixed for 9.3.

I was a bit surprised by this assertion, as I'd thought that tabstats
were flushed to the collector at transaction end, and thus that the
internal transaction boundaries in a VACUUM or ANALYZE should prevent
the tabstats table from getting unreasonably large. However, a look
at the code shows that pgstat_report_stat() is only called when the main
loop in postgres.c is about to wait for client input.

We could build a lot of infrastructure to try to index the tabstat
arrays more efficiently ... or we could just do something like the
attached.

It appears that the next tallest mole in the VACUUM case is
CleanupTempFiles. This workload is not creating any temp files, I hope,
so the implication is that have_pending_fd_cleanup is getting set by
FileSetTransient (probably from blind writes). We might want to revisit
how that works --- particularly since I see no reason that there would
be any actually-blind writes in this example. But in any case, that
innocent looking flag setting can result in a lot of work.

regards, tom lane

Attachment Content-Type Size
dump-stats-during-vacuum-or-analyze.patch text/x-patch 1.1 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Moshe Jacobson 2012-10-05 02:53:09 Re: Re: What's faster? BEGIN ... EXCEPTION or CREATE TEMP TABLE IF NOT EXISTS?
Previous Message Bruce Momjian 2012-10-04 21:06:56 Re: pg_upgrade default ports in the --help output