Skip to content

Instantly share code, notes, and snippets.

@kmatt
Created May 24, 2012 20:07
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kmatt/2783910 to your computer and use it in GitHub Desktop.
Save kmatt/2783910 to your computer and use it in GitHub Desktop.
Monitoring dump and restore with pv
# dump
pg_dump testdb | pv -c -s $(psql -tc "SELECT pg_database_size('testdb')") -N dump | gzip > testdb.sql.gz
# restore
pv testdb_20120501.sql.gz | zcat | psql testdb
@wojtulab
Copy link

you can round it by 10%
pg_dumpall | pv -s $(psql -tc "SELECT SUM(1.1*(pg_database_size(datname))) FROM pg_database") | gzip > pg-dump.sql.gz

@banderlog
Copy link

Cool solution :)

Also, interactive password input will not work, so you need to pass it through.
Something like (running postgres from container):

PGPASSWORD="postgrespw" \
pg_dump -U postgres -h localhost DATABASE |\
pv -c -s $(psql -h localhost -U postgres -tc "SELECT pg_database_size('DATABASE')") -N dump |\
gzip > DATABASE.sql.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment