Thread: database size after a DELETE and VACUUM

database size after a DELETE and VACUUM

From
Mike.Samson@apcc.com
Date:
Hello All,

I need a reliable way to determine the overall size of our database.
Recently, I started using the database_size() function from the dbsize
contrib.

Everything seems to work great until I need to delete records.
After I DELETE records, the pg_autovacuum daemon kicks in an runs a VACUUM.

Once the VACUUM finishes, I run database_size() again and the size does not
decrease.

I would expect the database size to decrease after the VACUUM.
I also don't want to run a VACUUM FULL because this kills the performance
of the system.

Do I have any other alternatives to determine the database size reliably
after a DELETE
and a VACUUM?

Note that I have also experimented with reltuples which does not give me
accurate results
either unless I run two VACUUMS in a row.

Please help.

Thank you,
Mike Samson
Senior Software Engineer
APC





Re: database size after a DELETE and VACUUM

From
Michael Fuhr
Date:
On Fri, Jul 01, 2005 at 09:30:50AM -0400, Mike.Samson@apcc.com wrote:
>
> I would expect the database size to decrease after the VACUUM.

Note what the documentation says about VACUUM and recovering disk
space:

http://www.postgresql.org/docs/8.0/static/maintenance.html#VACUUM-FOR-SPACE-RECOVERY

"There are two variants of the VACUUM command.  The first form,
known as 'lazy vacuum' or just VACUUM, marks expired data in tables
and indexes for future reuse; it does not attempt to reclaim the
space used by this expired data immediately.  Therefore, the table
file is not shortened, and any unused space in the file is not
returned to the operating system.  This variant of VACUUM can be
run concurrently with normal database operations."

"The standard form of VACUUM is best used with the goal of maintaining
a fairly level steady-state usage of disk space.  If you need to
return disk space to the operating system you can use VACUUM FULL --
but what's the point of releasing disk space that will only have
to be allocated again soon?"

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Re: database size after a DELETE and VACUUM

From
Christopher Browne
Date:
After a long battle with technology, Mike.Samson@apcc.com, an earthling, wrote:
> I need a reliable way to determine the overall size of our database.
> Recently, I started using the database_size() function from the dbsize
> contrib.
>
> Everything seems to work great until I need to delete records.
> After I DELETE records, the pg_autovacuum daemon kicks in an runs a VACUUM.
>
> Once the VACUUM finishes, I run database_size() again and the size does not
> decrease.
>
> I would expect the database size to decrease after the VACUUM.

I wouldn't. VACUUM doesn't decrease database size; it only reclaims
empty pages for re-use.

After a VACUUM, there will be empty space ready to be reused by later
activity.

> I also don't want to run a VACUUM FULL because this kills the
> performance of the system.

Fair enough...

It is, however, only VACUUM FULL that will actually decrease the size
of the database.

With a regimen of running VACUUM reasonably often is that if the
database isn't steadily growing, you'll find that the size stabilizes,
with there being some portion of unused space that will accomodate
upcoming UPDATE/INSERT activity.

If the database *is* steadily growing, well, the unused space will
soon be used :-).

You might want to look in the contrib area for a function called
"pgstattuple" which does a detailed analysis, for any requested table,
as to what portion is live versus dead.
--
If this was helpful, <http://svcs.affero.net/rm.php?r=cbbrowne> rate me
http://cbbrowne.com/info/rdbms.html
THAT COMMAND IS NOT KNOWN TO THIS PROGRAM.
MAYBE YOU SHOULD LOG IN? (TYPE HELP FOR DETAILS)