如何在导出中排除PL/pgSQL函数?

Rad*_*mko 1 postgresql pg-dump plpgsql

我使用以下命令从服务器的数据库转储一些结构,以便能够在我的本地硬盘驱动器上创建数据样本.

pg_dump -h myserver.com -U product_user -s -f ./data/base.structure.postgresql.sql -F p -v -T public.* -T first_product.* -T second_product.* -T another_product.locales mydatabase
Run Code Online (Sandbox Code Playgroud)

我需要排除一些模式,否则它会最终导致权限或其他错误.即使我排除了schema public,它也会转储该模式中的所有函数,如下所示:

REVOKE ALL ON FUNCTION gin_extract_trgm(text, internal) FROM PUBLIC;
psql:./data/base.structure.postgresql.sql:8482: ERROR:  function gin_extract_trgm(text, internal) does not exist
Run Code Online (Sandbox Code Playgroud)

我知道这来自PostgreSQL中的全文或相似插件,但是我没有使用它而且我的机器上不需要它,所以我想排除这些功能.

我怎么能这样做?

Bar*_*ski 7

有办法做到这一点.假设您的备份名为backup.dump.你需要做的是:

$ pg_restore -l -f out.txt backup.dump
Run Code Online (Sandbox Code Playgroud)

这将创建一个文件out.txt,其中包含转储中的对象列表.您需要编辑该文件并删除不想要还原的项目.然后你这样做:

$ pg_restore -L out.txt -h your.host.name -U username ....  backup.dump
Run Code Online (Sandbox Code Playgroud)

这将使用文件out.txt(您编辑过的)来选择要恢复的内容.非常方便,尤其是在转储很大且无法重新转储数据库的情况下.