云数据库 GAUSSDB-gs_restore导入数据:示例

时间:2025-11-11 18:51:51

示例

gs_restore用来导入由gs_dump生成的导出文件。

  • 示例1:

    执行gs_restore,将导出的MPPDB_backup.dmp文件(自定义归档格式)导入到testdb数据库。

    gs_restore backup/MPPDB_backup.dmp -p 8000 -d testdb
    restore operation successful
    total time: 13053  ms
  • 示例2:

    执行gs_restore,将导出的MPPDB_backup.tar文件(tar格式)导入到testdb数据库。

    gs_restore backup/MPPDB_backup.tar -p 8000 -d testdb 
    restore operation successful
    total time: 21203  ms
  • 示例3:

    执行gs_restore,将导出的MPPDB_backup文件(目录格式)导入到testdb数据库。

    gs_restore backup/MPPDB_backup -p 8000 -d testdb
    restore operation successful
    total time: 21003  ms
  • 示例4:

    执行gs_restore,使用自定义归档格式的MPPDB_backup.dmp文件来进行如下导入操作。 导入PUBLIC模式下所有对象的定义和数据。在导入时会先删除已经存在的对象,如果原对象存在跨模式的依赖则需手工强制干预。

    gs_restore backup/MPPDB_backup.dmp -p 8000 -d testdb -e -c -n PUBLIC
    Error while PRO CES SING TOC:
    Error from TOC entry 313; 1259 337399 TABLE table1 gaussdba
    could not execute query: ERROR:  cannot drop table table1 because other objects depend on it
    DETAIL:  view t1.v1 depends on table table1
    HINT:  Use DROP ... CASCADE to drop the dependent objects too.
        Command was: DROP TABLE IF EXISTS public.table1;

    手工删除依赖,导入完成后再重新创建。

    gs_restore backup/MPPDB_backup.dmp -p 8000 -d testdb -e -c -n PUBLIC
    restore operation successful
    total time: 2203  ms
  • 示例5:

    执行gs_restore,使用自定义归档格式的MPPDB_backup.dmp文件来进行如下导入操作。只导入PUBLIC模式下表table1的定义。

    gs_restore backup/MPPDB_backup.dmp -p 8000 -d testdb -e -c -s -n PUBLIC -t table1
    restore operation successful
    total time: 21000  ms
  • 示例6:

    执行gs_restore,使用自定义归档格式的MPPDB_backup.dmp文件来进行如下导入操作。只导入PUBLIC模式下表table1的数据。

    gs_restore backup/MPPDB_backup.dmp -p 8000 -d testdb -e -a -n PUBLIC -t table1
    restore operation successful
    total time: 20203  ms
  • 特例:

    执行gsql程序,使用如下选项导入由gs_dump/gs_dumpall生成导出文件夹(纯文本格式)的MPPDB_backup.sql文件到testdb数据库。

    gsql -d testdb -p 8000 -f /home/omm/test/MPPDB_backup.sql
    SET
    SET
    SET
    SET
    SET
    ALTER TABLE
    ALTER TABLE
    ALTER TABLE
    ALTER TABLE
    ALTER TABLE
    CREATE INDEX
    CREATE INDEX
    CREATE INDEX
    SET
    CREATE INDEX
    REVOKE
    REVOKE
    GRANT
    GRANT
    total time: 30476  ms
    示例中“-f”后的是导出的文件,“8000”表示数据库服务器端口;“testdb”表示要访问的数据库名。
support.huaweicloud.com/tg-gaussdb-dist-v8/gaussdb-08-0013.html