gpt4 book ai didi

postgresql - 我想用不同的模式恢复数据库

转载 作者:行者123 更新时间:2023-11-29 11:05:50 24 4
gpt4 key购买 nike

我已经使用以下命令转储了名为 temp1 的数据库

$  pg_dump -i -h localhost  -U postgres -F c -b -v -f pub.backup temp1 

现在我想在另一个名为“db_temp”的数据库中恢复转储,但我只希望所有表都应该在“temp_schema”中创建(而不是 fms temp1 数据库中的默认模式)它在“db_temp”数据库​​中。

有什么方法可以使用 pg_restore 命令来做到这一点吗?

任何其他方法也不胜感激!

最佳答案

一种快速而肮脏的方式:

1) 重命名默认架构:

alter schema public rename to public_save;

2) 创建新模式作为默认模式:

create schema public;

3)恢复数据

pg_restore -f pub.backup db_temp [and whatever other options]

4) 根据需要重命名模式:

alter schema public rename to temp_schema;
alter schema public_save rename to public;

关于postgresql - 我想用不同的模式恢复数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4191653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com