Pg_restore 运行 ALTER TABLE .. OWNER 忽略 pg_dump --no-owner 选项

问题描述 投票:0回答:1

我正在使用 mac mini m1 和 postgresl14 进行数据库迁移。 对于迁移,需要更换所有者。

要导出所需的转储,我需要登录我的 Mac,调用

sudo su
成为 root 并使用以下命令:

pg_dump -Fc --no-owner --encoding=UTF8 -h 127.0.0.1 -U postgres [[dbname]] -n [[schemaname]] > upload.bak

[[dbname]]
[[schemaname]]
是此处的占位符。

之后,我将

upload.bak
文件上传到我的 ubuntu24 服务器实例。

在那个 ubuntu 服务器实例上,我尝试通过

导入文件
pg_restore -h 127.0.0.1 -U [[username]] -d [[dbname]] -n [[schemaname]]

导入开始运行,但它显示:

pg_restore: error: could not execute query: 
ERROR:  role "[[old_role]]" does not exist
Command was: ALTER TABLE [[schemaname]].[[tablename]] OWNER TO [[old_role]];

似乎

"-O"
大约。上面的
"--no-owner"
参数被完全忽略,即使我以 root 和 postgres 用户身份调用
pg_dump

如何指示

pg_dump
不导出“更新角色”语句?

postgresql pg-dump pg-restore
1个回答
0
投票

来自:

https://www.postgresql.org/docs/current/app-pgdump.html

--no-owner [...] 发出存档(非文本)输出文件时,此选项将被忽略。对于存档格式,您可以在调用 pg_restore 时指定该选项。

要完成此工作,您需要将

--no-owner
添加到
pg_restore
命令,如下所示:

pg_restore -h 127.0.0.1 --no-owner -U [[username]] -d [[dbname]] -n 
[[模式名称]]

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.