On Oct 2, 2006, at 22:17 , Madison Kelly wrote:
I am (re)writing a backup program and I want to add a section for
backing up pSQL DBs. In the planning steps (making sure a given
destination has enough space) I try to calculate how much space
will be needed by a 'pg_dump' run *before* actually dumping it.
Is there a relatively easy way to do that? Moreso, if it possible
to do this from an unpriviledged account? If not, is there a way to
add the permissions to a specific pg user to allow that user to
perform this?
You could dump the database to /dev/null, piping it through wc to
catch the size, but that would of course be wasteful.
You could count the disk space usage of the actual stored tuples,
though this will necessarily be inexact:
http://www.postgresql.org/docs/8.1/static/diskusage.html
Or you could count the size of the physical database files (/var/lib/
postgresql or wherever). While these would be estimates, you could at
least guarantee that the dump would not *exceed* the esimtate.
Keep in mind that pg_dump can compress the dump and (iirc) will do so
by default when you use the custom format (-Fc or --format=c).
Alexander.