某次在使用pg_dump命令逻辑备份出来的备份文件对指定的几个表恢复的时候,报错pg_restore: implied data-only restore
当然,遇到问题首先就是百度了,但好像没有什么明确的解决方案,具体的报错命令和报错信息如下:
- [postgres@node1 ~]$ pg_restore -Upostgres -v -x -d pgbench -t ds.dr_route_ds -t ds.dr_task_active_ds 2023-08-02T04_00-ds.dump
- pg_restore: connecting to database for restore
- pg_restore: implied data-only restore
第二行表示pg_restore 命令已经正确连接到数据库,数据库名称是pgbench,准备开始备份
第三行表示 暗示恢复命令是仅恢复数据,然后就没有然后了!!!!
what fa?
仔细观察这个备份命令,发现是-d 数据库名称 -t 模式名称.该模式下的表名 -t 模式名称.该模式下的表名 -t 模式名称.该模式下的表名
OK,将模式名称去掉,发现可以正常的恢复了
- postgres@node1 ~]$ pg_restore -Upostgres -v -x -a -d pgbench -t dr_route_ds -t dr_task_active_ds 2023-08-02T04_00-ds.dump
- pg_restore: connecting to database for restore
- pg_restore: processing data for table "dr.dr_route_ds"
- pg_restore: processing data for table "dr.dr_task_active_ds"
- pg_restore: processing data for table "ds.dr_route_ds"
- pg_restore: processing data for table "ds.dr_task_active_ds"
但出现了一个问题,pgbench这个数据库下有两个scheme,也就是两个模式,两个模式有同样的两张表,我现在只想恢复ds模式下的这两张表的数据,并不想恢复dr模式下的这两张表的数据
因此,最终的恢复命令为加 -n参数,-指定ds模式:
- [postgres@node1 ~]$ pg_restore -Upostgres -v -x -a -d pgbench -n ds -t dr_route_ds -t dr_task_active_ds 2023-08-02T04_00-ds.dump
- pg_restore: connecting to database for restore
- pg_restore: processing data for table "ds.dr_route_ds"
- pg_restore: processing data for table "ds.dr_task_active_ds"