小编lin*_*lof的帖子

如何使用 pg_dump 和 pg_restore 将大型数据库移动到另一台机器?

我有点不清楚如何使用pg_dump/ pg_restoreduo 移动大型数据库。

这是我用来转储数据库的命令(主机和用户名取自环境变量):

pg_dump --dbname=mydb --format=custom > mydb.dump
Run Code Online (Sandbox Code Playgroud)

我使用这种custom格式是因为我通过网络执行此操作并希望使用压缩。

当我现在尝试恢复它时,我尝试了以下操作:

pg_restore --dbname=mydb --no-owner mydb.dump
Run Code Online (Sandbox Code Playgroud)

但我得到:

pg_restore: [archiver (db)] connection to database "mydb" failed: FATAL:  database "mydb" does not exist
Run Code Online (Sandbox Code Playgroud)

我接下来尝试使用该--create选项,但这会产生相同的错误消息。

最后我尝试通过template1作为一个--dbname选项:

pg_restore --dbname=template1 --no-owner --create mydb.dump
Run Code Online (Sandbox Code Playgroud)

但这是我得到的:

pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2125; 1262 16395 DATABASE mydb mydbuser
pg_restore: [archiver (db)] could not execute query: ERROR:  invalid locale name: …
Run Code Online (Sandbox Code Playgroud)

postgresql migration

6
推荐指数
1
解决办法
9629
查看次数

标签 统计

migration ×1

postgresql ×1