Postgres dump of only parts of tables for a dev snapshot

后端 未结 3 1148
日久生厌
日久生厌 2020-12-12 15:51

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, bu

3条回答
  •  鱼传尺愫
    2020-12-12 16:39

    I don't know about any software which already does this, but I can think of 3 alternative solutions. Unfortunately, they all require some custom coding.

    1. Re-create all the tables in a separate schema, then copy into those tables only the subset of data you would like to dump, using INSERT INTO copy.tablename SELECT * FROM tablename WHERE ... and dump that.

    2. Write your own script for dumping data as SQL statements. I have used this approach in the past and it only took something like 20-30 lines of PHP.

    3. Modify pg_dump so it accepts a condition along with the -t switch when dumping a single table.

提交回复
热议问题