Dump postgres data with indexes

AndreDurao picture AndreDurao · Sep 30, 2011 · Viewed 14.4k times · Source

I've got a Postgres 9.0 database which frequently I took data dumps of it.

This database has a lot of indexes and everytime I restore a dump postgres starts background task vacuum cleaner (is that right?). That task consumes much processing time and memory to recreate indexes of the restored dump.

My question is:

  1. Is there a way to dump the database data and the indexes of that database?
  2. If there is a way, will worth the effort (I meant dumping the data with the indexes will perform better than vacuum cleaner)?
  3. Oracle has some the "data pump" command a faster way to imp and exp. Does postgres have something similar?

Thanks in advance, Andre

Answer

wildplasser picture wildplasser · Sep 30, 2011

If you use pg_dump twice, once with --schema-only, and once with --data-only, you can cut the schema-only output in two parts: the first with the bare table definitions and the final part with the constraints and indexes. Something similar can probably be done with pg_restore.