• postgresql|数据库|恢复备份的时候报错:pg_restore: implied data-only restore的处理方案


    一,

    前情回顾

    某次在使用pg_dump命令逻辑备份出来的备份文件对指定的几个表恢复的时候,报错pg_restore: implied data-only restore  

    当然,遇到问题首先就是百度了,但好像没有什么明确的解决方案,具体的报错命令和报错信息如下:

    1. [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
    2. pg_restore: connecting to database for restore
    3. pg_restore: implied data-only restore

    第二行表示pg_restore 命令已经正确连接到数据库,数据库名称是pgbench,准备开始备份

    第三行表示    暗示恢复命令是仅恢复数据,然后就没有然后了!!!!

    what  fa?

    二,

    问题分析和解决方案

    仔细观察这个备份命令,发现是-d 数据库名称  -t 模式名称.该模式下的表名 -t 模式名称.该模式下的表名 -t 模式名称.该模式下的表名

    OK,将模式名称去掉,发现可以正常的恢复了

    1. 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
    2. pg_restore: connecting to database for restore
    3. pg_restore: processing data for table "dr.dr_route_ds"
    4. pg_restore: processing data for table "dr.dr_task_active_ds"
    5. pg_restore: processing data for table "ds.dr_route_ds"
    6. pg_restore: processing data for table "ds.dr_task_active_ds"

    但出现了一个问题,pgbench这个数据库下有两个scheme,也就是两个模式,两个模式有同样的两张表,我现在只想恢复ds模式下的这两张表的数据,并不想恢复dr模式下的这两张表的数据

    因此,最终的恢复命令为加 -n参数,-指定ds模式:

    1. [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
    2. pg_restore: connecting to database for restore
    3. pg_restore: processing data for table "ds.dr_route_ds"
    4. pg_restore: processing data for table "ds.dr_task_active_ds"

    ####注:

    • 参数-v 是显示恢复的过程,通常此参数是必加的
    • 参数-a 是只覆盖恢复数据不检查对象是否存在,比如,要恢复的表已存在,这个不检查,只把表数据覆盖到表内
    • 参数-x 如果逻辑备份文件内有包含权限的对象,例如用户什么的,使用此参数的时候将不执行相关操作,例如,某个用户的创建在此逻辑备份文件内,但不会执行,也不会检查
    • 参数-d 指定要恢复到哪个数据库内,也就是目标数据库
    • 参数-n 指定目标数据库下的scheme,也就是模式名称
    • 参数-t  指定要恢复的表的表名
    • 最后,逻辑备份文件前面不要加任何参数

  • 相关阅读:
    LeetCode 【算法专栏】 【图】
    Compose和AndroidView的交互
    Ubuntu18.04 ROS与Anaconda兼容并且在python3的虚拟环境下与ROS通信
    如何提升爬虫IP使用效率?精打细算的方法分享
    我参加NVIDIA Sky Hackathon 环境安装(编程环境)
    ping命令使用示例解析
    通过easyexcel导出数据到excel表格
    java-php-python-ssm家电产品售后计算机毕业设计
    【计算机毕业设计】外卖点餐源码
    一个完全纯净的windows资源站
  • 原文地址:https://blog.csdn.net/alwaysbefine/article/details/133780363