1

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

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

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

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

我知道这来自 PostgreSQL 中的全文或相似插件,但我不使用它,也不需要在我的机器上使用它,所以我想排除这些功能。

我怎么能那样做?

4

3 回答 3

8

There is a way to do it. Say your backup is named backup.dump. What you need to do is:

$ pg_restore -l -f out.txt backup.dump

That will create a file out.txt that contains a list of objects that are in the dump. You need to edit the file and delete the items you don't want restored. Then you do this:

$ pg_restore -L out.txt -h your.host.name -U username ....  backup.dump

This will use a file out.txt (that you edited) to select the things that will be restored. Pretty handy especially in case the dump is large and you cannot re-dump the database.

于 2015-06-25T06:52:28.733 回答
3

我需要排除一些模式

pg_dump 有一个排除模式的开关:

pg_dump -N schema ...

我引用了有关 pg_dump 的手册

-N 模式
--exclude-schema=模式

不要转储任何与模式模式匹配的模式。该模式根据与 -n 相同的规则进行解释。可以多次给出 -N 以排除与多个模式中的任何一个匹配的模式。
...


使用PostgreSQL 9.1或更高版本,您可以使用新选项将扩展移动到单独的架构中 - 甚至是预安装的旧式模块。您可以使用(新式)扩展注册旧对象,然后使用新工具。和你可能的意思是fulltext和。例子:similarityfuzzystrmatchtsearch2

为扩展注册现有的旧式对象fuzzystrmatch

CREATE EXTENSION fuzzystrmatch SCHEMA public FROM unpackaged;

删除扩展名:

DROP EXTENSION fuzzystrmatch;

将其安装到另一个架构:

CREATE EXTENSION fuzzystrmatch SCHEMA my_schema;

当然,如果扩展中的对象正在使用中,则不能删除扩展。
此外,如果您安装到另一个架构,则需要对其使用中的功能进行架构限定或将架构添加到search_path.

于 2012-03-15T07:54:47.293 回答
0

除了上面 Bartosz 的回答之外,您还可以使用以下 sed 命令在恢复之前从列表中删除例如某个 FUNCTION:

sed -r -i -e '/FUNCTION public plpgsql_call_handler\(\) postgres/d' /var/backup/${DBNAME}.list 
于 2020-06-18T07:29:52.597 回答