我创建了两个不同的转储文件,一个没有指定模式,另一个指定了public
模式。
而不指定公共模式“
pg_dump -h IP_ADDRESS -p 5432 -U my_user -Fc my_db > my_db_allschema.dump
以及指定公共模式时的pg_dump语句。
pg_dump -h IP_ADDRESS -p 5432 -U my_user -Fc my_db -n public > my_db_publicschema.dump
在使用pg_restore还原转储文件时,在指定公共模式时生成的转储文件会出现错误。
postgres@debian:~$ pg_restore -h localhost -p 5432 -U my_user -d my_db my_db_publicschemaonly.dump
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 8; 2615 2200 SCHEMA public postgres
pg_restore: error: could not execute query: ERROR: schema "public" already exists
Command was: CREATE SCHEMA public;
pg_restore: from TOC entry 212; 1259 18102 TABLE abandoned_url real_estate
pg_restore: error: could not execute query: ERROR: function public.gen_random_uuid() does not exist
LINE 2: id uuid DEFAULT public.gen_random_uuid() NOT NULL
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Command was: CREATE TABLE public.abandoned_url (
id uuid DEFAULT public.gen_random_uuid() NOT NULL
);
查看这个抛出错误的语句
CREATE TABLE public.abandoned_url (
id uuid DEFAULT public.gen_random_uuid() NOT NULL
);
它抛出错误的原因是因为pg_dump将public
放在gen_random_uuid()
之前,当删除gen_random_uuid()之前的public时,下面的语句工作得很好
CREATE TABLE public.abandoned_url (
id uuid DEFAULT gen_random_uuid() NOT NULL
);
我是否错误地创建了转储文件?这可能是pg_dump中的一个bug吗?
发布于 2020-10-31 08:38:09
正如Postgres在这两个命令中使用if exists
进行导出一样,但是可以在插入备份之前删除数据库
使用
创建转储时
-c
--clean
输出命令,以便在输出用于创建数据库对象的命令之前清理(删除)数据库对象。(除非-如果也指定了--如果--如果目标数据库中没有任何对象,那么restore可能会生成一些无害的错误消息。)此选项仅对纯文本格式有意义。对于归档格式,可以在调用pg_restore时指定选项。
对于pg_恢复也存在同样的情况,但是如果您在pg_dump中使用它,则这里不需要它
-c
--clean
在重新创建数据库对象之前清除(删除)数据库对象。(除非使用--如果存在,否则可能会生成一些无害的错误消息,如果目标数据库中没有任何对象。)
https://dba.stackexchange.com/questions/278984
复制相似问题