openGauss 数据库将磁盘表转换为 MOT

一、将磁盘表转换为 MOT 方法

磁盘表直接转换为 MOT 尚不能实现,这意味着尚不存在将基于磁盘的表转换为 MOT 的 ALTER TABLE 语句。目前 MOT 表也不支持 rename,create as select 以及 insert select(普通表)的操作。将基于磁盘的表转换为 MOT 方法,可以使用 gs_dump 工具导出数据,再使用 gs_restore 工具导入数据的方法。

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

二、操作示例:将表 enmo.customer_t1 转换为 MOT 表

1.确认 MOT 表支持表 customer_t1 所有列的数据类型

enmo=> \d

List of relations

Schema | Name | Type | Owner | Storage

--------+--------------+-------+-------+----------------------------------

enmo | all_data | table | enmo | {orientation=row,compression=no}

enmo | customer_t1 | table | enmo | {orientation=row,compression=no}

enmo | cux_setting | table | enmo | {orientation=row,compression=no}

enmo | data_studio1 | table | enmo | {orientation=row,compression=no}

enmo | table2 | table | enmo | {orientation=row,compression=no}

public | table1 | table | enmo | {orientation=row,compression=no}

(6 rows)

enmo=> \d+ customer_t1

Table "enmo.customer_t1"

Column | Type | Modifiers | Storage | Stats target | Description

-----------------+-----------------------+-----------+----------+--------------+-------------

c_customer_sk | integer | | plain | |

c_customer_name | character varying(32) | | extended | |

Has OIDs: no

Options: orientation=row, compression=no

enmo=>

2.暂停表 customer_t1 相关的应用程序操作后,使用 gs_dump 命令导出表数据(仅数据):

$ gs_dump -U enmo -h ... -p 15400 enmo -a --table customer_t1 -F c -f /home/omm/dump/customer_t1_data_only.bak

Password:

gs_dump[port='15400'][enmo][2021-03-28 10:11:42]: dump database enmo successfully

gs_dump[port='15400'][enmo][2021-03-28 10:11:42]: total time: 8732 ms

3.重命名原表 customer_t1 为 customer

enmo=> alter table customer_t1 rename to customer;

ALTER TABLE

4.创建与原表相同数据格式的 MOT 表 customer_t1

--首先给enmo用于赋予创建和访问MOT(DDL、DML、SELECT)权限:

enmo=> GRANT USAGE ON FOREIGN SERVER mot_server TO enmo;

GRANT

--创建外部表

enmo=> CREATE foreign TABLE customer_t1(c_customer_sk INTEGER, c_customer_name VARCHAR(32));

CREATE FOREIGN TABLE

Time: 9.408 ms

enmo=> \d+

List of relations

Schema | Name | Type | Owner | Size | Storage | Description

--------+--------------+---------------+-------+------------+----------------------------------+-------------

enmo | all_data | table | enmo | 8192 bytes | {orientation=row,compression=no} |

enmo | customer | table | enmo | 8192 bytes | {orientation=row,compression=no} |

enmo | customer_t1 | foreign table | enmo | 16 kB | |

enmo | cux_setting | table | enmo | 160 kB | {orientation=row,compression=no} |

enmo | data_studio1 | table | enmo | 8192 bytes | {orientation=row,compression=no} |

enmo | table2 | table | enmo | 8192 bytes | {orientation=row,compression=no} |

public | table1 | table | enmo | 8192 bytes | {orientation=row,compression=no} |

(7 rows)

enmo=> \d+ customer_t1

Foreign table "enmo.customer_t1"

Column | Type | Modifiers | FDW Options | Storage | Stats target | Description

-----------------+-----------------------+-----------+-------------+----------+--------------+-------------

c_customer_sk | integer | | | plain | |

c_customer_name | character varying(32) | | | extended | |

Server: mot_server

FDW permition: read/write

Has OIDs: no

enmo=> select * from customer_t1;

c_customer_sk | c_customer_name

---------------+-----------------

(0 rows)

Time: 0.782 ms

enmo=>

5.使用 gs_restore 将磁盘文件的数据加载/恢复到数据库表中

$ gs_restore -U enmo -h ... -p 15400 -d enmo /home/omm/dump/customer_t1_data_only.bak

Password:

start restore operation ...

table customer_t1 complete data imported !

Finish reading 3 SQL statements!

end restore operation ...

restore operation successful

total time: 3697 ms

6.浏览或手动验证所有原始数据是否正确导入到新的 MOT 中

enmo=> select * from customer_t1;

c_customer_sk | c_customer_name

---------------+-----------------

0 | data 0

2 | data 2

1 | new Data

(3 rows)

Time: 0.587 ms

enmo=>

openGauss数据库将磁盘表转换为MOT的更多相关文章

  1. MySQL中查询所有数据库占用磁盘空间大小和单个库中所有表的大小的sql语句

    查询所有数据库占用磁盘空间大小的SQL语句: ,),' MB') as data_size, concat(,),'MB') as index_size from information_schema ...

  2. 用java语言将数据库中的数据表转换为xml文件的通用程序(细化)

    转自:https://www.cnblogs.com/wudage/p/7650685.html 总是在网络上copy别人的源代码,今天我也贴出自己今天写的源码,相信这个程序会对大家在平时的工作中需要 ...

  3. 分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)

    分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...

  4. wordpress数据库优化wp_posts表 OPTIMIZE

    wordpress数据库优化wp_posts表 对 MySQL 数据记录进行插入.更新或删除时,会占有不同大小的空间,记录就会变成碎片,且留下空闲的空间.就像具有碎片的磁盘,会降低性能,需要整理,因此 ...

  5. (转)分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)

    分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...

  6. MySQL之终端(Terminal)管理数据库、数据表、数据的基本操作(转)

    MySQL有很多的可视化管理工具,比如“mysql-workbench”和“sequel-pro-”. 现在我写MySQL的终端命令操作的文章,是想强化一下自己对于MySQL的理解,总会比使用图形化的 ...

  7. c#创建access数据库和数据表

      由于在程序中使用了ADOX,所以先要在解决方案中引用之,方法如下: 解决方案资源管理器(项目名称)-->(右键)添加引用-->COM--> Microsoft ADO Ext. ...

  8. oracle下的数据库实例、表空间、用户及其表的区分

    完整的Oracle数据库通常由两部分组成:Oracle数据库和数据库实例. 1) 数据库是一系列物理文件的集合(数据文件,控制文件,联机日志,参数文件等): 2) Oracle数据库实例则是一组Ora ...

  9. Oracle数据库--解决单张表中数据量巨大(大数据、数据量上百万级别,后查询,更新数据等耗时剧增)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/QQ578473688/article/details/54561397 思路1:采用备份表 备份表中 ...

  10. Oracle数据表转换为Shapefile(二)

    在上一篇博文<Oracle数据表转换为Shapefile(一)>中详细描述了一种基于Oracle数据表生产Shapefile的技术方法,本文同样以详细图解的方式描述一种更便捷的方法来完成同 ...

随机推荐

  1. tomcat启动错误“The temporary upload location”

    目录 问题的原因 解决方案 临时的,直接重新启动项目就行,会重新建立临时文件夹 在配置文件中配置tomcat的临时目录: 写个配置类,通过@Bean的方式配置目录: 问题的原因 在Linux 系统中, ...

  2. [Linux] 无显示器 无键盘 网线直连传输文件

    有显示器可以操作 这种情况下要简单的多,基本思想是,网线直连之后让其中一方当作网关,分配好ip地址,比如说192.168.8.1,网关也是192.168.8.1即可,如果要填写子网掩码就写255.25 ...

  3. stm32OLED多级菜单

    今天实现了OLED多级菜单的显示.我用的是stm32f103ve,和四脚的OLED屏幕,用了三个按键. 话不多说,直接上代码. 点击查看代码 //先定义按键功能结构体 typedef struct { ...

  4. pandas plot函数:数据可视化的快捷通道

    一般来说,我们先用pandas分析数据,然后用matplotlib之类的可视化库来显示分析结果.而pandas库中有一个强大的工具--plot函数,可以使数据可视化变得简单而高效. 1. plot 函 ...

  5. gitee的 私人令牌 就是 Gitee Open API 的 access_token

    gitee的 私人令牌 就是 Gitee Open API 的 access_token

  6. WPF之命令

    目录 命令系统的基本元素 基本元素之间的关系 小试命令 WPF的命令库 命令参数 命令与Binding的结合 近观命令 ICommand接口与RoutedCommand 自定义Command 定义命令 ...

  7. deepin平台安装debian的cao蛋时

    我在deepin系统安装别的系统的时候,一直在boot界面无法进行下一步.困扰了我好几天,最后从电脑的左侧换成了电脑的右侧(usb)接口. 终于安装成功.你是......牛(deepin)

  8. pip 安装requirements.txt 的问题

    用新环境 在进行pip 安装的时候, 如果出现不进行安装 ,但是不报错就是满足条件,这个时候重新起一个shell,然后进行pip的安装.

  9. Window10系统通过软件切换扬声器与耳机的音源输出

    原文地址: Window10系统通过软件切换扬声器与耳机的音源输出 - Stars-One的杂货小窝 个人平常一般使用扬声器,但有时候直播或和别人打游戏的时候,可能会带上耳机 目前的情况就是手动去插播 ...

  10. Ubuntu 14.04 Intel 处理器 硬编解码配置(Intel® Media Server Studio)

    PS:要转载请注明出处,本人版权所有. PS: 这个只是基于<我自己>的理解, 如果和你的原则及想法相冲突,请谅解,勿喷. 前置说明   本文作为本人csdn blog的主站的备份.(Bl ...