pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Vacuum Question
33+ messages / 20 participants
[nested] [flat]

* Vacuum Question
@ 2000-06-01 09:17 brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:32 ` Re: Vacuum Question Bruce Momjian <pgman@candle.pha.pa.us>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 33+ messages in thread

From: brianb @ 2000-06-01 09:17 UTC (permalink / raw)
  To: pgsql-general


I have a Postgres application that must run 24x7. If postgres needs to be
vacuumed periodically, must I take the application offline completely, or
is it enough to disallow write (INSERT/UPDATE) access while allowing read
access?

I hope it is the latter, as I have a large amount of data and there are
transactions going on all the time.

Brian
--
Brian Baquiran <brianb@edsamail.com>
http://www.baquiran.com/
AIM: bbaquiran



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
@ 2000-06-02 05:32 ` Bruce Momjian <pgman@candle.pha.pa.us>
  1 sibling, 0 replies; 33+ messages in thread

From: Bruce Momjian @ 2000-06-02 05:32 UTC (permalink / raw)
  To: brianb <brianb-pggeneral@evoserve.com>; +Cc: pgsql-general

[ Charset ISO-8859-1 unsupported, converting... ]
> 
> I have a Postgres application that must run 24x7. If postgres needs to be
> vacuumed periodically, must I take the application offline completely, or
> is it enough to disallow write (INSERT/UPDATE) access while allowing read
> access?
> 
> I hope it is the latter, as I have a large amount of data and there are
> transactions going on all the time.

Applications will hang until the vacuum is completed.  No changes
required.


-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
@ 2000-06-02 05:43 ` Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  1 sibling, 1 reply; 33+ messages in thread

From: Tom Lane @ 2000-06-02 05:43 UTC (permalink / raw)
  To: brianb <brianb-pggeneral@evoserve.com>; +Cc: pgsql-general

"brianb" <brianb-pggeneral@evoserve.com> writes:
> I have a Postgres application that must run 24x7. If postgres needs to be
> vacuumed periodically, must I take the application offline completely, or
> is it enough to disallow write (INSERT/UPDATE) access while allowing read
> access?

You're wasting your time to think of allowing or disallowing access;
VACUUM is quite capable of locking out other accesses without help ;-)

The short answer is that a table being vacuumed is locked against any
other access, read or write; but only that one table.  You might as
well leave the rest of the database open for use.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
@ 2000-06-02 14:44   ` Ed Loehr <eloehr@austin.rr.com>
  2000-06-02 15:11     ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 33+ messages in thread

From: Ed Loehr @ 2000-06-02 14:44 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: brianb <brianb-pggeneral@evoserve.com>; pgsql-general

Tom Lane wrote:
> 
> "brianb" <brianb-pggeneral@evoserve.com> writes:
> > I have a Postgres application that must run 24x7. If postgres needs to be
> > vacuumed periodically, must I take the application offline completely, or
> > is it enough to disallow write (INSERT/UPDATE) access while allowing read
> > access?
> 
> The short answer is that a table being vacuumed is locked against any
> other access, read or write; but only that one table.  You might as
> well leave the rest of the database open for use.

I take it you don't give much credence to the previous reports that
concurrently writing during vacuuming caused corruption?  Was that a
previous problem that's fixed now?

Regards,
Ed Loehr



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
@ 2000-06-02 15:11     ` Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 06:05       ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Tom Lane @ 2000-06-02 15:11 UTC (permalink / raw)
  To: Ed Loehr <eloehr@austin.rr.com>; +Cc: pgsql-general

Ed Loehr <eloehr@austin.rr.com> writes:
>> The short answer is that a table being vacuumed is locked against any
>> other access, read or write; but only that one table.  You might as
>> well leave the rest of the database open for use.

> I take it you don't give much credence to the previous reports that
> concurrently writing during vacuuming caused corruption?

No, not really, for the simple reason that there aren't going to *be*
any concurrent writes (or reads either) during a vacuum ... unless our
table locking system fails, in which case we've got lots worse problems
than vacuum.

There are scenarios involving known (and fixed!) bugs that might be
stressed by vacuum running concurrently with operations on other tables.
I'm thinking particularly of shared cache invalidation: a vacuum on a
system table will spit out a lot of SI messages for the tuples it moves
around, and it used to be that we had bugs that could be triggered by
SI buffer overflow, or more accurately by the cache flush that's used to
recover from SI overflow.  (Those bugs seem to be fixed in 7.0.  I've
successfully run parallel regression tests with the SI buffer reduced to
a mere dozen messages or so.  It spits out an impressive number of "SI
buffer overflow" notices, but keeps going...)

If you are feeling conservative you might want to vacuum just selected
user tables during normal usage, and do a database-wide vacuum only at
low load --- if there are any low-probability bugs still lurking in
there, they're almost surely things that would be triggered by system
table vacuums and not user-table vacuums.  That'd probably be a good
idea for performance reasons anyway, since locking a system table is
much more likely to block other backends than locking any one user
table.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-02 15:11     ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
@ 2000-06-06 06:05       ` Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 06:12         ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 06:18         ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  0 siblings, 2 replies; 33+ messages in thread

From: Ed Loehr @ 2000-06-06 06:05 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general

Tom Lane wrote:
> 
> Ed Loehr <eloehr@austin.rr.com> writes:
> >> The short answer is that a table being vacuumed is locked against any
> >> other access, read or write; but only that one table.  You might as
> >> well leave the rest of the database open for use.
> 
> > I take it you don't give much credence to the previous reports that
> > concurrently writing during vacuuming caused corruption?
> 
> No, not really, for the simple reason that there aren't going to *be*
> any concurrent writes (or reads either) during a vacuum ... unless our
> table locking system fails, in which case we've got lots worse problems
> than vacuum.

On my way to some performance testing I ran into this repeatable crash
scenario.  Just wondering if anyone else can reproduce the same or
explain what is happening.  Could very well be something peculiar/buggy
about the bash/perl commands...

First, start up this rather obfuscated perl/bash command which just
inserts random records forever...

%  createdb pdb; psql -d pdb -c "create table foo(id serial, t timestamp
not null default current_timestamp, f float, s varchar, i integer, l
int8);"; perl -e 'for (my $j = 0; $j < 10000000; $j++ ) { print "--
Insert #$j\n"; $f = rand(2000000); $i = int(rand(2000000)) % 16000; $l =
int(rand(2000000000)); $s = chr(65 + int(rand(20))) x int(rand(128));
$delim = chr(39); print "insert into foo (f,s,i,l) values ($f,
$delim${s}$delim, $i, $l);\n"; }' | psql -d pdb

Then, start this one in another bash window/terminal/whatever...

% while test 1; do echo -n "`date`: "; psql -d pdb -c "vacuum analyze;
select count(*) from foo;"; sleep 3; done

This seems to consistently crash after the first vacuum with the
following message:

NOTICE:  Message from PostgreSQL backend:
        The Postmaster has informed me that some other backend died
abnormally and possibly corrupted shared memory.
        I have rolled back the current transaction and am going to
terminate your database system connection and exit.
        Please reconnect to the database system and repeat your query.
pqReadData() -- backend closed the channel unexpectedly.
        This probably means the backend terminated abnormally
        before or while processing the request.
connection to server was lost


Regards,
Ed Loehr



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-02 15:11     ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 06:05       ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
@ 2000-06-06 06:12         ` Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 07:18           ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 33+ messages in thread

From: Ed Loehr @ 2000-06-06 06:12 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general

Ed Loehr wrote:
> 
> Tom Lane wrote:
> >
> > Ed Loehr <eloehr@austin.rr.com> writes:
> > >> The short answer is that a table being vacuumed is locked against any
> > >> other access, read or write; but only that one table.  You might as
> > >> well leave the rest of the database open for use.
> >
> > > I take it you don't give much credence to the previous reports that
> > > concurrently writing during vacuuming caused corruption?
> >
> > No, not really, for the simple reason that there aren't going to *be*
> > any concurrent writes (or reads either) during a vacuum ... unless our
> > table locking system fails, in which case we've got lots worse problems
> > than vacuum.
> 
> On my way to some performance testing I ran into this repeatable crash
> scenario.  Just wondering if anyone else can reproduce the same or
> explain what is happening.  Could very well be something peculiar/buggy
> about the bash/perl commands...
> 
> First, start up this rather obfuscated perl/bash command which just
> inserts random records forever...
> 
> %  createdb pdb; psql -d pdb -c "create table foo(id serial, t timestamp
> not null default current_timestamp, f float, s varchar, i integer, l
> int8);"; perl -e 'for (my $j = 0; $j < 10000000; $j++ ) { print "--
> Insert #$j\n"; $f = rand(2000000); $i = int(rand(2000000)) % 16000; $l =
> int(rand(2000000000)); $s = chr(65 + int(rand(20))) x int(rand(128));
> $delim = chr(39); print "insert into foo (f,s,i,l) values ($f,
> $delim${s}$delim, $i, $l);\n"; }' | psql -d pdb

Sorry...word-wrap killed that one's cut-n-paste-ability...try this if
you're interested:

createdb pdb; 
psql -d pdb -c "create table foo(
	id serial, 
	t timestamp not null default current_timestamp, 
	f float, 
	s varchar, 
	i integer, 
	l int8);";
perl -e 'for (my $j = 0; $j < 10000000; $j++ ) { 
	print "-- Insert #$j\n"; 
	$f = rand(2000000); 
	$i = int(rand(2000000)) % 16000; 
	$l = int(rand(2000000000)); 
	$s = chr(65 + int(rand(20))) x int(rand(128));
	$delim = chr(39); 
	print "insert into foo (f,s,i,l) values \n";
	print "($f, $delim${s}$delim, $i, $l);\n"; }' | psql -d pdb
> 
> Then, start this one in another bash window/terminal/whatever...
> 
> % while test 1; do echo -n "`date`: "; psql -d pdb -c "vacuum analyze;
> select count(*) from foo;"; sleep 3; done
> 
> This seems to consistently crash after the first vacuum with the
> following message:
> 
> NOTICE:  Message from PostgreSQL backend:
>         The Postmaster has informed me that some other backend died
> abnormally and possibly corrupted shared memory.
>         I have rolled back the current transaction and am going to
> terminate your database system connection and exit.
>         Please reconnect to the database system and repeat your query.
> pqReadData() -- backend closed the channel unexpectedly.
>         This probably means the backend terminated abnormally
>         before or while processing the request.
> connection to server was lost
> 
> Regards,
> Ed Loehr



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-02 15:11     ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 06:05       ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 06:12         ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
@ 2000-06-06 07:18           ` Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 14:17             ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Tom Lane @ 2000-06-06 07:18 UTC (permalink / raw)
  To: Ed Loehr <eloehr@austin.rr.com>; +Cc: pgsql-general

Ed Loehr <eloehr@austin.rr.com> writes:
>> Then, start this one in another bash window/terminal/whatever...
>> 
>> % while test 1; do echo -n "`date`: "; psql -d pdb -c "vacuum analyze;
>> select count(*) from foo;"; sleep 3; done
>> 
>> This seems to consistently crash after the first vacuum with the
>> following message:

This is a known gotcha that's got nothing to do with any sort of
concurrency.  You can't safely send a VACUUM followed by anything
else in a single query string.  The problem is that VACUUM forces a
transaction commit, which releases all transiently allocated memory
in its backend ... including the already-parsed querytrees for the
rest of the query string.  Oops.  (cf. comment near line 560 in
src/backend/tcop/postgres.c)

You won't see the problem if you enter "vacuum analyze; select ..."
interactively or as a script in psql, because it chops up the
commands into separate query submittals.  But apparently psql
doesn't chop up a -c string.  Non-psql frontends can expose the bug
as well.

It's possible that this will get cleaned up as a byproduct of the
proposed rework of transaction-local memory contexts.  But it's
not a real high-priority problem, at least not IMHO.  For now,
the answer is "if it hurts, don't do it ;-)"

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-02 15:11     ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 06:05       ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 06:12         ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 07:18           ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
@ 2000-06-06 14:17             ` Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 17:53               ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 33+ messages in thread

From: Ed Loehr @ 2000-06-06 14:17 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general

Tom Lane wrote:
> 
> Ed Loehr <eloehr@austin.rr.com> writes:
> >> Then, start this one in another bash window/terminal/whatever...
> >>
> >> % while test 1; do echo -n "`date`: "; psql -d pdb -c "vacuum analyze;
> >> select count(*) from foo;"; sleep 3; done
> >>
> >> This seems to consistently crash after the first vacuum with the
> >> following message:
> 
> This is a known gotcha that's got nothing to do with any sort of
> concurrency.  You can't safely send a VACUUM followed by anything
> else in a single query string.  

Well, I thought that select count(*) might've been causing a problem, so
I experimented without it and found the same problem.  Doesn't seem to
happen with 'vacuum'or 'vacuum analyze foo', only 'vacuum analyze'...

Regards,
Ed Loehr



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-02 15:11     ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 06:05       ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 06:12         ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 07:18           ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 14:17             ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
@ 2000-06-06 17:53               ` Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 18:20                 ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Tom Lane @ 2000-06-06 17:53 UTC (permalink / raw)
  To: Ed Loehr <eloehr@austin.rr.com>; +Cc: pgsql-general

Ed Loehr <eloehr@austin.rr.com> writes:
>>>>> % while test 1; do echo -n "`date`: "; psql -d pdb -c "vacuum analyze;
>>>>> select count(*) from foo;"; sleep 3; done
>>>>> 
>>>>> This seems to consistently crash after the first vacuum with the
>>>>> following message:
>> 
>> This is a known gotcha that's got nothing to do with any sort of
>> concurrency.  You can't safely send a VACUUM followed by anything
>> else in a single query string.  

> Well, I thought that select count(*) might've been causing a problem, so
> I experimented without it and found the same problem.  Doesn't seem to
> happen with 'vacuum'or 'vacuum analyze foo', only 'vacuum analyze'...

I can't reproduce any problem with just a "vacuum" (with or without
analyze) and no following command.

I did, however, notice that very occasionally the inserting process
would spit out weird error messages like "Function '(int4)' does not
exist" and "init_fcache: null probin for procedure 481".  This seems
to be due to VACUUM (on system tables) causing syscache entries to be
flushed at unexpected times.  I've committed patches for the two cases
I observed, but there may be more lurking...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-02 15:11     ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 06:05       ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 06:12         ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 07:18           ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 14:17             ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 17:53               ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
@ 2000-06-06 18:20                 ` Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 21:25                   ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 33+ messages in thread

From: Ed Loehr @ 2000-06-06 18:20 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general

Tom Lane wrote:
> 
> Ed Loehr <eloehr@austin.rr.com> writes:
> >>>>> % while test 1; do echo -n "`date`: "; psql -d pdb -c "vacuum analyze;
> >>>>> select count(*) from foo;"; sleep 3; done
> >>>>>
> >>>>> This seems to consistently crash after the first vacuum with the
> >>>>> following message:
> >>
> >> This is a known gotcha that's got nothing to do with any sort of
> >> concurrency.  You can't safely send a VACUUM followed by anything
> >> else in a single query string.
> 
> > Well, I thought that select count(*) might've been causing a problem, so
> > I experimented without it and found the same problem.  Doesn't seem to
> > happen with 'vacuum'or 'vacuum analyze foo', only 'vacuum analyze'...
> 
> I can't reproduce any problem with just a "vacuum" (with or without
> analyze) and no following command.
> 
> I did, however, notice that very occasionally the inserting process
> would spit out weird error messages like "Function '(int4)' does not
> exist" and  null probin for procedure 481".  This seems
> to be due to VACUUM (on system tables) causing syscache entries to be
> flushed at unexpected times.  I've committed patches for the two cases
> I observed, but there may be more lurking...

Yes, I was getting a similar Function error message, though I never saw
the init_fcache message.  And it appeared the backend would crash
coincidentally with the function error message.  If the patch can be
applied to 7.0 (beta3), and you don't mind posting it, I could test it
here...

Regards,
Ed Loehr



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-02 15:11     ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 06:05       ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 06:12         ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 07:18           ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 14:17             ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-06 17:53               ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 18:20                 ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
@ 2000-06-06 21:25                   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 33+ messages in thread

From: Tom Lane @ 2000-06-06 21:25 UTC (permalink / raw)
  To: Ed Loehr <eloehr@austin.rr.com>; +Cc: pgsql-general

Ed Loehr <eloehr@austin.rr.com> writes:
> Tom Lane wrote:
>> I can't reproduce any problem with just a "vacuum" (with or without
>> analyze) and no following command.
>> 
>> I did, however, notice that very occasionally the inserting process
>> would spit out weird error messages like "Function '(int4)' does not
>> exist" and  null probin for procedure 481".  This seems
>> to be due to VACUUM (on system tables) causing syscache entries to be
>> flushed at unexpected times.  I've committed patches for the two cases
>> I observed, but there may be more lurking...

> Yes, I was getting a similar Function error message, though I never saw
> the init_fcache message.  And it appeared the backend would crash
> coincidentally with the function error message.  If the patch can be
> applied to 7.0 (beta3), and you don't mind posting it, I could test it
> here...

Hmm, I only saw error messages, no crashes --- but I suppose a crash is
possible, since the root of the problem here is a dangling pointer.

Patches for 7.0.2 are attached.  Not sure if they will apply perfectly
cleanly to beta3, but you should be able to make the right mods by hand
if patch doesn't cope...

			regards, tom lane

inline patch 1: src/backend/parser/parse_type.c, src/backend/utils/cache/fcache.c (+10/-5 lines) download inline-1.patch*** src/backend/parser/parse_type.c.orig Tue May 30 00:24:49 2000 --- src/backend/parser/parse_type.c Tue Jun 6 11:41:08 2000 *************** *** 48,54 **** return NULL; } typetuple = (Form_pg_type) GETSTRUCT(tup); ! return NameStr(typetuple->typname); } /* return a Type structure, given a type id */ --- 48,55 ---- return NULL; } typetuple = (Form_pg_type) GETSTRUCT(tup); ! /* pstrdup here because result may need to outlive the syscache entry */ ! return pstrdup(NameStr(typetuple->typname)); } /* return a Type structure, given a type id */ *************** *** 119,125 **** Form_pg_type typ; typ = (Form_pg_type) GETSTRUCT(t); ! return NameStr(typ->typname); } /* given a type, return its typetype ('c' for 'c'atalog types) */ --- 120,127 ---- Form_pg_type typ; typ = (Form_pg_type) GETSTRUCT(t); ! /* pstrdup here because result may need to outlive the syscache entry */ ! return pstrdup(NameStr(typ->typname)); } /* given a type, return its typetype ('c' for 'c'atalog types) */ *** src/backend/utils/cache/fcache.c~ Wed Apr 12 13:15:53 2000 --- src/backend/utils/cache/fcache.c Tue Jun 6 13:39:03 2000 *************** *** 14,19 **** --- 14,20 ---- */ #include "postgres.h" + #include "access/heapam.h" #include "catalog/pg_language.h" #include "catalog/pg_proc.h" #include "catalog/pg_type.h" *************** *** 89,97 **** if (!use_syscache) elog(ERROR, "what the ????, init the fcache without the catalogs?"); ! procedureTuple = SearchSysCacheTuple(PROCOID, ! ObjectIdGetDatum(foid), ! 0, 0, 0); if (!HeapTupleIsValid(procedureTuple)) elog(ERROR, "init_fcache: Cache lookup failed for procedure %u", --- 90,98 ---- if (!use_syscache) elog(ERROR, "what the ????, init the fcache without the catalogs?"); ! procedureTuple = SearchSysCacheTupleCopy(PROCOID, ! ObjectIdGetDatum(foid), ! 0, 0, 0); if (!HeapTupleIsValid(procedureTuple)) elog(ERROR, "init_fcache: Cache lookup failed for procedure %u", *************** *** 258,263 **** --- 259,266 ---- } else retval->func.fn_addr = (func_ptr) NULL; + + heap_freetuple(procedureTuple); return retval; }
^ permalink raw reply [nested|flat] 33+ messages in thread

* Re: Vacuum Question
  2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
  2000-06-02 05:43 ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-02 14:44   ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
  2000-06-02 15:11     ` Re: Vacuum Question Tom Lane <tgl@sss.pgh.pa.us>
  2000-06-06 06:05       ` Re: Vacuum Question Ed Loehr <eloehr@austin.rr.com>
@ 2000-06-06 06:18         ` Ed Loehr <eloehr@austin.rr.com>
  1 sibling, 0 replies; 33+ messages in thread

From: Ed Loehr @ 2000-06-06 06:18 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general

Ed Loehr wrote:
> 
> On my way to some performance testing I ran into this repeatable crash
> scenario.  Just wondering if anyone else can reproduce the same or
> explain what is happening.  Could very well be something peculiar/buggy
> about the bash/perl commands...
> 
> First, start up this rather obfuscated perl/bash command which just
> inserts random records forever...
> 
> %  createdb pdb; psql -d pdb -c "create table foo(id serial, t timestamp
> not null default current_timestamp, f float, s varchar, i integer, l
> int8);"; perl -e 'for (my $j = 0; $j < 10000000; $j++ ) { print "--
> Insert #$j\n"; $f = rand(2000000); $i = int(rand(2000000)) % 16000; $l =
> int(rand(2000000000)); $s = chr(65 + int(rand(20))) x int(rand(128));
> $delim = chr(39); print "insert into foo (f,s,i,l) values ($f,
> $delim${s}$delim, $i, $l);\n"; }' | psql -d pdb
> 
> Then, start this one in another bash window/terminal/whatever...
> 
> % while test 1; do echo -n "`date`: "; psql -d pdb -c "vacuum analyze;
> select count(*) from foo;"; sleep 3; done
> 
> This seems to consistently crash after the first vacuum ...

Oh, and the possibly relevant snippet from the server log:

20000606.01:13:27.116  [8659] query: insert into foo (f,s,i,l) values 
(941636.60146296, 'HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH',
7223, 754988800);
20000606.01:13:27.164  [8679] DEBUG:  --Relation pg_aggregate--
20000606.01:13:27.164  [8679] DEBUG:  Pages 1: Changed 0, reaped 0, Empty
0, New 0; Tup 45: Vac 0, Keep/VTL 0/0, Crash 0, UnUsed 0, MinLen 100,
MaxLen 107;
 Re-using: Free/Avail. Space 0/0; EndEmpty/Avail. Pages 0/0. CPU
0.00s/0.00u sec.
20000606.01:13:27.165  [8679] DEBUG:  Index pg_aggregate_name_type_index:
Pages 2; Tuples 45. CPU 0.00s/0.00u sec.
20000606.01:13:27.172  [8679] DEBUG:  --Relation pg_ipl--
20000606.01:13:27.172  [8679] DEBUG:  Pages 0: Changed 0, reaped 0, Empty
0, New 0; Tup 0: Vac 0, Keep/VTL 0/0, Crash 0, UnUsed 0, MinLen 0, MaxLen
0; Re-u
sing: Free/Avail. Space 0/0; EndEmpty/Avail. Pages 0/0. CPU 0.00s/0.00u
sec.
20000606.01:13:27.175  [8679] DEBUG:  --Relation pg_inheritproc--
20000606.01:13:27.176  [8679] DEBUG:  Pages 0: Changed 0, reaped 0, Empty
0, New 0; Tup 0: Vac 0, Keep/VTL 0/0, Crash 0, UnUsed 0, MinLen 0, MaxLen
0; Re-u
sing: Free/Avail. Space 0/0; EndEmpty/Avail. Pages 0/0. CPU 0.00s/0.00u
sec.
20000606.01:13:27.180  [8679] DEBUG:  --Relation pg_rewrite--
20000606.01:13:27.184  [8679] DEBUG:  Pages 1: Changed 0, reaped 0, Empty
0, New 0; Tup 5: Vac 0, Keep/VTL 0/0, Crash 0, UnUsed 0, MinLen 903,
MaxLen 1236;
 Re-using: Free/Avail. Space 0/0; EndEmpty/Avail. Pages 0/0. CPU
0.00s/0.00u sec.
20000606.01:13:27.186  [8679] DEBUG:  Index pg_rewrite_rulename_index:
Pages 2; Tuples 5. CPU 0.00s/0.00u sec.
20000606.01:13:27.187  [8679] DEBUG:  Index pg_rewrite_oid_index: Pages
2; Tuples 5. CPU 0.00s/0.00u sec.
20000606.01:13:27.188  [8659] ERROR:  Function
'<FF><FF><FF><FF>^Ap(int4)' does not exist
        Unable to identify a function that satisfies the given argument
types
        You may need to add explicit typecasts

One day maybe I'll learn to include all the relevant stuff in one
post...nah.

Regards,
Ed Loehr



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Vacuum question..
@ 2002-10-01 00:08 Williams, Travis L, NPONS <tlw@att.com>
  2002-10-01 07:37 ` Re: Vacuum question.. Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
  0 siblings, 1 reply; 33+ messages in thread

From: Williams, Travis L, NPONS @ 2002-10-01 00:08 UTC (permalink / raw)
  To: pgsql-general

I have a DB that's about 1000 rows and 100 columns with 97 of them being updated every 20-30 min.  This DB is basically all of the data that I poll off of 1000 different machines thats used by different scripts.  How often should I run Vacuum?  Would I be better off doing it every time after I do my updates?

Travis



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: Vacuum question..
  2002-10-01 00:08 Vacuum question.. Williams, Travis L, NPONS <tlw@att.com>
@ 2002-10-01 07:37 ` Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
  0 siblings, 0 replies; 33+ messages in thread

From: Shridhar Daithankar @ 2002-10-01 07:37 UTC (permalink / raw)
  To: pgsql-general

On 30 Sep 2002 at 20:08, Williams, Travis L, NPONS wrote:

> I have a DB that's about 1000 rows and 100 columns with 97 of them being updated every 20-30 min.  This DB is basically all of the data that I poll off of 1000 different machines thats used by different scripts.  How often should I run Vacuum?  Would I be better off doing it every time after I 
do my updates?

Well no. I would say every 15 minutes would be a good idea.

How often do you query the table? Vacuum can do three things for you.

1) Update statistics so that planner chooses correct plan thus improving 
performance.

2) Update causes dead tuples of earlier verson. Vacuum analyze marks these dead 
tuples for reuse so that resources are used efficiently.

3) Vacuum full also retrieves any lost disk space when you do a bulk delete.

Clearly in your case, (2) seems to be predominant factor. So I would say a 
vacuum analyze <tablename> for each 15 minutes will keep things in good 
shape..Even half an hour would do..


Bye
 Shridhar

--
Nachman's Rule:	When it comes to foreign food, the less authentic the better.		-
- Gerald Nachman




^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* VACUUM Question
@ 2004-02-19 06:51 Alex <alex@meerkatsoft.com>
  2004-06-04 14:21 ` Re: VACUUM Question Greg Stark <gsstark@mit.edu>
  0 siblings, 1 reply; 33+ messages in thread

From: Alex @ 2004-02-19 06:51 UTC (permalink / raw)
  To: pgsql-general

Hi,
just a few questions on the Vaccum

I run a vacuum analyze on the database every night as part of a 
maintenance job.

During the day I have a job that loads 30-70,000 records into two tables 
(each 30-70k).
This job runs 2-3 times a day; the first time mainly inserts, the 2nd, 
3rd time mostly updates.
Both tables have in the area of 1-3Mio records

How reasonable is it to run a Vacuum Analyze before and after the 
insert/update of the data.

Also, I noticed that i get quite some performance improvement if I run a 
count(*) on the two tables before the insert. Any reasons for that?


One more question; on one server the Vacuum Analyze before the insert 
takes approx. 2min after that the same command takes 15min.

I run PG7.3.4

Thanks for any help

Alex









^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2004-02-19 06:51 VACUUM Question Alex <alex@meerkatsoft.com>
@ 2004-06-04 14:21 ` Greg Stark <gsstark@mit.edu>
  2004-06-04 18:50   ` Re: VACUUM Question Joseph Shraibman <jks@selectacast.net>
  2004-06-04 19:31   ` Re: VACUUM Question Rick Gigger <rick@alpinenetworking.com>
  0 siblings, 2 replies; 33+ messages in thread

From: Greg Stark @ 2004-06-04 14:21 UTC (permalink / raw)
  To: pgsql-general

Alex <alex@meerkatsoft.com> writes:

> How reasonable is it to run a Vacuum Analyze before and after the
> insert/update of the data.

On a busy system you should run vacuum more often than once per day.

You should probably run a VACUUM after the update. And running ANALYZE at the
same time isn't a bad idea, especially if the update changes the distribution
a lot.

There won't be anything to VACUUM after the insert, but perhaps you still want
to run ANALYZE. Note that a plain ANALYZE uses a statistical sample which is
much faster, whereas VACUUM ANALYZE has to look at every record anyways so
it's slower but produces more accurate statistics. If you don't have
performance problems then using VACUUM ANALYZE isn't a bad idea, but it's
probably overkill.

> Also, I noticed that i get quite some performance improvement if I run a
> count(*) on the two tables before the insert. Any reasons for that?

Uh, just preloading the kernel cache with blocks from the table and index?

> One more question; on one server the Vacuum Analyze before the insert takes
> approx. 2min after that the same command takes 15min.

You might try a VACUUM FULL sometime when you can deal with 15min of downtime
or so. Actually it would probably be longer. Perhaps the table that's taking
15min has a ton of extra dead tuples left over from the fsm settings being too
low and/or vacuum being too infrequent.

-- 
greg




^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2004-02-19 06:51 VACUUM Question Alex <alex@meerkatsoft.com>
  2004-06-04 14:21 ` Re: VACUUM Question Greg Stark <gsstark@mit.edu>
@ 2004-06-04 18:50   ` Joseph Shraibman <jks@selectacast.net>
  2004-06-04 20:57     ` Re: VACUUM Question Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 33+ messages in thread

From: Joseph Shraibman @ 2004-06-04 18:50 UTC (permalink / raw)
  To: Greg Stark <gsstark@mit.edu>; +Cc: pgsql-general

Greg Stark wrote:
> Alex <alex@meerkatsoft.com> writes:
> 

> There won't be anything to VACUUM after the insert, but perhaps you still want
> to run ANALYZE. Note that a plain ANALYZE uses a statistical sample which is
> much faster, whereas VACUUM ANALYZE has to look at every record anyways so
> it's slower but produces more accurate statistics. If you don't have

That is not true.  My nightly vacuum analyze clearly is sampling:

INFO:  "tablename": 22102 pages, 30000 rows sampled, 1712934 estimated 
total rows



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2004-02-19 06:51 VACUUM Question Alex <alex@meerkatsoft.com>
  2004-06-04 14:21 ` Re: VACUUM Question Greg Stark <gsstark@mit.edu>
  2004-06-04 18:50   ` Re: VACUUM Question Joseph Shraibman <jks@selectacast.net>
@ 2004-06-04 20:57     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 33+ messages in thread

From: Tom Lane @ 2004-06-04 20:57 UTC (permalink / raw)
  To: Joseph Shraibman <jks@selectacast.net>; +Cc: Greg Stark <gsstark@mit.edu>; pgsql-general

Joseph Shraibman <jks@selectacast.net> writes:
> Greg Stark wrote:
>> There won't be anything to VACUUM after the insert, but perhaps you still want
>> to run ANALYZE. Note that a plain ANALYZE uses a statistical sample which is
>> much faster, whereas VACUUM ANALYZE has to look at every record anyways so
>> it's slower but produces more accurate statistics. If you don't have

> That is not true.  My nightly vacuum analyze clearly is sampling:

> INFO:  "tablename": 22102 pages, 30000 rows sampled, 1712934 estimated 
> total rows

There is (only) one aspect in which VACUUM ANALYZE will produce more
accurate stats than a standalone ANALYZE: what it stores into
pg_class.reltuples is the true total tuple count produced by the VACUUM
phase, rather than the estimate produced by the ANALYZE phase.  What
goes into pg_statistic will be the same in both cases, however, and will
be based on a sample not the whole table.

BTW, a VACUUM just after a table is loaded by INSERT/COPY is not
necessarily useless.  It won't reclaim space, there being none to
reclaim, but it will mark all the rows as "known committed", thereby
saving some amount of I/O that would otherwise be incurred by later
transactions.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2004-02-19 06:51 VACUUM Question Alex <alex@meerkatsoft.com>
  2004-06-04 14:21 ` Re: VACUUM Question Greg Stark <gsstark@mit.edu>
@ 2004-06-04 19:31   ` Rick Gigger <rick@alpinenetworking.com>
  2004-06-04 19:40     ` Re: VACUUM Question Bill Moran <wmoran@potentialtech.com>
  1 sibling, 1 reply; 33+ messages in thread

From: Rick Gigger @ 2004-06-04 19:31 UTC (permalink / raw)
  To: Greg Stark <gsstark@mit.edu>; +Cc: pgsql-general

>>One more question; on one server the Vacuum Analyze before the insert takes
>>approx. 2min after that the same command takes 15min.
> 
> 
> You might try a VACUUM FULL sometime when you can deal with 15min of downtime
> or so. Actually it would probably be longer. Perhaps the table that's taking
> 15min has a ton of extra dead tuples left over from the fsm settings being too
> low and/or vacuum being too infrequent.

Does VACUUM FULL just lock entire tables and thus cause you to 
essentially have downtime on that database because it doesn't respond 
quickly or do you actually have to shut down postgres to safely do a 
vacuum full?



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2004-02-19 06:51 VACUUM Question Alex <alex@meerkatsoft.com>
  2004-06-04 14:21 ` Re: VACUUM Question Greg Stark <gsstark@mit.edu>
  2004-06-04 19:31   ` Re: VACUUM Question Rick Gigger <rick@alpinenetworking.com>
@ 2004-06-04 19:40     ` Bill Moran <wmoran@potentialtech.com>
  2004-06-04 20:38       ` Re: VACUUM Question Alvaro Herrera <alvherre@dcc.uchile.cl>
  0 siblings, 1 reply; 33+ messages in thread

From: Bill Moran @ 2004-06-04 19:40 UTC (permalink / raw)
  To: Rick Gigger <rick@alpinenetworking.com>; +Cc: gsstark@mit.edu; pgsql-general

Rick Gigger <rick@alpinenetworking.com> wrote:

> >>One more question; on one server the Vacuum Analyze before the insert takes
> >>approx. 2min after that the same command takes 15min.
> > 
> > 
> > You might try a VACUUM FULL sometime when you can deal with 15min of downtime
> > or so. Actually it would probably be longer. Perhaps the table that's taking
> > 15min has a ton of extra dead tuples left over from the fsm settings being too
> > low and/or vacuum being too infrequent.
> 
> Does VACUUM FULL just lock entire tables and thus cause you to 
> essentially have downtime on that database because it doesn't respond 
> quickly or do you actually have to shut down postgres to safely do a 
> vacuum full?

The former.  You don't shut the database server down, but it won't be
responsive while vacuum full is running.

-- 
Bill Moran
Potential Technologies
http://www.potentialtech.com



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2004-02-19 06:51 VACUUM Question Alex <alex@meerkatsoft.com>
  2004-06-04 14:21 ` Re: VACUUM Question Greg Stark <gsstark@mit.edu>
  2004-06-04 19:31   ` Re: VACUUM Question Rick Gigger <rick@alpinenetworking.com>
  2004-06-04 19:40     ` Re: VACUUM Question Bill Moran <wmoran@potentialtech.com>
@ 2004-06-04 20:38       ` Alvaro Herrera <alvherre@dcc.uchile.cl>
  0 siblings, 0 replies; 33+ messages in thread

From: Alvaro Herrera @ 2004-06-04 20:38 UTC (permalink / raw)
  To: Bill Moran <wmoran@potentialtech.com>; +Cc: Rick Gigger <rick@alpinenetworking.com>; gsstark@mit.edu; pgsql-general

On Fri, Jun 04, 2004 at 03:40:45PM -0400, Bill Moran wrote:
> Rick Gigger <rick@alpinenetworking.com> wrote:
> 
> > Does VACUUM FULL just lock entire tables and thus cause you to 
> > essentially have downtime on that database because it doesn't respond 
> > quickly or do you actually have to shut down postgres to safely do a 
> > vacuum full?
> 
> The former.  You don't shut the database server down, but it won't be
> responsive while vacuum full is running.

But only for the table that's currently being vacuumed: there's only one
table locked at any time.

(A different issue is the IO storm caused by the vacuum, which makes
everything else slower.)

-- 
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"En las profundidades de nuestro inconsciente hay una obsesiva necesidad
de un universo lógico y coherente. Pero el universo real se halla siempre
un paso más allá de la lógica" (Irulan)




^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* VACUUM Question
@ 2004-02-19 14:58 Alex <alex@meerkatsoft.com>
  2004-02-19 16:56 ` Re: VACUUM Question scott.marlowe <scott.marlowe@ihs.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Alex @ 2004-02-19 14:58 UTC (permalink / raw)
  To: pgsql-general

Hi,
just a few questions on the Vaccum

I run a vacuum analyze on the database every night as part of a
maintenance job.

During the day I have a job that loads 30-70,000 records into two tables
(each 30-70k).
This job runs 2-3 times a day; the first time mainly inserts, the 2nd,
3rd time mostly updates.
Both tables have in the area of 1-3Mio records

How reasonable is it to run a Vacuum Analyze before and after the
insert/update of the data.

Also, I noticed that i get quite some performance improvement if I run a
count(*) on the two tables before the insert. Any reasons for that?


One more question; on one server the Vacuum Analyze before the insert
takes approx. 2min after that the same command takes 15min.

I run PG7.3.4

Thanks for any help

Alex










^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2004-02-19 14:58 VACUUM Question Alex <alex@meerkatsoft.com>
@ 2004-02-19 16:56 ` scott.marlowe <scott.marlowe@ihs.com>
  0 siblings, 0 replies; 33+ messages in thread

From: scott.marlowe @ 2004-02-19 16:56 UTC (permalink / raw)
  To: Alex <alex@meerkatsoft.com>; +Cc: pgsql-general

On Thu, 19 Feb 2004, Alex wrote:

> Hi,
> just a few questions on the Vaccum
> 
> I run a vacuum analyze on the database every night as part of a
> maintenance job.
> 
> During the day I have a job that loads 30-70,000 records into two tables
> (each 30-70k).
> This job runs 2-3 times a day; the first time mainly inserts, the 2nd,
> 3rd time mostly updates.
> Both tables have in the area of 1-3Mio records
> 
> How reasonable is it to run a Vacuum Analyze before and after the
> insert/update of the data.

Running it before probably gains you little.  In some circumstances 
(running analyze on an empty table is one) analyzing before loading data 
is counterproductive, because postgresql's query planner will be making 
decisions on the 30,000th of 70,000 inserts based on a table size of very 
few rows, and favoring seq scans when it should be using index scans.

vacuuming (and analyzing) after the import is a good thing.

> Also, I noticed that i get quite some performance improvement if I run a
> count(*) on the two tables before the insert. Any reasons for that?

Likely it is loading the whole table into kernel cache.

> One more question; on one server the Vacuum Analyze before the insert
> takes approx. 2min after that the same command takes 15min.

Normal.  Before hand, there are no dead tuples to harvest / put in the 
fsm, but afterward there are plenty to harvest.

Make sure your fsm settings are high enough to retain all the freed pages, 
or you'll wind up with table bloat.

Vacuum full every so often (off hours are best) to make sure.  Do a df on 
the database mount point before and after and see how much spave it 
recovers.




^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* VACUUM Question
@ 2006-01-26 19:10 Oisin Glynn <me@oisinglynn.com>
  2006-01-26 19:35 ` Re: VACUUM Question Matthew T. O'Connor <matthew@zeut.net>
  0 siblings, 1 reply; 33+ messages in thread

From: Oisin Glynn @ 2006-01-26 19:10 UTC (permalink / raw)
  To: pgsql-general

We have 2 tables we expect to grow by up to 50,000 rows per day each depending on the customer.  In normal operation we will most likely never update or delete from these tables as they are for historical reporting. (Eventually we may but a limit on the amount of data and delete older than X months or such)
We intend to create a number of indexes based upon the reporting search criteria.

What would the best setup be for VACUUM, ANALYSE, REINDEX.  Alot of the infor refers to data hanging around from deletes and updates which in normal course we will not do on these tables?


Oisin

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2006-01-26 19:10 VACUUM Question Oisin Glynn <me@oisinglynn.com>
@ 2006-01-26 19:35 ` Matthew T. O'Connor <matthew@zeut.net>
  2006-01-26 20:44   ` Re: VACUUM Question Michael Fuhr <mike@fuhr.org>
  2006-01-26 21:14   ` Re: VACUUM Question Chris Browne <cbbrowne@acm.org>
  0 siblings, 2 replies; 33+ messages in thread

From: Matthew T. O'Connor @ 2006-01-26 19:35 UTC (permalink / raw)
  To: Oisin Glynn <me@oisinglynn.com>; +Cc: pgsql-general

If you really are just inserting, and never updating or deleting, then you
will never need to vacuum the table, rather you will just need to ANALYSE
the table.  If you use autovacuum that is exactly what it will do.

As for Reindex, I'm not entirely sure, I don't think you would benefit
from reindex because you aren't updating or deleting.  Can anyone comment
on this?  Is is possibile that a table with lots of inserts resulting in
lots of page splits etc could ever benifit form REINDEX?

Matt


> We have 2 tables we expect to grow by up to 50,000 rows per day each
> depending on the customer.  In normal operation we will most likely never
> update or delete from these tables as they are for historical reporting.
> (Eventually we may but a limit on the amount of data and delete older than
> X months or such)
> We intend to create a number of indexes based upon the reporting search
> criteria.
>
> What would the best setup be for VACUUM, ANALYSE, REINDEX.  Alot of the
> infor refers to data hanging around from deletes and updates which in
> normal course we will not do on these tables?
>
>
> Oisin
>




^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2006-01-26 19:10 VACUUM Question Oisin Glynn <me@oisinglynn.com>
  2006-01-26 19:35 ` Re: VACUUM Question Matthew T. O'Connor <matthew@zeut.net>
@ 2006-01-26 20:44   ` Michael Fuhr <mike@fuhr.org>
  2006-01-26 21:41     ` Re: VACUUM Question Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 33+ messages in thread

From: Michael Fuhr @ 2006-01-26 20:44 UTC (permalink / raw)
  To: Matthew T. O'Connor <matthew@zeut.net>; +Cc: Oisin Glynn <me@oisinglynn.com>; pgsql-general

On Thu, Jan 26, 2006 at 02:35:42PM -0500, Matthew T. O'Connor wrote:
> If you really are just inserting, and never updating or deleting, then you
> will never need to vacuum the table, rather you will just need to ANALYSE
> the table.

That's not quite true; the table must still be vacuumed occasionally
to prevent transaction ID wraparound failure, else you risk losing
data.

http://www.postgresql.org/docs/8.1/interactive/maintenance.html#VACUUM-FOR-WRAPAROUND

-- 
Michael Fuhr



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2006-01-26 19:10 VACUUM Question Oisin Glynn <me@oisinglynn.com>
  2006-01-26 19:35 ` Re: VACUUM Question Matthew T. O'Connor <matthew@zeut.net>
  2006-01-26 20:44   ` Re: VACUUM Question Michael Fuhr <mike@fuhr.org>
@ 2006-01-26 21:41     ` Tom Lane <tgl@sss.pgh.pa.us>
  2006-01-27 03:48       ` Re: VACUUM Question Matthew T. O'Connor <matthew@zeut.net>
  0 siblings, 1 reply; 33+ messages in thread

From: Tom Lane @ 2006-01-26 21:41 UTC (permalink / raw)
  To: Michael Fuhr <mike@fuhr.org>; +Cc: Matthew T. O'Connor <matthew@zeut.net>; Oisin Glynn <me@oisinglynn.com>; pgsql-general

Michael Fuhr <mike@fuhr.org> writes:
> On Thu, Jan 26, 2006 at 02:35:42PM -0500, Matthew T. O'Connor wrote:
>> If you really are just inserting, and never updating or deleting, then you
>> will never need to vacuum the table, rather you will just need to ANALYSE
>> the table.

> That's not quite true; the table must still be vacuumed occasionally
> to prevent transaction ID wraparound failure,

Also, somebody made a real good point about rolled-back insertions.
Even if the only command you ever apply to the table is INSERT, you
could still have dead rows in the table if some of those transactions
occasionally roll back.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2006-01-26 19:10 VACUUM Question Oisin Glynn <me@oisinglynn.com>
  2006-01-26 19:35 ` Re: VACUUM Question Matthew T. O'Connor <matthew@zeut.net>
  2006-01-26 20:44   ` Re: VACUUM Question Michael Fuhr <mike@fuhr.org>
  2006-01-26 21:41     ` Re: VACUUM Question Tom Lane <tgl@sss.pgh.pa.us>
@ 2006-01-27 03:48       ` Matthew T. O'Connor <matthew@zeut.net>
  0 siblings, 0 replies; 33+ messages in thread

From: Matthew T. O'Connor @ 2006-01-27 03:48 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Michael Fuhr <mike@fuhr.org>; Matthew T. O'Connor <matthew@zeut.net>; Oisin Glynn <me@oisinglynn.com>; pgsql-general

> Also, somebody made a real good point about rolled-back insertions.
> Even if the only command you ever apply to the table is INSERT, you
> could still have dead rows in the table if some of those transactions
> occasionally roll back.

hmm... That's true.  I don't think autovacuum doesn't anything to account
for the concept of rolledback inserts.  I suppose in most real world
situations that number is going to be small enough to be ignored, but not
in all cases.  Is there anyway for the stats system to report the
information about rolledback inserts?  In fact autovacuum probably has a
similar deficiency for rolled back deletes but not a rolled back update. 
Anyone think this is enough of an issue that it needs more attention?

Matt




^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2006-01-26 19:10 VACUUM Question Oisin Glynn <me@oisinglynn.com>
  2006-01-26 19:35 ` Re: VACUUM Question Matthew T. O'Connor <matthew@zeut.net>
@ 2006-01-26 21:14   ` Chris Browne <cbbrowne@acm.org>
  2006-01-31 19:52     ` Re: VACUUM Question Jim C. Nasby <jnasby@pervasive.com>
  1 sibling, 1 reply; 33+ messages in thread

From: Chris Browne @ 2006-01-26 21:14 UTC (permalink / raw)
  To: pgsql-general

matthew@zeut.net ("Matthew T. O'Connor") writes:
> If you really are just inserting, and never updating or deleting,
> then you will never need to vacuum the table, rather you will just
> need to ANALYSE the table.  If you use autovacuum that is exactly
> what it will do.

"Never" is a pretty long time...

You need a VACUUM every 2^31 transactions, but since there needs to be
such a vacuum for the whole database, that one will do...

> As for Reindex, I'm not entirely sure, I don't think you would benefit
> from reindex because you aren't updating or deleting.  Can anyone comment
> on this?  Is is possibile that a table with lots of inserts resulting in
> lots of page splits etc could ever benifit form REINDEX?

I could imagine a CLUSTER doing some good, and if that's the case,
REINDEX could have some favorable results.  But you'd better have a
real specific model as to why that would be...
-- 
let name="cbbrowne" and tld="ntlug.org" in name ^ "@" ^ tld;;
http://cbbrowne.com/info/spreadsheets.html
Oh,  boy, virtual memory!  Now I'm  gonna make  myself a  really *big*
RAMdisk!



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: VACUUM Question
  2006-01-26 19:10 VACUUM Question Oisin Glynn <me@oisinglynn.com>
  2006-01-26 19:35 ` Re: VACUUM Question Matthew T. O'Connor <matthew@zeut.net>
  2006-01-26 21:14   ` Re: VACUUM Question Chris Browne <cbbrowne@acm.org>
@ 2006-01-31 19:52     ` Jim C. Nasby <jnasby@pervasive.com>
  0 siblings, 0 replies; 33+ messages in thread

From: Jim C. Nasby @ 2006-01-31 19:52 UTC (permalink / raw)
  To: Chris Browne <cbbrowne@acm.org>; +Cc: pgsql-general

On Thu, Jan 26, 2006 at 04:14:45PM -0500, Chris Browne wrote:
> > As for Reindex, I'm not entirely sure, I don't think you would benefit
> > from reindex because you aren't updating or deleting.  Can anyone comment
> > on this?  Is is possibile that a table with lots of inserts resulting in
> > lots of page splits etc could ever benifit form REINDEX?
> 
> I could imagine a CLUSTER doing some good, and if that's the case,
> REINDEX could have some favorable results.  But you'd better have a
> real specific model as to why that would be...

Aside from the cluster case, are there any issues with how page splits
in the b-tree are done that could lead to better performance after a
REINDEX?
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* vacuum question
@ 2018-09-30 11:32 Torsten Förtsch <tfoertsch123@gmail.com>
  2018-09-30 11:53 ` Re: vacuum question Stephen Frost <sfrost@snowman.net>
  0 siblings, 1 reply; 33+ messages in thread

From: Torsten Förtsch @ 2018-09-30 11:32 UTC (permalink / raw)
  To: pgsql-general

Hi,

I have a table with a really small number of rows, usually about 1500,
sometimes may be up to 5000. The usage pattern of that table is such that
rows are inserted and kept for a while, mostly seconds or minutes but
theoretically up to 1 year. After that they are deleted. No updates, just
insert, delete. The table is pretty actively written, sometimes >100
transactions per second.

Although the table is frequently auto-vacuumed, its size is growing over
time. The size of the table corresponds to the remaining number of pages in
the autovacuum log.

 pages: 0 removed, 30069 remain, 0 skipped due to pins, 29985 skipped
frozen
 tuples: 136 removed, 1643 remain, 15 are dead but not yet removable
 buffer usage: 44327 hits, 0 misses, 21 dirtied
 avg read rate: 0.000 MB/s, avg write rate: 0.036 MB/s
 system usage: CPU 0.06s/0.05u sec elapsed 4.59 sec

What does "29985 skipped frozen" mean? I presume these skipped buffers is
the table bloat.

My way to get rid of the bloat is to cluster the table. That takes less
than half a second and the next autovacuum log then looks like this:

 pages: 0 removed, 3493 remain, 0 skipped due to pins, 0 skipped frozen
 tuples: 0 removed, 58873 remain, 57470 are dead but not yet removable
 buffer usage: 9425 hits, 0 misses, 0 dirtied
 avg read rate: 0.000 MB/s, avg write rate: 0.000 MB/s
 system usage: CPU 0.02s/0.03u sec elapsed 1.01 sec

For a number of autovacuum cycles "skipped frozen" remains 0 until
eventually:

 pages: 0 removed, 4822 remain, 0 skipped due to pins, 4433 skipped frozen
 tuples: 227 removed, 2609 remain, 13 are dead but not yet removable
 buffer usage: 5269 hits, 0 misses, 315 dirtied
 avg read rate: 0.000 MB/s, avg write rate: 2.065 MB/s
 system usage: CPU 0.03s/0.01u sec elapsed 1.19 sec

Is there anything I can do to prevent that bloat from accumulating in the
first place?

Another thing that seems odd is the number of dead but not removable tuples
in the record in the middle. Sifting through the log, I can see numbers up
to 80000. One of our replicas is configured with hot_standby_feedback. Can
that be the culprit?

This is 9.6.10.

Thanks,
Torsten

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: vacuum question
  2018-09-30 11:32 vacuum question Torsten Förtsch <tfoertsch123@gmail.com>
@ 2018-09-30 11:53 ` Stephen Frost <sfrost@snowman.net>
  0 siblings, 0 replies; 33+ messages in thread

From: Stephen Frost @ 2018-09-30 11:53 UTC (permalink / raw)
  To: Torsten Förtsch <tfoertsch123@gmail.com>; +Cc: pgsql-general

Greetings,

* Torsten Förtsch (tfoertsch123@gmail.com) wrote:
> I have a table with a really small number of rows, usually about 1500,
> sometimes may be up to 5000. The usage pattern of that table is such that
> rows are inserted and kept for a while, mostly seconds or minutes but
> theoretically up to 1 year. After that they are deleted. No updates, just
> insert, delete. The table is pretty actively written, sometimes >100
> transactions per second.

The number of live tuples is never over 5000..?  Or 5000 per
transaction, meaning the upper bound is more like 500 000?

> Although the table is frequently auto-vacuumed, its size is growing over
> time. The size of the table corresponds to the remaining number of pages in
> the autovacuum log.
> 
>  pages: 0 removed, 30069 remain, 0 skipped due to pins, 29985 skipped
> frozen
>  tuples: 136 removed, 1643 remain, 15 are dead but not yet removable
>  buffer usage: 44327 hits, 0 misses, 21 dirtied
>  avg read rate: 0.000 MB/s, avg write rate: 0.036 MB/s
>  system usage: CPU 0.06s/0.05u sec elapsed 4.59 sec
> 
> What does "29985 skipped frozen" mean? I presume these skipped buffers is
> the table bloat.

No, the pages skipped because they're frozen just means that there's
nothing for vacuum to do on those pages.

To look at bloat, use pgstattuple.

> My way to get rid of the bloat is to cluster the table. That takes less
> than half a second and the next autovacuum log then looks like this:
> 
>  pages: 0 removed, 3493 remain, 0 skipped due to pins, 0 skipped frozen
>  tuples: 0 removed, 58873 remain, 57470 are dead but not yet removable
>  buffer usage: 9425 hits, 0 misses, 0 dirtied
>  avg read rate: 0.000 MB/s, avg write rate: 0.000 MB/s
>  system usage: CPU 0.02s/0.03u sec elapsed 1.01 sec
> 
> For a number of autovacuum cycles "skipped frozen" remains 0 until
> eventually:
> 
>  pages: 0 removed, 4822 remain, 0 skipped due to pins, 4433 skipped frozen
>  tuples: 227 removed, 2609 remain, 13 are dead but not yet removable
>  buffer usage: 5269 hits, 0 misses, 315 dirtied
>  avg read rate: 0.000 MB/s, avg write rate: 2.065 MB/s
>  system usage: CPU 0.03s/0.01u sec elapsed 1.19 sec
> 
> Is there anything I can do to prevent that bloat from accumulating in the
> first place?

What problem is the bloat causing?  If you can keep all of your
transactions short and autovacuum the table fast enough then the table
size should stablize.

> Another thing that seems odd is the number of dead but not removable tuples
> in the record in the middle. Sifting through the log, I can see numbers up
> to 80000. One of our replicas is configured with hot_standby_feedback. Can
> that be the culprit?

Yes, if you have hot_standby_feedback on then a long running transaction
on the replica would have the same effect as on the primary- PG is
unable to mark rows as reusable until the oldest transaction in the
system is after the commit where the rows were deleted.

If you need to be able to perform long running transactions on the
primary or replica w/ hot standby feedback enabled then there's a few
other approaches which can be used but they're more complicated and
involve things which aren't MVCC-safe (which is why they work to avoid
bloat, but does mean that those long-running transactions won't see rows
that maybe they should have if they look at this table).  Consider
having two tables where you flip between them periodically and empty the
prior one and then TRUNCATE it, then flip again, etc.  The TRUNCATE will
clear out all of the bloat, but will remove rows that a long running
transaction maybe should have been able to see (and which a routine
VACUUM would have kept, just in case).

Thanks!

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 33+ messages in thread


end of thread, other threads:[~2018-09-30 11:53 UTC | newest]

Thread overview: 33+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-06-01 09:17 Vacuum Question brianb <brianb-pggeneral@evoserve.com>
2000-06-02 05:32 ` Bruce Momjian <pgman@candle.pha.pa.us>
2000-06-02 05:43 ` Tom Lane <tgl@sss.pgh.pa.us>
2000-06-02 14:44   ` Ed Loehr <eloehr@austin.rr.com>
2000-06-02 15:11     ` Tom Lane <tgl@sss.pgh.pa.us>
2000-06-06 06:05       ` Ed Loehr <eloehr@austin.rr.com>
2000-06-06 06:12         ` Ed Loehr <eloehr@austin.rr.com>
2000-06-06 07:18           ` Tom Lane <tgl@sss.pgh.pa.us>
2000-06-06 14:17             ` Ed Loehr <eloehr@austin.rr.com>
2000-06-06 17:53               ` Tom Lane <tgl@sss.pgh.pa.us>
2000-06-06 18:20                 ` Ed Loehr <eloehr@austin.rr.com>
2000-06-06 21:25                   ` Tom Lane <tgl@sss.pgh.pa.us>
2000-06-06 06:18         ` Ed Loehr <eloehr@austin.rr.com>
2002-10-01 00:08 Vacuum question.. Williams, Travis L, NPONS <tlw@att.com>
2002-10-01 07:37 ` Re: Vacuum question.. Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
2004-02-19 06:51 VACUUM Question Alex <alex@meerkatsoft.com>
2004-06-04 14:21 ` Re: VACUUM Question Greg Stark <gsstark@mit.edu>
2004-06-04 18:50   ` Re: VACUUM Question Joseph Shraibman <jks@selectacast.net>
2004-06-04 20:57     ` Re: VACUUM Question Tom Lane <tgl@sss.pgh.pa.us>
2004-06-04 19:31   ` Re: VACUUM Question Rick Gigger <rick@alpinenetworking.com>
2004-06-04 19:40     ` Re: VACUUM Question Bill Moran <wmoran@potentialtech.com>
2004-06-04 20:38       ` Re: VACUUM Question Alvaro Herrera <alvherre@dcc.uchile.cl>
2004-02-19 14:58 VACUUM Question Alex <alex@meerkatsoft.com>
2004-02-19 16:56 ` Re: VACUUM Question scott.marlowe <scott.marlowe@ihs.com>
2006-01-26 19:10 VACUUM Question Oisin Glynn <me@oisinglynn.com>
2006-01-26 19:35 ` Re: VACUUM Question Matthew T. O'Connor <matthew@zeut.net>
2006-01-26 20:44   ` Re: VACUUM Question Michael Fuhr <mike@fuhr.org>
2006-01-26 21:41     ` Re: VACUUM Question Tom Lane <tgl@sss.pgh.pa.us>
2006-01-27 03:48       ` Re: VACUUM Question Matthew T. O'Connor <matthew@zeut.net>
2006-01-26 21:14   ` Re: VACUUM Question Chris Browne <cbbrowne@acm.org>
2006-01-31 19:52     ` Re: VACUUM Question Jim C. Nasby <jnasby@pervasive.com>
2018-09-30 11:32 vacuum question Torsten Förtsch <tfoertsch123@gmail.com>
2018-09-30 11:53 ` Re: vacuum question Stephen Frost <sfrost@snowman.net>

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