因为业务需求,需要将服务器上的postgre多个数据库的数据整个库得迁移到另一个postgre数据库上。
一般表较少时,会使用postgre 的copy to 和 copy from 命令就能完成表的迁移,但这种方式需要target_database 上提前先创建好对应的表,并且每一个表都需要一次copy to 和copy from操作,当表比较多的时候,非常繁琐。
因此我查询了网上的方法,发现了pg_dump这个方法,但是网上的描述比较杂乱,因此我查询了
postgresql的官方手册
https://www.postgresql.org/docs/9.2/app-pgdump.html。
使用pg_dump和pg_restore可以非常快速进行整个database的数据迁移或者备份。
以下是pg_dump的部分选项,pg_restore相似:
1 -F format 2 --format=format 3 Selects the format of the output. format can be one of the following: 4 p 5 plain 6 Output a plain-text SQL script file (the default). 7 c 8 custom