A faster way to copy a postgresql database (or the best way)

后端 未结 4 1478
礼貌的吻别
礼貌的吻别 2021-01-29 22:12

I did a pg_dump of a database and am now trying to install the resulting .sql file on to another server.

I\'m using the following command.

psql -f databa         


        
4条回答
  •  难免孤独
    2021-01-29 23:12

    Why are you producing a raw .sql dump? The opening description of pg_dump recommends the "custom" format -Fc.

    Then you can use pg_restore which will restore your data (or selected parts of it). There is a "number of jobs" option -j which can use multiple cores (assuming your disks aren't already the limiting factor). In most cases, on a modern machine you can expect at least some gains from this.

    Now you say "I don't know how long this is supposed to take". Well, until you've done a few restores you won't know. Do monitor what your system is doing and whether you are limited by cpu or disk I/O.

    Finally, the configuration settings you want for restoring a database are not those you want to run it. A couple of useful starters:

    1. Increase maintenance_work_mem so you can build indexes in larger chunks
    2. Turn off fsync during the restore. If your machine crashes, you'll start from scratch again anyway.

    Do remember to reset them after the restore though.

提交回复
热议问题