使用 pg_dump 迁移prod环境的function到uat环境

由于prod环境和uat环境的差异,开发人员要求把prod环境的function全量导入到uat环境。

prod环境 导出模式对象,不含数据

$ pg_dump -U postgres -Fc -s -f /tmp/mondb mondb

uat环境 导出函数名

$ pg_restore -l /tmp/mondb | grep FUNCTION > mondb_func

uat环境 导出所有函数

$ pg_restore -L mondb_func  /tmp/mondb > mondb_function.sql 

uat环境 替换

$ sed -i "s/CREATE FUNCTION/CREATE OR REPLACE FUNCTION/g" /tmp/mondb_function.sql

uat环境 执行

$ psql -U postgres -p 5432 trade < /tmp/mondb_function.sql

参考:
http://postgres.cn/docs/9.6/app-pgrestore.html
-l
–list
列出归档的内容。这个操作的输出能被用作-L选项的输入。注意如果把-n或-t这样的过滤开关与-l一起使用,它们将会限制列出的项

-L list-file
–use-list=list-file
只恢复在list-file中列出的归档元素,并且按照它们出现在该文件中的顺序进行恢复。注意如果把-n或-t这样的过滤开关与-L一起使用,它们将会进一步限制要恢复的项。

list-file通常是编辑一个-l操作的输出来创建。行可以被移动或者移除,并且也可以通过在行首放一个(;)将其注释掉。

猜你喜欢

转载自blog.csdn.net/ctypyb2002/article/details/80611421