如何将 pg_dump 的输出恢复为新的表名

Ant*_*ony 4 postgresql pg-restore

我正在倾倒一个像这样的大型 Postgres 表:

pg_dump -h myserver  -U mt_user --table=mytable  -Fc -Z 9 --file mytable.dump mydb
Run Code Online (Sandbox Code Playgroud)

以上创建了一个mytable.dump文件。我现在想将此转储恢复到名为mytable_restored.

我怎样才能使用pg_restore命令来做到这一点?

Lau*_*lbe 7

没有pg_restore重命名表的选项。

我会这样做:

-- create a table that is defined like the original
CREATE TABLE mytable_restored (LIKE mytable INCLUDING ALL);

-- copy the table contents
COPY mytable TO '/tmp/mytable.dmp';
COPY mytable_restored FROM '/tmp/mytable.dmp';
Run Code Online (Sandbox Code Playgroud)