• openGauss学习笔记-88 openGauss 数据库管理-内存优化表MOT管理-内存表特性-使用MOT-MOT使用将磁盘表转换为MOT


    openGauss学习笔记-88 openGauss 数据库管理-内存优化表MOT管理-内存表特性-使用MOT-MOT使用将磁盘表转换为MOT

    磁盘表直接转换为MOT尚不能实现,这意味着尚不存在将基于磁盘的表转换为MOT的ALTER TABLE语句。

    下面介绍如何手动将基于磁盘的表转换为MOT,如何使用gs_dump工具导出数据,以及如何使用gs_restore工具导入数据。

    88.1 前置条件检查

    检查待转换为MOT的磁盘表的模式是否包含所有需要的列。

    检查架构是否包含任何不支持的列数据类型,具体参见“不支持的数据类型”章节。

    如果不支持特定列,则建议首先创建一个更新了模式的备磁盘表。此模式与原始表相同,只是所有不支持的类型都已转换为支持的类型。

    使用以下脚本导出该备磁盘表,然后导入到MOT中。

    88.2 转换

    要将基于磁盘的表转换为MOT,请执行以下步骤:

    1. 暂停应用程序活动。
    2. 使用gs_dump工具将表数据转储到磁盘的物理文件中。请确保使用data only。
    3. 重命名原始基于磁盘的表。
    4. 创建同名同模式的MOT。请确保使用创建FOREIGN关键字指定该表为MOT。
    5. 使用gs_restore将磁盘文件的数据加载/恢复到数据库表中。
    6. 浏览或手动验证所有原始数据是否正确导入到新的MOT中。下面将举例说明。
    7. 恢复应用程序活动。

    img 须知:

    由于表名称保持不变,应用程序查询和相关数据库存储过程将能够无缝访问新的MOT,而无需更改代码。另一种方法是通过INSERT INTO SELECT语句将数据从普通(堆)表复制到新的MOT表。

    INSERT INTO [MOT_table] SELECT * FROM [PG_table] WHERE condition;
    
    • 1

    此方法受MOT事务大小限制,小于1GB。

    88.3 转换示例

    假设要将数据库benchmarksql中一个基于磁盘的表customer迁移到MOT中。

    将customer表迁移到MOT,操作步骤如下:

    1. 检查源表列类型。验证MOT支持所有类型,详情请参阅“不支持的数据类型”章节。

      benchmarksql-# \d+ customer 
                             Table "public.customer" 
       Column |  Type   | Modifiers | Storage | Stats target | Description 
      --------+---------+-----------+---------+--------------+------------- 
       x      | integer |           | plain   |              | 
       y      | integer |           | plain   |              | 
      Has OIDs: no 
      Options: orientation=row, compression=no
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
    2. 请检查源表数据。

      benchmarksql=# select * from customer; 
       x | y 
      ---+--- 
       1 | 2 
       3 | 4 
      (2 rows)
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
    3. 只能使用gs_dump转储表数据。

      $ gs_dump -Fc benchmarksql -a --table customer -f customer.dump -p 16000
      gs_dump[port='15500'][benchmarksql][2020-06-04 16:45:38]: dump database benchmarksql successfully 
      gs_dump[port='15500'][benchmarksql][2020-06-04 16:45:38]: total time: 332  ms
      
      • 1
      • 2
      • 3
    4. 重命名源表。

      benchmarksql=# alter table customer rename to customer_bk; 
      ALTER TABLE
      
      • 1
      • 2
    5. 创建与源表完全相同的MOT。

      benchmarksql=# create foreign table customer (x int, y int); 
      CREATE FOREIGN TABLE 
      benchmarksql=# select * from customer; 
       x | y 
      ---+--- 
      (0 rows)
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
    6. 将源转储数据导入到新MOT中。

      $ gs_restore -C -d benchmarksql customer.dump -p 16000
      restore operation successful 
      total time: 24  ms 
      Check that the data was imported successfully. 
      benchmarksql=# select * from customer; 
       x | y 
      ---+--- 
       1 | 2 
       3 | 4 
      (2 rows) 
      
      benchmarksql=# \d 
                                      List of relations 
       Schema |    Name     |     Type      | Owner  |             Storage 
      --------+-------------+---------------+--------+---------------------------------- 
       public | customer    | foreign table | aharon | 
       public | customer_bk | table         | aharon | {orientation=row,compression=no} 
      (2 rows)
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18

    👍 点赞,你的认可是我创作的动力!

    ⭐️ 收藏,你的青睐是我努力的方向!

    ✏️ 评论,你的意见是我进步的财富!

    图片

  • 相关阅读:
    linux0.11 源码阅读 head.s setup.s bootsect.s加载位置
    【halcon】halcon字符识别——OCR
    瑞芯微RKNN开发·yolov5
    说话人识别声纹识别CAM++,ECAPA-TDNN等算法
    面试算法20:回文子字符串的个数
    【附源码】Python计算机毕业设计设计与实现大学常规信息管理系统
    信号:singal
    网工内推 | 技术支持工程师,厂商公司,HCIA即可,有带薪年假
    Java_IO流05:打印流、数据流、标准输入、输出流(了解)
    BHQ-3 amine,1661064-89-6可在430nm至730nm范围内猝灭所有普通荧光团
  • 原文地址:https://blog.csdn.net/shuchaoyang/article/details/133527769