- 开发者
- 数据库处理
#数据库处理#
-
只读原因当CN和DN的磁盘使用率达到阈值时,集群管理就会自动将相应的CN或DN分片设为只读(业务只能读不能写),执行cm_ctl query -Cv命令查询集群状态如下: 设置为只读后禁止业务继续写入,避免磁盘被撑爆,同时也避免后续无法扩容(扩容需要磁盘有一定的剩余空间)。只读guc参数datastorage_threshold_value_check磁盘使用率阈值,超过该阈值,就会被设置为只读,默认85%enable_transaction_read_only 检测磁盘只读的开关,如果关闭,不再检测磁盘,即使磁盘使用率超过阈值也不会设置只读,磁盘清空后也不会消除只读,默认值为on。datastorage_threshold_check_interval 检测磁盘使用率的时间间隔,多久检测一次磁盘使用率,默认为10秒。3个参数都在CMserver数据目录下的cm_server.conf配置文件中。处理措施当CN或DN被设置为只读时,根据上图中查到的CN或DN目录,检查所在磁盘使用率是否超过阈值。1、检查对应磁盘被什么文件占用,确认文件用途,是否可以清理或转移到其他磁盘。2、可以调高磁盘使用率阈值。可以通过如下命令修改CMserver的guc参数,支持reload修改参数,无需重启CMserver进程。确认集群是否有扩容计划,若有后续扩容计划,datastorage_threshold_value_check值建议不要超过50,扩容要求,数据磁盘使用率不超过50%。gs_guc reload -Z cmserver -N all -I all -c "datastorage_threshold_value_check = 85"gs_guc reload -Z cmserver -N all -I all -c "enable_transaction_read_only = on"当磁盘使用率超阈值时,集群管理会自动把CN、DN设置为只读,对应的guc参数default_transaction_read_only被设置为on。当磁盘使用率降到阈值以下或者调高阈值后,集群管理会自动把CN、DN解除只读,对应的guc参数default_transaction_read_only被设置为off。由于集群管理默认检测磁盘的周期是10s秒,所以磁盘超阈值或者降到阈值以下,或者通过gs_guc调整阈值,CN、DN的只读状态可能最长会延迟600秒才变化,请耐心等待。如果想马上去掉只读限制,除了清理磁盘或调整阈值外,手动设置对应的CN、DN的guc参数。DN、CN设置只读和取消只读参数:gs_guc reload -Z datanode -N nodename -D dataPath -c 'default_transaction_read_only = on' 设置DN只读gs_guc reload -Z datanode -N nodename -D dataPath -c 'default_transaction_read_only = off' 取消DN只读gs_guc reload -Z coordinator -N nodename -D dataPath -c 'default_transaction_read_only = on' 设置CN只读gs_guc reload -Z coordinator -N nodename -D dataPath -c 'default_transaction_read_only = off' 取消CN只读
-
10月17,《GaussDB入门级开发者认证》技术解读2直播——实践篇,专家为您现场演示沙箱,拆解考试样题,帮助用户提高认证通过率。参与直播,送499元代金券,还有移动电源、公牛插座等你来!活动链接:cid:link_0
-
1 背景 我们平时会写各种各样或简单或复杂的sql语句,提交后就会得到我们想要的结果集。比如sql语句,”select * from t_user where user_id > 10;”,意在从表t_user中筛选出user_id大于10的所有记录。你有没有想过从一条sql到一个结果集,这中间经历了多少坎坷呢?2 SQL引擎 从MySQL、Oracle、TiDB、CK,到Hive、HBase、Spark,从关系型数据库到大数据计算引擎,他们大都可以借助SQL引擎,实现“接受一条sql语句然后返回查询结果”的功能。他们核心的执行逻辑都是一样的,大致可以通过下面的流程来概括:中间蓝色部分则代表了SQL引擎的基本工作流程,其中的词法分析和语法分析,则可以引申出“抽象语法树”的概念。3 抽象语法树 3.1 概念 高级语言的解析过程都依赖于解析树(Parse Tree),抽象语法树(AST,Abstract Syntax Tree)是忽略了一些解析树包含的一些语法信息,剥离掉一些不重要的细节,它是源代码语法结构的一种抽象表示。以树状的形式表现编程语言的结构,树的每个节点ASTNode都表示源码中的一个结构;AST在不同语言中都有各自的实现。解析的实现过程这里不去深入剖析,重点在于当SQL提交给SQL引擎后,首先会经过词法分析进行“分词”操作,然后利用语法解析器进行语法分析并形成AST。下图对应的SQL则是“select username,ismale from userInfo where age>20 and level>5 and 1=1”; 这棵抽象语法树其实就简单的可以理解为逻辑执行计划了,它会经过查询优化器利用一些规则进行逻辑计划的优化,得到一棵优化后的逻辑计划树,我们所熟知的“谓词下推”、“剪枝”等操作其实就是在这个过程中实现的。得到逻辑计划后,会进一步转换成能够真正进行执行的物理计划,例如怎么扫描数据,怎么聚合各个节点的数据等。最后就是按照物理计划来一步一步的执行了。3.2 ANTLR4 解析(词法和语法)这一步,很多SQL引擎采用的是ANTLR4工具实现的。ANTLR4采用的是构建G4文件,里面通过正则表达式、特定语法结构,来描述目标语法,进而在使用时,依赖语法字典一样的结构,将SQL进行拆解、封装,进而提取需要的内容。下图是一个描述SQL结构的G4文件。3.3 示例 3.2.1 SQL解析 在java中的实现一次SQL解析,获取AST并从中提取出表名。首先引入依赖: org.antlr antlr4-runtime 4.7在IDEA中安装ANTLR4插件;示例1,解析SQL表名。使用插件将描述MySQL语法的G4文件,转换为java类(G4文件忽略)。类的结构如下:其中SqlBase是G4文件名转换而来,SqlBaseLexer的作用是词法解析,SqlBaseParser是语法解析,由它生成AST对象。HelloVisitor和HelloListener:进行抽象语法树的遍历,一般都会提供这两种模式,Visitor访问者模式和Listener监听器模式。如果想自己定义遍历的逻辑,可以继承这两个接口,实现对应的方法。读取表名过程,是重写SqlBaseBaseVisitor的几个关键方法,其中TableIdentifierContext是表定义的内容;SqlBaseParser下还有SQL其他“词语”的定义,对应的就是G4文件中的各类描述。比如TableIdentifierContext对应的是G4中TableIdentifier的描述。3.2.2 字符串解析 上面的SQL解析过程比较复杂,以一个简单字符串的解析为例,了解一下ANTLR4的逻辑。1)定义一个字符串的语法:Hello.g42)使用IDEA插件,将G4文件解析为java类3)语法解析类HelloParser,内容就是我们定义的h和world两个语法规则,里面详细转义了G4文件的内容。4)HelloBaseVisitor是采用访问者模式,开放出来的接口,需要自行实现,可以获取xxxParser中的规则信息。5)编写测试类,使用解析器,识别字符串“hi abc”:6)调试后发现命中规则h,解析为Hi和abc两部分。7)如果是SQL的解析,则会一层层的获取到SQL中的各类关键key。4 SqlParser 利用ANTLR4进行语法解析,是比较底层的实现,因为Antlr4的结果,只是简单的文法解析,如果要进行更加深入的处理,就需要对Antlr4的结果进行更进一步的处理,以更符合我们的使用习惯。利用ANTLR4去生成并解析AST的过程,相当于我们在写rpc框架前,先去实现一个netty。因此在工业生产中,会直接采用已有工具来实现解析。Java生态中较为流行的SQL Parser有以下几种(此处摘自网络):fdb-sql-parser 是FoundationDB在被Apple收购前开源的SQL Parser,目前已无人维护。jsqlparser 是基于JavaCC的开源SQL Parser,是General SQL Parser的Java实现版本。Apache calcite 是一款开源的动态数据管理框架,它具备SQL解析、SQL校验、查询优化、SQL生成以及数据连接查询等功能,常用于为大数据工具提供SQL能力,例如Hive、Flink等。calcite对标准SQL支持良好,但是对传统的关系型数据方言支持度较差。alibaba druid 是阿里巴巴开源的一款JDBC数据库连接池,但其为监控而生的理念让其天然具有了SQL Parser的能力。其自带的Wall Filer、StatFiler等都是基于SQL Parser解析的AST。并且支持多种数据库方言。Apache Sharding Sphere(原当当Sharding-JDBC,在1.5.x版本后自行实现)、Mycat都是国内目前大量使用的开源数据库中间件,这两者都使用了alibaba druid的SQL Parser模块,并且Mycat还开源了他们在选型时的对比分析Mycat路由新解析器选型分析与结果.4.1 应用场景 当我们拿到AST后,可以做什么?语法审核:根据内置规则,对SQL进行审核、合法性判断。查询优化:根据where条件、聚合条件、多表Join关系,给出索引优化建议。改写SQL:对AST的节点进行增减。生成SQL特征:参考JIRA的慢SQL工单中,生成的指纹(不一定是AST方式,但AST可以实现)。4.2 改写SQL 提到改写SQL,可能第一个思路就是在SQL中添加占位符,再进行替换;再或者利用正则匹配关键字,这种方式局限性比较大,而且从安全角度不可取。基于AST改写SQL,是用SQL字符串生成AST,再对AST的节点进行调整;通过遍历Tree,拿到目标节点,增加或修改节点的子节点,再将AST转换为SQL字符串,完成改写。这是在满足SQL语法的前提下实现的安全改写。以Druid的SQL Parser模块为例,利用其中的SQLUtils类,实现SQL改写。4.2.1 新增改写 1)原始SQL2)实际执行SQL4.2.2 查询改写前面省略了Tree的遍历过程,需要识别诸如join、sub-query等语法1)简单join查询原始SQL实际执行SQL2)join查询+隐式where条件原始SQL实际执行SQL3)union查询+join查询+子查询+显示where条件原始SQL(unionQuality_Union_Join_SubQuery_ExplicitCondition)实际执行SQL5 总结 本文是基于环境隔离的技术预研过程产生的,其中改写SQL的实现,是数据库在数据隔离上的一种尝试。可以让开发人员无感知的情况下,以插件形式,在SQL提交到MySQL前实现动态改写,只需要在数据表上增加字段、标识环境差异,后续CRUD的SQL都会自动增加标识字段(flag=’预发’、flag=’生产’),所操作的数据只能是当前应用所在环境的数据。来源:51CTO
-
索引及其作用 索引(Index)是帮助 MySQL 高效获取数据的数据结构。索引的本质是数据结构。索引作用是帮助 MySQL 高效获取数据。通俗的说,索引就像一本书的目录,通过目录去找想看的章节就很快,索引也是一样的。如果没有索引,MySQL在查询数据的时候就需要从第一行数据开始一行一行数据对比,只能扫描完整个表找到要查询的数据,表的数据越多需要花费的时间越多。如果表中有相关列的索引,MySQL可以快速确定在数据文件中间查找的位置,而无需查看所有数据,这比按顺序读取每一行要快得多。索引常用的数据结构有BTREE、HASH、RTREE等等,其中数BTREE最为常见。索引的分类 索引分为聚集索引和二级索引。聚集索引 InnoDB引擎中使用了聚集索引(Clustered index),就是将表的主键用来构造一棵B+树,并且将整张表的行记录数据存放在该 B+树的叶子节点中。也就是所谓的索引即数据,数据即索引。由于聚集索引是利用表的主键构建的,所以每张表只能拥有一个聚集索引。一般来说,在MySQL中聚集索引和主键是一个意思。聚集索引的叶子节点就是数据页。换句话说,数据页上存放的是完整的每行记录。因此聚集索引的一个优点就是:通过过聚集索引能获取完整的整行数据。另一个优点是:对于主键的排序查找和范围查找速度非常快。如果没有设置主键的话,MySQL默认会创建一个隐含列row_id作为主键。二级索引 二级索引(Secondary Index,也称辅助索引、非聚集索引)是InnoDB引擎中的一类索引,聚集索引以外的索引统称为二级索引,包括唯一索引、联合索引、全文索引等等。二级索引并不包含行记录的全部数据,二级索引上除了当前列以外还包含一个主键,通过这个主键来查询聚集索引上对应的数据。当查询除索引以外的其他数据时,由于数据不在索引上就需要通过主键来找到完整的行记录,这就是回表。针对二级索引MySQL提供了一个优化技术,索引覆盖(covering index)。即从辅助索引中就可以得到查询的记录,就不需要回表再根据聚集索引查询一次完整记录。使用索引覆盖的一个好处是辅助索引不包含整行记录的所有信息,故其大小要远小于聚集索引,因此可以减少大量的IO操作,但是前提是要查询的所有列必须都加了索引。唯一索引 唯一索引(Unique Index)要求列的数据必须是唯一的,唯一索引具有唯一性约束,在插入数据时,如果有列中有相同的数据就会报错。唯一索引可以允许多个列的值为NULL,如果列是字符串类型的话,空字符串值只能有一个。全文索引 全文索引(Full-Text Index)只有在MyISAM和InnoDB存储引擎中支持,全文索引只能创建在基于文本的列上,例如CHAR、VARCHAR、TEXT类型。全文索引不支持索引前缀,即使设置了索引前缀也不会起作用。全文索引采用的是倒排索引(inverted index)设计,倒排索引就是将文档中包含的关键字全部提取处理,然后再将关键字和文档之间的对应关系保存起来,最后再对关键字本身做索引排序。用户在检索某一个关键字时,先对关键字的索引进行查找,再通过关键字与文档的对应关系找到所在文档。为了支持邻近搜索,还存储每个单词的位置信息,作为字节偏移量。MySQL 从设计之初就是关系型数据库,存储引擎虽然支持全文检索,整体架构上对全文检索支持并不好而且限制很多,比如每张表只能有一个全文检索的索引,不支持没有单词界定符(delimiter)的语言,如中文、日语、韩语等。全文索引辅助表创建一个db_test数据库,并创建一个users表,users表结构如下在name字段上创建全文索引:ALTER TABLE `users` ADD FULLTEXT INDEX `idx_name` (`name`);然后查看INNODB_SYS_TABLES中db_test数据库信息SELECT table_id, name, space from INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE name LIKE 'db_test/%';当全文索引创建时就会创建一组辅助索引表,前六个表就是辅助索引表。辅助索引表以 FTS_ 开头,以index_# 结尾,每个辅助索引表的表名都和全文索引所在表的table_id的十六进制值关联。比如db_test/users的table_id是170,170对应的十六进制是0xaa,辅助索引表的表名就用aa作为其表名的一部分,以便和db_test/users表关联。全文索引的index_id也可以通过辅助索引表的表名获取,拿第一个辅助索引表db_test/FTS_00000000000000aa_00000000000000fb_INDEX_1举例,fb就是index_id的十六进制表示,换算成十进制是251,所以index_id=251.可通过以下SQL语句验证index_id:SELECT index_id, name, table_id, space from INFORMATION_SCHEMA.INNODB_SYS_INDEXES WHERE index_id = 251;db_test/users表的table_id=170,通过index_id = 251查询到的table_id也是170,并且索引名称也是我们创建的idx_name,所以这个index_id就是我们创建的全文索引的id。多列索引 多列索引(Multiple-Column Index,又称联合索引、复合索引)顾名思义就是几个列共同组成一个索引。多列索引最多由16个列组成。多列索引遵守最左前缀原则。最左前缀原则就是在查询数据时,以最左边的列为基准进行索引匹配。例如,有个索引mul_index(col1, col2, col3),在进行索引查询的时候,只有(col1)、(col1, col2)和(col1, col2, col3)这三种组合才能使多列索引mul_index(col1, col2, col3)生效。就是说col1只能在查询时被用到,这个索引就能被用到,索引在创建多列索引时一定要将查询最频繁的列放到最左边。空间索引 MyISAM、InnoDB、NDB和ARCHIVE存储引擎都支持空间索引(Spatial Indexe),但是要求列必须是POINT和GEOMETRY相关类型。但是,对空间列索引的支持因引擎而异,可根据以下规则使用空间列上的空间和非空间索引。1.空间索引在空间列上有以下特性:只有MyISAM和InnoDB可以使用,如果在创建时指定其他存储引擎会报错索引列必须是NOT NULL不允许使用索引前缀2.非空间索引在空间列上有以下特性:允许用于除ARCHIVE存储引擎之外的任何支持空间列的存储引擎。列值可以为NULL,除非是唯一索引。非空间索引在空间列时,除了列的类型是POINT之外,在创建索引的时候都要指定索引前缀并且索引前缀长度是以字节为单位的。非空间索引在空间列的数据结构取决于存储引擎,目前使用的是BTREE。在InnoDB、MyISAM和 MEMORY存储引擎中允许空间列的值为NULL。空间索引主要用于列类型是地理位置或者坐标之类的列上的,空间索引主要使用的是R-Tree。自适应哈希索引 自适应哈希索引(Adaptive Hash Index)是InnoDB表的优化,可以通过在内存中构造哈希索引来加速使用 = 和 IN 运算符的查找。InnoDB 存储引擎内部自己去监控索引表,如果监控到某个索引频繁使用,那么就认为是热数据,然后内部就会自动创建一个 hash 索引。从某种意义上说,自适应哈希索引在运行时对MySQL进行配置,以利用充足的主存,这样更接近主存数据库的架构。这个特性是由innodb_adaptive_hash_index参数控制的,默认是开启的。可以通过以下命令查看自适应hash索引的使用状况show engine innodb statusstatus字段内容很长,有兴趣的可以自己试试看下,里面有这么一段:-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 195, seg size 197, 0 mergesmerged operations: insert 0, delete mark 0, delete 0discarded operations: insert 0, delete mark 0, delete 0Hash table size 2267, node heap has 0 buffer(s)Hash table size 2267, node heap has 2 buffer(s)Hash table size 2267, node heap has 0 buffer(s)Hash table size 2267, node heap has 1 buffer(s)Hash table size 2267, node heap has 0 buffer(s)Hash table size 2267, node heap has 1 buffer(s)Hash table size 2267, node heap has 0 buffer(s)Hash table size 2267, node heap has 1 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s通过 hash searches: nonhash searches 可以大概了解使用哈希索引后的效率。索引的增删改查 新增索引 新增索引有三种方式:使用create index 语句使用alter 语句在CREATE TABLE的时候创建索引前两种方式都是在创建好表以后再给表新增索引的,第三种是在创建表的同时创建索引CREATE TABLE 创建索引 例如:CREATE TABLE `test` (`id` int NOT NULL AUTO_INCREMENT ,`name` varchar(255) NULL ,PRIMARY KEY (`id`),INDEX `idx` (`name`) )CREATE INDEX 创建索引语法:CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name [index_type] ON tbl_name (key_part,...) [index_option] [algorithm_option | lock_option] ...key_part: col_name [(length)] [ASC | DESC]index_option: { KEY_BLOCK_SIZE [=] value | index_type | WITH PARSER parser_name | COMMENT 'string'}index_type: USING {BTREE | HASH}algorithm_option: ALGORITHM [=] {DEFAULT | INPLACE | COPY}lock_option: LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE}带中括号[]的都是可选项,可写可不写,[=]表示等于号可要可不要key_part:col_name [(length)] [ASC | DESC] :表示列名、索引前缀长度、升序或降序index_type:表示使用BTREE或HASH作为索引的数据结构index_option:索引的可选项,包括索引类型、备注、PARSER、KEY_BLOCK_SIZE 等algorithm_option:算法的选择,可选值为DEFAULT、INPLACE、COPYlock_option:锁的选择,可选值为DEFAULT、NONE、SHARED(共享锁)、EXCLUSIVE(排它锁)示例:CREATE INDEX index_name USING BTREE ON account(amount DESC) COMMENT 'string' ALGORITHM INPLACE LOCK SHARED;ALTER TABLE 创建索引 语法:ALTER TABLE tbl_name ADD {UNIQUE | FULLTEXT | SPATIAL} INDEX index_name(key_part,...) [index_option]index_option: { KEY_BLOCK_SIZE [=] value | index_type | WITH PARSER parser_name | COMMENT 'string'示例:-- 添加唯一索引ALTER TABLE `account` ADD UNIQUE INDEX `uk` (`amount`) USING BTREE;ALTER TABLE 和 CREATE INDEX 创建索引的区别:ALTER 本身有修改的意思,所以可以对索引进行增删改,而CREATE只能创建索引CREATE不能创建主键,ALTER可以CREATE INDEX 可以指定索引算法ALGORITHM和LOCK,ALTER在添加索引的时候不能指定。修改索引 修改索引是先删除之前的索引,然后重新添加ALTER TABLE tableName DROP INDEX oldIndexName,ADD INDEX indexName(columns ...) USING BTREE;删除索引 删除索引有两种方式:ALTER TABLE tableName DROP INDEX indexName;或DROP INDEX indexName ON tableName;索引查询 SHOW INDEX FROM tableName;索引前缀 对于字符串类型的索引,在创建索引的时候可以指定以索引的前多少个字符作为索引,可以通过使用col_name(length)语法来指定索引前缀长度,这样可以节省空间和查询效率。索引前缀使用范围及注意事项:可以给类型为CHAR、VARCHAR、BINARY和VARBINARY的列指定前缀。如果给类型是BLOB或者TEXT的列创建索引,必须为其指定前缀。此外,BLOB和TEXT类型的列只能在存储引擎是InnoDB、MyISAM和BLACKHOLE的表上建立索引。索引前缀的长度是以字节为单位的。对于非二进制的(CHAR,VARCHAR,TEXT)的字符类型来说,长度指的是字符的长度。对于二进制的(BINARY, VARBINARY, BLOB)字符类型来说,长度指的是字节的长度。使用多字节的字符编码时,在给二进制的字符类型的列设置长度时要考虑这些。索引前缀长度是否支持或者如何支持取决于存储引擎。对于InnoDB引擎来说,索引前缀长度可以最多可以支持767 bits,如果innodb_large_prefix参数开启,最多能支持3072 bits。对于MyISAM引擎来说,索引前缀的长度被限制在1000 bits以内。对于NDB引擎来说,压根就不支持索引前缀。从 MySQL 5.7.17 开始,如果指定的索引前缀超过最大列数据类型大小,CREATE INDEX会按如下方式处理索引:对于非唯一索引,要么发生错误(如果启用了SQL严格模式),要么索引长度减少到列数据类型大小内并产生警告(如果未启用严格SQL模式)。对于唯一索引,无论SQL模式如何都会发生错误,因为减少索引长度可能会导致插入不满足指定唯一性要求的非唯一条目。如果列的前n(n < 列的数据类型长度)个字符不同,使用索引前缀可能不会比使用整个列做索引慢,而且使用索引前缀索引文件更小,可以省更多磁盘空间并且可能会提高插入时的效率。索引的选择性 索引的选择性是指不重复的索引值(也称为基数,cardinality)和数据表的记录总数(N)的比值,取值范围是1/N到1之间。索引的选择性越高则查询效率越高,因为选择性高的索引可以让MySQL 在查找时过滤掉更多的行。唯一索引的选择性是1,这是最好的索引选择性,性能也是最好的。创建索引时要选择索引选择性高的值创建索引。比如有一百条数据,重复的行数有10条,那么索引的选择性就是10/100,也就是0.1。索引的选择性可以通过下列计算方式带入计算:SELECT COUNT(DISTINCT col...) / COUNT(*) FROM table_name;索引的代价 索引是把双刃剑,有利有弊。利:方面就是能提高查询效率。弊端主要是两个方面:空间代价:每创建一个就会产生一个索引数据文件占用磁盘空间,索引越多占用的磁盘空间也就越大。时间代价:虽然索引是提高了查询效率,但同时也降低了插入、删除和更新的效率。每次对数据进行增删改操作的同时也是在对索引的更改,索引越多更改时需要花费的时间越多。总结本文只是对索引进行一个简单的介绍。索引是把双刃剑,用的好可以提升系统查询效率,用的不好效率不升反降得不偿失。来源:51cto
-
1.基于JDBC连接openGauss1)准备java环境 下载安装jdk1.8,我这里是jdk-16.0.1配置环境变量: 我的电脑——>属性——>高级系统设置——>环境变量 系统环境变量:JAVA_HOME:D:\Program Files\Java\jdk-16.0.1 Path:增加:%JAVA_HOME%\bin CLASSPATH:.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar;打开控制台(win+r——>输入cmd),查看jdk版本:2)在linux中下载openGauss jdbc驱动程序,并解压,或者直接在windows中下载解压,也是可以的:[root@OG1 ~]# wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.1.0/x86/openGauss-2.1.0-JDBC.tar.gz [root@OG1 ~]# tar -zxvf openGauss-2.1.0-JDBC.tar.gz postgresql.jar #将jar包传送到windows宿主机 [root@OG1 ~]# sz postgresql.jar3)配置集成开发环境IntelliJ IDEA :创建一个项目:openGauss点击Project structure:配置jdk环境和openGauss JDBC驱动:配置jdk环境:配置jdbc jar包:依次点击Libraries——>+号——>java——>然后选择jar的存放位置,4)配置客户端接入认证:因为虚拟主机采用的是NAT模式上网,所以它与windows宿主机之间是通过VMnet8虚拟网卡进行通信的。此时VMnet8的IP地址为:10.0.0.1:允许zb用户通过这个主机进行远程连接数据库test:[omm@OG1 ~]$ gs_guc reload -N all -I all -h "host test zb 10.0.0.1/24 sha256"5)连接数据库(不使用ssl方式连接)在项目下创建一个测试类:右键src——>new——>java class:Jdbc_conimport java.sql.Connection; import java.sql.DriverManager; import java.util.Properties; public class Jdbc_con { public static void main(String args[]) { Connection conn1 = getConnect("zb","Test@123"); try { conn1.close(); System.out.println("Disconnect succeed!!"); }catch(Exception e){ e.printStackTrace(); } } //以下代码将获取数据库连接操作封装为一个接口,可通过给定用户名和密码来连接数据库。 public static Connection getConnect(String username, String passwd){ //驱动类 String driver = "org.postgresql.Driver"; //数据库连接描述符 String sourceURL = "jdbc:postgresql://10.0.0.100:15400/test"; Connection conn = null; try { //加载驱动 Class.forName(driver); } catch(Exception e) { e.printStackTrace(); return null; } try { //创建连接 conn = DriverManager.getConnection(sourceURL, username, passwd); System.out.println("Connection succeed!"); } catch (Exception e){ e.printStackTrace(); return null; } return conn; } // 以下代码将使用Properties对象作为参数建立连接 public static Connection getConnectUseProp(String username, String passwd){ //驱动类 String driver = "org.postgresql.Driver"; //数据库连接描述符 String sourceURL = "jdbc:postgresql://10.0.0.100:15400/test?"; Connection conn = null; Properties info = new Properties(); try { //加载驱动 Class.forName(driver); } catch(Exception e) { e.printStackTrace(); return null; } try { info.setProperty("user",username); info.setProperty("password",passwd); //创建连接 conn = DriverManager.getConnection(sourceURL, info); System.out.println("Connection succeed!"); }catch (Exception e){ e.printStackTrace(); return null; } return conn; } }复制执行代码测试连接:表示连接成功!!
-
在Oralce数据库中,遇到性能问题,我们通常会查看有无对应时间段的快照,生成awr报告并进一步分析(AWR是Automatic Workload Repository的简称,中文叫着自动工作量资料档案库。是Oracle数据库用于收集、管理和维护数据库整个运行期间和性能相关统计数据的存储仓库,是Oracle数据库性能调整和优化的基础。awr收集到的数据会被定期保存到磁盘,可以从数据字典查询以及生成性能报告。)。AWR报告整个数据库在运行期间的现状或者说真实状态只有在被完整记录下来,才是可查,可知,可比较,可推测或者说为未来性能优化调整提供支撑建议的基础。在opengauss数据库中,也有着这样的“awr”,它叫做——wdr。WDR是(Workload Diagnosis Report)负载诊断报告,是openGauss的工作负载诊断报告,常用于判断openGauss长期性能问题。前提:生成WDR报告的前提条件是,打开参数enable_wdr_snapshot。确认当前已按照的openGauss数据库是否打开WDR报告的参数,需要通过下图登录数据库进行查询。enable_wdr_snapshot的值为on表示打开,off表示关闭以下介绍WDR报告的参数:序号参数参数说明取值范围1enable_wdr_snapshot是否开启数据库监控快照功能取值范围:布尔型on: 打开数据库监控快照功能。off: 关闭数据库监控快照功能。默认值: off2wdr_snapshot_interval后台线程Snapshot自动对数据库监控数据执行快照操作的时间间隔取值范围: 整型,10~60(分钟)默认值: 1h3wdr_snapshot_query_timeout系统执行数据库监控快照操作时,设置快照操作相关的sql语句的执行超时时间。如果语句超过设置的时间没有执行完并返回结果,则本次快照操作失败取值范围: 整型,100~INT_MAX(秒)默认值: 100s4wdr_snapshot_retention_days系统中数据库监控快照数据的保留天数,超过设置的值之后,系统每隔wdr_snapshot_interval时间间隔,清理snapshot_id最小的快照数据取值范围: 整型,1~8默认值: 8操作步骤:1.执行以下SQL命令,查询已经生成的快照信息。select * from snapshot.snapshot;snapshot.snapshot 【记录当前系统中存储的WDR快照信息】2.生成WDR报告。执行如下步骤,生成节点node级别wdr报告。1)查询 pgxc_node_name参数值,或者使用查询视图:pg_node_env。2) \a \t \o 服务器文件路径生成格式化性能报告\a \t \o /home/opengauss/wdrTest.html上述命令涉及参数说明如下:\a:切换非对齐模式。\t:切换输出的字段名的信息和行计数脚注。\o:把所有的查询结果发送至服务器文件里。服务器文件路径:生成性能报告文件存放路径。用户需要拥有此路径的读写权限。如果不退出当前登录gsql客户端,进行执行其他SQL,关闭格式化输出命令:\o \a \t3)向性能报告wdrTest.html中写入数据,从snapshot.snapshot视图中选取要生成WDR报告的时间点。例如:127和128两个时间点。gsql -d postgres -p 6000 -r -c"select generate_wdr_report(快照id1,快照id2,‘all’,‘node’,‘pgxc_node_name参数值’);"select generate_wdr_report(127,128,'all','node','dn_6001');函数说明:generate_wdr_report语法select generate_wdr_report(begin_snap_id bigint, end_snap_id bigint, report_type cstring, report_scope cstring, node_name cstring);选项:begin_snap_id:查询时间段开始的snapshot的id(表snapshot.snaoshot中的snapshot_id)end_snap_id: 查询时间段结束snapshot的id。默认end_snap_id大于begin_snap_id(表snapshot.snaoshot中的snapshot_id)report_type: 指定生成report的类型。例如,summary/detail/all,其中:summary[汇总数据]/detail[明细数据]/all[包含summary和detail]report_scope: 指定生成report的范围,可以为cluster或者node,其中:cluster是数据库级别的信息,node是节点级别的信息。node_name: 当report_scope指定为node时,需要把该参数指定为对应节点的名称。当report_scope为cluster时,该值可以省略或者指定为空或NULL。node[节点名称]、cluster[省略/空/NULL]4)目录下生成对应的wdr报告,cd /home/opegauss生成报告的指定路径进行查看。3.手工创建快照信息当在openGauss数据库执行性能测试,数据库默认每小时自动执行一次snapshot操作。生成指定时间段内的WDR报告,查询快照视图后选取指定开始时间的快照id,结束时间的快照id。通过函数generate_wdr_report生成wdr报告。但是有些情况,固定时间段的WDR报告,就需要使用具有sysadmin权限用户手工创建快照信息,需要执行两次。具体操作步骤如下:1)首先确认一下,当前的快照信息视图snapshot.snapshot中的时间节点。2)执行函数create_wdr_snapshot()创建快照手工创建wdr报告快照执行语句:select create_wdr_snapshot();3)等待10分钟以后再次执行函数create_wdr_snapshot(),手工创建结束快照。4)执行操作步骤第二步:生成WDR报告,执行如下图步骤,生成节点node级别wdr报告(其中dn_6001客户端gsql登录数据show pgxc_node_name查询的结果)。4.WDR涉及的数据表说明:WDR的数据表保存在snapshot这个schema下以snap_开头的表,其数据来源于dbe_perf这个schema内的视图,总共61张视图。5.WDR报告解读说明:为了使得WDR报告内容不空洞,本次在测试环境使用BenchmarkSQL5.0对openGauss数据库进行100warehouse,100并发压力测试。 本次的WDR报告样例来自于此时手工创建的快照数据。手工生成WDR报告后,通过浏览器查看。opengauss的wdr报告类似于oracle的awr,拥有资源消耗、等待事件、TOPSQL,以及参数设置等。1)下图是执行前tpcc表信息:2)以下是手工创建的快照开始时间点:3)开始执行benchmarksql,运行10分钟完成后。手工再次生成wdr报告的结束快照。4)生成wdr报告如下图:5)以下是解读WDR报告开头介绍了一下当前wdr报告概况信息:信息分类信息描述报告采集类型Summary + Detail,即汇总数据+明细数据Snapshot信息使用snapshot_id为24和25的快照采集2022-10-09(15:28 ~ 15:39)的运行信息硬件配置X*Xc/GB节点名dn_6001openGauss版本openGauss 3.0.0类别分类明细作用SummaryInstance Efficiency Percentages实例的效率百分比Top 10 Events by Total Wait Time事件等待时间排名前10Wait Classes by Total Wait Time按照等待类型分类Host_CPU主机CPU的负载情况IO Profile描述了openGauss在快照期间的IO负载情况Memory_Statistics描述了节点内存的变化信息Report DetailsTime Model描述了数据库各种状态所消耗的时间SQL Statistics从SQL执行时间、SQL消耗CPU的时间、SQL返回的行数、SQL扫描的行数、SQL执行的次数、SQL物理读的次数、SQL逻辑读的次数等多维度对两次快照期间的SQL执行情况进行统计Wait Events从等待时长、等待次数这两个维度对等待事件进行统计Cache IO Stats根据Heap block的命中率排序统计用户表的IO活动状态Utility status描述的是后台写操作的统计信息Object stats描述用户表状态的统计信息Configuration settings描述的是数据库参数配置信息SQL Detail描述的是SQL语句的详细信息
-
由于平时工作中使用Navicat比较多,数据库基本通过Navicat来管理操作。本文将介绍如何使用Navicat进行远程连接openGauss服务设置主要修改pg_hba.conf和postgresql.conf两个文件。找到这两个文件所在目录极简版所在目录:/opt/software/openGauss/data/single_node/企业版所在目录:/opt/huawei/install/data/dn注意:使用普通用户,不要使用root用户修改pg_hba.conf文件修改pg_hba.conf文件,主要用于添加放行IP增加Navicat所在机器的IP(如果不考虑安全性,也可以用0.0.0.0/0对所有IP地址进行开放)修改trust替换成md5加密方式 # 1.使用vim打开pg_hba.conf文件 [omm@opengauss openGauss]$ vim /opt/software/openGauss/data/single_node/pg_hba.conf # 2.加入需要放行的IP,如图所示 # 3.按esc键退出输入模式,输入:wq!退出 修改postgresql.conf文件修改postgresql.conf文件,主要用于修改监听地址和加密方式 # 1.使用vim打开postgresql.conf文件 [omm@opengauss openGauss]$ vim /opt/software/openGauss/data/single_node/postgresql.conf # 2.修改监听地址listen_addresses = '*',如图所示 # 3.修改加密方式password_encryption_type = 0,如图所示 重启服务企业版重启命令 [omm@opengauss openGauss]$ gs_om -t stop [omm@opengauss openGauss]$ gs_om -t start 极简版重启命令 # 路径为pg_hba.conf和postgresql.conf所在目录 [omm@opengauss openGauss]$ gs_ctl restart -D /opt/software/openGauss/data/single_node/ 创建远程连接角色由于修改了加密方式,需要对用户之前的密码进行修改;或者创建新用户用于远程连接 # 使用命令进入数据库 [omm@opengauss openGauss]$ gsql -d postgres -p 5432 # 修改密码方式 alter user test identified by 'openGauss@1234' # 创建新用户方式 create user navicatuser password 'openGauss@1234'; 开放端口 # 查看firewalld状态 [omm@opengauss openGauss]$ systemctl status firewalld # 把端口加入防火墙 [omm@opengauss openGauss]$ sudo firewall-cmd --zone=public --add-port=5432/tcp --permanent # 重新加载防火墙 [omm@opengauss openGauss]$ sudo systemctl reload firewalld Navicat连接打开navicat点击新建连接选择postgresSQL连接输入ip、端口号等参数
-
前言: 随着pg在国内越来越热,我也想赶紧的学习学习,pg的挺多语法跟mysql和oracle不太一样,光看书还是不太行,还是得多动手。前面实践了下mogdb,这次借着机会学习学习openGauss。本次实践的是opengauss的MOT表,我们都知道现在数据库的瓶颈都在IO上,内存操作的速度是极快的,MOT特性就是建立在内存中的存储引擎。根据官档介绍MOT是openGauss数据库最先进的生产级特性,看起来好处多多啊,这次主要是尝尝鲜。这次实践是基于docker的,之前对docker不太感冒,每次做个实验都要弄一套不同版本的数据库环境,太费事了,自从用了docker以后,感觉不要太爽,不用再在自己电脑上弄一个个虚拟机了,直接装个docker环境,撸镜像得了。一、利用docker拉起openGuass1、配置好docker环境,这里就不再细讲了,网上都有保姆教程。2、恩墨制作了opengauss 3.0的镜像,直接从网上拉镜像就可以。3、确认镜像已经拉下来,总共480M,不大也不小。4、启动镜像,指定下密码就行,如果密码太简单会报错。docker run --name myopengauss --privileged=true -d -e GS_PASSWORD=Gauss@123 enmotech/opengauss:3.0.0二、测试MOT表1、新建一个普通用户test2、创建MOT,在创建表的时候加关键词foreign。在创建的时候可能会报,无法创建,这是因为如果postgresql.conf中开启了增量检查点,则无法创建MOT。因此请在创建MOT前将enable_incremental_checkpoint设置为off。解决方案如下: a.找到镜像的postgresql.conf配置文件 b.修改enable_incremental_checkpoint=off c.基于现有镜像生成新镜像 d.启动新镜像三、测试将磁盘表转换成MOT表根据官方手册的说法,目前还不能一键实现磁盘表到MOT表的转换,需要利用导入导出的方法。转换步骤如下: a、停应用,做的时候不能有写入。 b、利用gs_dump导出数据,必须使用data only c、重命名原表 d、新建mot表,与原表同名。 e、使用gs_restore导入数据 f、恢复应用。1、新建普通测试表,确认相关字段MOT都能支持。2、导出表数据3、重命名原表4、新建同名MOT表5、导入数据6、确认数据
-
前言openGauss是华为旗下的国产数据库,我对着这个数据库的了解要从今年8月份开始说起,这个数据库我刚开始使用的时候还头疼了很久,感觉搭建的过程还是比较复杂的,但是熟悉之后发现是真的很香!一、openGauss介绍官方介绍: openGauss是一款全面友好开放,携手伙伴共同打造的企业级开源关系型数据库。openGauss采用木兰宽松许可证v2发行,提供面向多核架构的极致性能、全链路的业务、数据安全、基于AI的调优和高效运维的能力。openGauss内核源自PostgreSQL,深度融合华为在数据库领域多年的研发经验,结合企业级场景需求,持续构建竞争力特性。同时,openGauss也是一个开源、免费的数据库平台,鼓励社区贡献、合作。个人理解: 基于linux为内核的国产数据库,安全性大大提高二、MySQL数据迁移到openGauss1.全量迁移(1)介绍官方介绍 chameleon是一个用Python3编写的将MySQL迁移至openGauss的实时复制工具,支持初始全量数据的复制以及后续增量数据的实时在线复制功能。chameleon通过一次初始化配置,使用只读模式,将MySQL的数据全量拉取到openGauss。支持在同一快照下,表间数据并行迁移。全量迁移支持的功能:支持表及表数据、视图、触发器、自定义函数、存储过程的全量迁移个人理解 也就是说,将数据库中的数据通过工具全量复制到openGauss里面,这是最简单易懂的解释。和上图其实原理很类似,就是对大量数据进行批量复制,从MySQL复制到openGauss,只不过中间开始利用工具进行操作。(2)优势官方解释: 基于sysbench测试模型,在Kunpeng-920 2p服务器上,MySQL数据库10张表单表数据量在300万以上时,chameleon使用10并发迁移数据至openGauss,整体全量迁移性能可达300M/S以上。个人理解 也就是说,在大量数据的迁移的时候,通常会出现两种问题难以解决,第一数据量过于庞大,第二迁移速度太慢,openGauss很好的解决了这两点问题。(3)chameleon工具下载地址:https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/chameleon/chameleon-1.0.0-py3-none-any.whlpip3 install ./chameleon-1.0.0-py3-none-any.whl(安装chameleon命令)(4)安装git clone git@gitee.com:opengauss/openGauss-tools-chameleon.git #(下载源码) python3 -m venv venv #(创建环境) source venv/bin/activate #(激活环境) cd openGauss-tools-chameleon #(进入指定目录) python3 setup.py install #(安装)(5)迁移chameleon set_configuration_files (创建目录) cd ~/.pg_chameleon/configuration (进入目录) cp config-example.yml default.yml (配置default.yml) ** 修改default.yml配置文件 ** # global settings pid_dir: '~/.pg_chameleon/pid/' log_dir: '~/.pg_chameleon/logs/' log_dest: file log_level: info log_days_keep: 10 rollbar_key: '' rollbar_env: '' \# type_override allows the user to override the default type conversion \# into a different one. type_override: "tinyint(1)": override_to: boolean override_tables: \- "*" \# postgres destination connection pg_conn: host: "1.1.1.1" port: "5432" user: "opengauss_test" password: "password_123" database: "opengauss_database" charset: "utf8" sources: mysql: readers: 4 writers: 4 db_conn: host: "1.1.1.1" port: "3306" user: "mysql_test" password: "password123" charset: 'utf8' connect_timeout: 10 schema_mappings: mysql_database:sch_mysql_database limit_tables: skip_tables: grant_select_to: \- usr_migration lock_timeout: "120s" my_server_id: 1 replica_batch_size: 10000 replay_max_rows: 10000 batch_retention: '1 day' copy_max_memory: "300M" copy_mode: 'file' out_dir: /tmp sleep_loop: 1 on_error_replay: continue on_error_read: continue auto_maintenance: "disabled" gtid_enable: false type: mysql keep_existing_schema: No migrate_default_value: Yes **初始化** chameleon create_replica_schema --config default chameleon add_source --config default --source mysql **迁移数据** chameleon init_replica --config default --source mysql chameleon start_view_replica --config default --source mysql --debug chameleon start_trigger_replica --config default --source mysql --debug chameleon start_func_replica --config default --source mysql --debug chameleon start_proc_replica --config default --source mysql --debug **结束迁移** chameleon stop_replica --config default --source mysql chameleon detach_replica --config default --source mysql chameleon drop_replica_schema --config default 2.增量迁移(1)介绍官方解释: 基于开源三方件mysql-binlog-connector-java解析mysql的binlog,并根据mysql主备并行复制的原理,对可并行的事务在openGauss端采用多线程进行并行回放,以实现MySQL到openGauss端的在线迁移。其中并行事务的判断规则为:如果所有正在回放的事务的最小sequence_number大于该事务的last_committed,那么该事务就可以并行执行。该方案可以严格保证事务的顺序和一致性。个人理解 也就是传输工程中的一种类似协议的东西,加固迁移过程的稳定性(2)迁移代码git clone https://gitee.com/opengauss/openGauss-tools-onlineMigration-mysql.git(下载源码) **改动配置文件** #openGauss config openGauss_conn: host: "127.0.0.1" port: "5432" user: "opengauss" password: "password123" database: "postgres" #mysql config mysql_conn: host: "127.0.0.1" port: "3306" user: "mysql" password: "password123" database: "mysql" cd openGauss-tools-onlineMigration-mysql/mysql2openGauss/ mvn clean package(编译) java -jar ./target/online-migration-mysql-3.1.0.jar (运行) numactl -C 0-31 -m 0 java -Xms15G -Xmx25G -jar ./target/online-migration-mysql-3.1.0.jar (执行) 3.数据校验(1)介绍官方介绍全量校验: 在全量数据迁移完成后,由extract服务对MySQL源端和openGauss目标端数据抽取然后规整,并将数据推送到kafka中。最后由check服务提取kafka中的数据,并进行校验且输出校验结果。增量校验: 由debezium服务侦听源端MySQL数据库的增量数据,到指定topic。再由源端extract服务处理该topic增量数据,触发check增量校验。个人理解:就是在全量数据迁移之后,正对数据迁移的准确性做一个调查,查看数据库信息是否在迁移过程中有丢失等等情况(2)代码git clone https://gitee.com/opengauss/openGauss-tools-datachecker-performance.git(下载源码) mvn clean package -Dmvnen.test.skip=true(构建check 和 extract jar包) **配置application.yml文件** server: port: 9000 spring: kafka: bootstrap-servers: 192.168.0.114:9092 # kafka 集群地址 data: check: data-path: D:\code\tool # 配置数据校验结果输出本地路径 bucket-expect-capacity: 10 # 桶容量范围最小值为1 source-uri: http://127.0.0.1:9002 # 配置源端服务地址和服务端口server.port sink-uri: http://127.0.0.1:9001 # 配置源端服务地址和服务端口server.port **配置 application-source.yml文件** server: port: 9002 spring: check: server-uri: http://127.0.0.1:9000 # 数据校验服务地址 extract: schema: test # 源端数据实例 databaseType: MS # 源端数据库类型 MS mysql debezium-enable: false #是否开启增量debezium配置 默认不开启 debezium-topic:topic # debezium监听表增量数据,使用单一topic进行增量数据管理 debezium-groupId: debezium-extract-group # d debezium增量迁移topic ,groupId消费Group设置 debezium-topic-partitions: 1 # debezium监听topic 分区数量配置 debezium-tables: # debezium-tables配置debezium监听的表名称列表; 该配置只在源端服务配置并生效 table1, table2 debezium-time-period: 1 # debezium增量迁移校验 时间周期 24*60 单位分钟 debezium-num-period: 1000 #debezium增量迁移校验 统计增量变更记录数量阀值,默认值1000 阀值应大于100 datasource: druid: dataSourceOne: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&allowPublicKeyRetrieval=true username: jack # 源端mysql用于校验的用户名称 password: test@123 # 源端mysql用于校验的用户名称密码 **配置 application-sink.yml文件** server: port: 9001 spring: check: server-uri: http://127.0.0.1:9000 # 数据校验服务地址 extract: schema: test # 宿端opengauss 用于校验数据schema databaseType: OG # 宿端数据库类型 OG opengauss datasource: druid: dataSourceOne: driver-class-name: org.opengauss.Driver # 宿端opengauss用于校验数据库链接地址 url: jdbc:opengauss://127.0.0.1:15432/test?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&batchMode=OFF username: jack # 宿端opengauss用于校验的用户名称 password: test@123 # 宿端opengauss用于校验的用户名称密码 **校验前的准备工作** cd /data/kafka/confluent-7.2.0 bin/zookeeper-server-start -daemon etc/kafka/zookeeper.properties(启动服务) bin/kafka-server-start.sh -daemon etc/kafka/server.properties(启动服务) bin/connect-standalone -daemon etc/kafka/connect-standalone.properties etc/kafka/mysql-conect.properties(文件连接) **校验** sh extract-endpoints.sh stat|restart|stop(启动校验服务) sh check-endpoint.sh stat|restart|stop(启动校验服务) curl -X 'POST' 'http://localhost:9000/start/check?checkMode=FULL' -H 'accept: */*' -d ''(全量校验) curl -X 'POST' 'http://localhost:9000/stop/clean/check' -H 'accept: */*' -d ''(环境清理) debezium-enable: true(开始校验)4.反向迁移1.介绍官方解释:反向迁移是指用户将源端数据库迁移到目标数据库,应用切到目标数据库后,再将目标端新产生的数据迁移回源端。反向迁移可满足用户业务迁移逃生的诉求,保持源端、目标端两个库并行运行,在目标端数据库出问题后应用能及时切回源端数据库。openGauss提供reverse-migration工具,将openGauss数据库迁移至MySQL数据库,满足反向迁移要求。个人理解:也就是从openGauss数据库迁移回Mysql数据库中的过程2.代码**配置config.yaml文件** og_conn: host: "openGauss_ip" port: "5432" user: "user" password: "password" database: "postgres" charset: "utf8" driver: "org.opengauss.Driver" ASSUME_MIN_SERVER_VERSION: "9.4"//逻辑复制必备属性 REPLICATION: "database" //逻辑复制必备属性 PREFER_QUERY_MODE: "simple"//逻辑复制必备属性 slot: name: "replication_slot"//逻辑复制槽名称 include-xids: false//解码数据是否包含xid信息 skip-empty-xacts: true//解码事务是否包含空事务 waitLSN: ""//逻辑复制槽开启的lsn parallel-decode-num: 20//并行解码个数,最大20 white-table-list: ""//库表白名单 standby-connection: false//强制备机解码 decode-style: "j"//解码格式 decoding: "mppdb_decoding"//创建逻辑复制槽的工具 runnable_num: 1//并行回放个数 mysql: driver: "com.mysql.cj.jdbc.Driver" host: "mysql_ip" port: "3306" user: "user" password: "password" database: "database **反项迁移** mvn clean package(编译) java -jar ./reverse-migration-mysql-1.0-SNAPSHOT.jar start/create/drop(运行) numactl -c 0 -31 -m 0 java -Xms15G -Xmx25Gs -jar ./reverse-migration-mysql-1.0-SNAPSHOT.jar start/create/drop(执行)三、小结本次文章我准备写一个系列,主要针对openGauss数据库的各种讲解,希望各位小伙伴予以支持!
-
三、新容器镜像制作1. clone目录[root@node3 dockerfiles]# cp -r 3.0.0/ 3.1.0 [root@node3 dockerfiles]# cd 3.1.0/ [root@node3 3.1.0]# ll total 98812 -rw-r--r-- 1 root root 1373 Oct 9 09:43 dockerfile_amd -rw-r--r-- 1 root root 1457 Oct 9 09:43 dockerfile_arm -rw-r--r-- 1 root root 17730 Oct 9 09:43 entrypoint.sh -rw-r--r-- 1 root root 2404352 Oct 9 09:43 gosu-amd64 -rw-r--r-- 1 root root 2490368 Oct 9 09:43 gosu-arm64 -rw-r--r-- 1 root root 1688 Oct 9 09:43 openEuler_aarch64.repo -rw-r--r-- 1 root root 96246093 Oct 9 09:43 openGauss-3.0.0-CentOS-64bit.tar.bz2 -rw-r--r-- 1 root root 103 Oct 9 09:43 sha256_file_amd64 -rw-r--r-- 1 root root 106 Oct 9 09:43 sha256_file_arm64 [root@node3 3.1.0]# rm -f openGauss-3.0.0-CentOS-64bit.tar.bz22. 修改配置文件dockerfile_amd[root@ecs-lee 3.1.0]# cat dockerfile_amd FROM centos:7.6.1810 as builder RUN set -eux; \ yum install -y \ wget && \ wget https://github.com/tianon/gosu/releases/download/1.14/gosu-amd64 && \ wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/x86/openGauss-3.1.0-CentOS-64bit.tar.bz2 FROM centos:7.6.1810 COPY --from=builder /gosu-amd64 /usr/local/bin/gosu #COPY gosu-amd64 /usr/local/bin/gosu COPY --from=builder /openGauss-3.1.0-CentOS-64bit.tar.bz2 /tmp #COPY openGauss-3.1.0-CentOS-64bit.tar.bz2 /tmp COPY entrypoint.sh /usr/local/bin/ ENV LANG en_US.utf8 ENV PGDATA /var/lib/opengauss/data RUN set -eux; \ yum install -y \ bzip2 \ bzip2-devel \ libaio-devel && \ groupadd -g 70 omm; \ useradd -u 70 -g omm -m -s /bin/bash omm; \ mkdir -p /var/lib/opengauss && \ mkdir -p /usr/local/opengauss && \ mkdir -p /var/run/opengauss && \ mkdir /docker-entrypoint-initdb.d && \ tar -xf /tmp/openGauss-3.1.0-CentOS-64bit.tar.bz2 -C /usr/local/opengauss && \ chown -R omm:omm /var/lib/opengauss /home/omm /var/run/opengauss /docker-entrypoint-initdb.d /usr/local/opengauss/ && \ chmod 755 -R /usr/local/opengauss && \ rm -f /tmp/openGauss-3.1.0-CentOS-64bit.tar.bz2 && \ yum clean all && \ echo "export GAUSSHOME=/usr/local/opengauss" >> /home/omm/.bashrc && \ echo "export PATH=\$GAUSSHOME/bin:\$PATH " >> /home/omm/.bashrc && \ echo "export LD_LIBRARY_PATH=\$GAUSSHOME/lib:\$LD_LIBRARY_PATH" >> /home/omm/.bashrc && \ echo "export GAUSSLOG=/var/lib/opengauss/data/pg_log" >> /home/omm/.bashrc && \ echo "export PGDATA=/var/lib/opengauss/data" >> /home/omm/.bashrc && \ echo "\set PROMPT1 'openGauss%R%#'" >> /home/omm/.gsqlrc && \ echo "\set PROMPT2 '#'" >> /home/omm/.gsqlrc && \ echo "\set PROMPT3 '>'" >> /home/omm/.gsqlrc && \ chown -R omm:omm /home/omm && \ chmod +x /usr/local/bin/gosu && \ chmod 755 /usr/local/bin/entrypoint.sh && \ ln -s /usr/local/bin/entrypoint.sh / ENTRYPOINT ["entrypoint.sh"] EXPOSE 5432 CMD ["gaussdb"]entrypoint.sh[root@ecs-lee 3.1.0]# cat entrypoint.sh #!/usr/bin/env bash set -Eeo pipefail # usage: file_env VAR [DEFAULT] # ie: file_env 'XYZ_DB_PASSWORD' 'example' # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of # "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) export GAUSSHOME=/usr/local/opengauss export PATH=$GAUSSHOME/bin:$PATH export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH export LANG=en_US.UTF-8 export PGDATA=/var/lib/opengauss/data file_env() { local var="$1" local fileVar="${var}_FILE" local def="${2:-}" if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then echo >&2 "error: both $var and $fileVar are set (but are exclusive)" exit 1 fi local val="$def" if [ "${!var:-}" ]; then val="${!var}" elif [ "${!fileVar:-}" ]; then val="$(< "${!fileVar}")" fi export "$var"="$val" unset "$fileVar" } # check to see if this file is being run or sourced from another script _is_sourced() { [ "${#FUNCNAME[@]}" -ge 2 ] \ && [ "${FUNCNAME[0]}" = '_is_sourced' ] \ && [ "${FUNCNAME[1]}" = 'source' ] } # used to create initial opengauss directories and if run as root, ensure ownership belong to the omm user docker_create_db_directories() { local user; user="$(id -u)" mkdir -p "$PGDATA" chmod 700 "$PGDATA" # ignore failure since it will be fine when using the image provided directory; mkdir -p /var/run/opengauss || : chmod 775 /var/run/opengauss || : # Create the transaction log directory before initdb is run so the directory is owned by the correct user if [ -n "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" if [ "$user" = '0' ]; then find "$POSTGRES_INITDB_XLOGDIR" \! -user postgres -exec chown postgres '{}' + fi chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi # allow the container to be started with `--user` if [ "$user" = '0' ]; then find "$PGDATA" \! -user omm -exec chown omm '{}' + find /var/run/opengauss \! -user omm -exec chown omm '{}' + fi } # initialize empty PGDATA directory with new database via 'initdb' # arguments to `initdb` can be passed via POSTGRES_INITDB_ARGS or as arguments to this function # `initdb` automatically creates the "postgres", "template0", and "template1" dbnames # this is also where the database user is created, specified by `GS_USER` env docker_init_database_dir() { # "initdb" is particular about the current user existing in "/etc/passwd", so we use "nss_wrapper" to fake that if necessary if ! getent passwd "$(id -u)" &> /dev/null && [ -e /usr/lib/libnss_wrapper.so ]; then export LD_PRELOAD='/usr/lib/libnss_wrapper.so' export NSS_WRAPPER_PASSWD="$(mktemp)" export NSS_WRAPPER_GROUP="$(mktemp)" echo "postgres:x:$(id -u):$(id -g):PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" echo "postgres:x:$(id -g):" > "$NSS_WRAPPER_GROUP" fi eval $cmdbase # unset/cleanup "nss_wrapper" bits if [ "${LD_PRELOAD:-}" = '/usr/lib/libnss_wrapper.so' ]; then rm -f "$NSS_WRAPPER_PASSWD" "$NSS_WRAPPER_GROUP" unset LD_PRELOAD NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP fi } # print large warning if GS_PASSWORD is long # error if both GS_PASSWORD is empty and GS_HOST_AUTH_METHOD is not 'trust' # print large warning if GS_HOST_AUTH_METHOD is set to 'trust' # assumes database is not set up, ie: [ -z "$DATABASE_ALREADY_EXISTS" ] docker_verify_minimum_env() { # set param cmdbase="gs_initdb " echo -e " ********************************************************************************" if [ -n "$GS_XLOGDIR" ]; then cmdbase="$cmdbase --xlogdir=$GS_XLOGDIR" echo -e " Message: GS_XLOGDIR is ${PGDATA}/xlog." else cmdbase="$cmdbase --xlogdir=$GS_XLOGDIR" GS_XLOGDIR=${PGDATA}/xlog echo -e " Message: Default GS_XLOGDIR is ${PGDATA}/xlog." fi if [ -n "$GS_NODENAME" ]; then cmdbase="$cmdbase --nodename=$GS_NODENAME" echo -e " Message: GS_NODENAME is ${GS_NODENAME}" else cmdbase="$cmdbase --nodename=opengauss" GS_NODENAME=opengauss echo -e " Message: Default GS_NODENAME is ${GS_NODENAME}." fi if [ -n "$ENCODING" ]; then cmdbase="$cmdbase --encoding=$ENCODING" echo -e " Message: ENCODING is ${ENCODING}" else cmdbase="$cmdbase --encoding=UTF-8" ENCODING=UTF-8 echo -e " Message: Default ENCODING is ${ENCODING}." fi if [ -n "$LOCALE" ]; then cmdbase="$cmdbase --locale=$LOCALE" echo -e " Message: LOCALE is ${LOCALE}" else cmdbase="$cmdbase --no-locale" LOCALE=--no-locale echo -e " Message: Default LOCALE is ${LOCALE}." fi if [ -n "$DBCOMPATIBILITY" ]; then cmdbase="$cmdbase --dbcompatibility=$DBCOMPATIBILITY" echo -e " Message: DBCOMPATIBILITY is ${DBCOMPATIBILITY}" else cmdbase="$cmdbase --dbcompatibility=PG" DBCOMPATIBILITY=PG echo -e " Message: Default DBCOMPATIBILITY is ${DBCOMPATIBILITY}." fi if [ -n "$GS_PASSWORD" ]; then cmdbase="$cmdbase --pwpasswd=$GS_PASSWORD" echo -e " Message: GS_PASSWORD is ${GS_PASSWORD}" else randpw(){ < /dev/urandom tr -dc '^(.*[#?!@$%^&*-]).*$_A-Z-a-z-0-9' | head -c${1:-4};echo;} GS_PASSWORD=`randpw`"Aa1!" cmdbase="$cmdbase --pwpasswd=$GS_PASSWORD" echo -e " Message: Default GS_PASSWORD is "${GS_PASSWORD}"." fi echo -e " ********************************************************************************" cmdbase="$cmdbase -D $PGDATA" # check password first so we can output the warning before postgres # messes it up if [[ "$GS_PASSWORD" =~ ^(.{8,}).*$ ]] && [[ "$GS_PASSWORD" =~ ^(.*[a-z]+).*$ ]] && [[ "$GS_PASSWORD" =~ ^(.*[A-Z]).*$ ]] && [[ "$GS_PASSWORD" =~ ^(.*[0-9]).*$ ]] && [[ "$GS_PASSWORD" =~ ^(.*[#?!@$%^&*-+]).*$ ]]; then echo -e " Message: The supplied GS_PASSWORD $GS_PASSWORD is meet requirements." else echo -e " Error: The supplied GS_PASSWORD $GS_PASSWORD is not meet requirements." cat >&2 <<-'EOWARN' Please Check if the password contains uppercase, lowercase, numbers, special characters, and password length(8). At least one uppercase, lowercase, numeric, special character. Example: Enmo@123 EOWARN exit 1 fi if [ -z "$GS_PASSWORD" ] && [ 'trust' != "$GS_HOST_AUTH_METHOD" ]; then # The - option suppresses leading tabs but *not* spaces. :) cat >&2 <<-'EOE' Error: Database is uninitialized and superuser password is not specified. You must specify GS_PASSWORD to a non-empty value for the superuser. For example, "-e GS_PASSWORD=password" on "docker run". You may also use "GS_HOST_AUTH_METHOD=trust" to allow all connections without a password. This is *not* recommended. EOE exit 1 fi if [ 'trust' = "$GS_HOST_AUTH_METHOD" ]; then cat >&2 <<-'EOWARN' ******************************************************************************** WARNING: GS_HOST_AUTH_METHOD has been set to "trust". This will allow anyone with access to the opengauss port to access your database without a password, even if GS_PASSWORD is set. It is not recommended to use GS_HOST_AUTH_METHOD=trust. Replace it with "-e GS_PASSWORD=password" instead to set a password in "docker run". ******************************************************************************** EOWARN fi } # usage: docker_process_init_files [file [file [...]]] # ie: docker_process_init_files /always-initdb.d/* # process initializer files, based on file extensions and permissions docker_process_init_files() { # gsql here for backwards compatiblilty "${gsql[@]}" gsql=( docker_process_sql ) echo local f for f; do case "$f" in *.sh) if [ -x "$f" ]; then echo "$0: running $f" "$f" else echo "$0: sourcing $f" . "$f" fi ;; *.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *) echo "$0: ignoring $f" ;; esac echo done } # Execute sql script, passed via stdin (or -f flag of pqsl) # usage: docker_process_sql [gsql-cli-args] # ie: docker_process_sql --dbname=mydb <<<'INSERT ...' # ie: docker_process_sql -f my-file.sql # ie: docker_process_sql <<-'EOSQL' create user opengauss with login password :"passwd" ; CREATE DATABASE opengauss; grant all privileges to opengauss; ALTER USER opengauss MONADMIN; EOSQL } docker_setup_user() { if [ -n "$GS_USERNAME" ]; then GS_DB= docker_process_sql --set passwd="$GS_PASSWORD" --set user="$GS_USERNAME" <<-'EOSQL' create user :"user" with login password :"passwd" ; EOSQL else echo " default user is opengauss" echo -e " Message: Default GS_USERNAME is ${GS_USERNAME}." fi } docker_setup_rep_user() { if [ -n "$SERVER_MODE" ] && [ "$SERVER_MODE" = "primary" ]; then GS_DB= docker_process_sql --set passwd="$GS_PASSWORD" --set user="repuser" <<-'EOSQL' create user :"user" SYSADMIN REPLICATION password :"passwd" ; EOSQL else echo " default no repuser created" fi } # Loads various settings that are used elsewhere in the script # This should be called before any other functions docker_setup_env() { # default authentication method is md5 : "${GS_HOST_AUTH_METHOD:=md5}" declare -g DATABASE_ALREADY_EXISTS # look specifically for OG_VERSION, as it is expected in the DB dir if [ -s "$PGDATA/PG_VERSION" ]; then DATABASE_ALREADY_EXISTS='true' fi } # append GS_HOST_AUTH_METHOD to pg_hba.conf for "host" connections opengauss_setup_hba_conf() { { echo if [ 'trust' = "$GS_HOST_AUTH_METHOD" ]; then echo '# warning trust is enabled for all connections' fi echo "host all all 0.0.0.0/0 $GS_HOST_AUTH_METHOD" if [ -n "$SERVER_MODE" ]; then echo "host replication repuser $OG_SUBNET trust" fi } >> "$PGDATA/pg_hba.conf" } # append parameter to postgres.conf for connections opengauss_setup_postgresql_conf() { { echo if [ -n "$GS_PORT" ]; then echo "password_encryption_type = 1" echo "port = $GS_PORT" echo "wal_level = logical" else echo '# use default port 5432' echo "password_encryption_type = 1" echo "wal_level = logical" fi if [ -n "$SERVER_MODE" ]; then echo "listen_addresses = '0.0.0.0'" echo "most_available_sync = on" echo "remote_read_mode = non_authentication" echo "pgxc_node_name = '$NODE_NAME'" # echo "application_name = '$NODE_NAME'" if [ "$SERVER_MODE" = "primary" ]; then echo "max_connections = 100" else echo "max_connections = 100" fi echo -e "$REPL_CONN_INFO" if [ -n "$SYNCHRONOUS_STANDBY_NAMES" ]; then echo "synchronous_standby_names=$SYNCHRONOUS_STANDBY_NAMES" fi else echo "listen_addresses = '*'" fi if [ -n "$OTHER_PG_CONF" ]; then echo -e "$OTHER_PG_CONF" fi } >> "$PGDATA/postgresql.conf" } opengauss_setup_mot_conf() { echo "enable_numa = false" >> "$PGDATA/mot.conf" } # start socket-only postgresql server for setting up or running scripts # all arguments will be passed along as arguments to `postgres` (via pg_ctl) docker_temp_server_start() { if [ "$1" = 'gaussdb' ]; then shift fi # internal start of server in order to allow setup using gsql client # does not listen on external TCP/IP and waits until start finishes set -- "$@" -c listen_addresses='127.0.0.1' -p "${PGPORT:-5432}" PGUSER="${PGUSER:-$GS_USER}" \ gs_ctl -D "$PGDATA" \ -o "$(printf '%q ' "$@")" \ -w start } # stop postgresql server after done setting up user and running scripts docker_temp_server_stop() { PGUSER="${PGUSER:-postgres}" \ gs_ctl -D "$PGDATA" -m fast -w stop } docker_slave_full_backup() { gs_ctl build -D "$PGDATA" -b full } # check arguments for an option that would cause opengauss to stop # return true if there is one _opengauss_want_help() { local arg count=1 for arg; do case "$arg" in # postgres --help | grep 'then exit' # leaving out -C on purpose since it always fails and is unhelpful: # postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory -'?'|--help|--describe-config|-V|--version) return 0 ;; esac if [ "$arg" == "-M" ]; then SERVER_MODE=${@:$count+1:1} echo "openGauss DB SERVER_MODE = $SERVER_MODE" shift fi count=$[$count + 1] done return 1 } _main() { # if first arg looks like a flag, assume we want to run postgres server if [ "${1:0:1}" = '-' ]; then set -- gaussdb "$@" fi if [ "$1" = 'gaussdb' ] && ! _opengauss_want_help "$@"; then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user exec gosu omm "$BASH_SOURCE" "$@" fi # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env # check dir permissions to reduce likelihood of half-initialized database ls /docker-entrypoint-initdb.d/ > /dev/null docker_init_database_dir opengauss_setup_hba_conf opengauss_setup_postgresql_conf opengauss_setup_mot_conf # PGPASSWORD is required for gsql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS export PGPASSWORD="${PGPASSWORD:-$GS_PASSWORD}" docker_temp_server_start "$@" if [ -z "$SERVER_MODE" ] || [ "$SERVER_MODE" = "primary" ]; then docker_setup_user docker_setup_rep_user docker_setup_db docker_process_init_files /docker-entrypoint-initdb.d/* fi if [ -n "$SERVER_MODE" ] && [ "$SERVER_MODE" != "primary" ]; then docker_slave_full_backup fi docker_temp_server_stop unset PGPASSWORD echo echo 'openGauss init process complete; ready for start up.' echo else echo echo 'openGauss Database directory appears to contain a database; Skipping initialization' echo fi fi exec "$@" } if ! _is_sourced; then _main "$@" fisha256_file_amd64[root@ecs-lee 3.1.0]# cat sha256_file_amd64 9cf6f2762664d67889b4cd8d879c14a7f1dae70cff0552e4a7263a301b336115 openGauss-3.1.0-CentOS-64bit.tar.bz23. buildDockerImage.sh[root@ecs-lee dockerfiles]# sh buildDockerImage.sh -v 3.1.0 -i ... ... ========================== Building image 'opengauss:3.1.0' ... Sending build context to Docker daemon 24.58kB Step 1/12 : FROM centos:7.6.1810 as builder ---> f1cb7c7d58b7 Step 2/12 : RUN set -eux; yum install -y wget && wget https://github.com/tianon/gosu/releases/download/1.14/gosu-amd64 && wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/x86/openGauss-3.1.0-CentOS-64bit.tar.bz2 ---> Running in 81f2e272d525 + yum install -y wget Loaded plugins: fastestmirror, ovl Determining fastest mirrors * base: mirrors.bupt.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.bupt.edu.cn Resolving Dependencies --> Running transaction check ---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: wget x86_64 1.14-18.el7_6.1 base 547 k Transaction Summary ================================================================================ Install 1 Package Total download size: 547 k Installed size: 2.0 M Downloading packages: warning: /var/cache/yum/x86_64/7/base/packages/wget-1.14-18.el7_6.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for wget-1.14-18.el7_6.1.x86_64.rpm is not installed Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) " Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-6.1810.2.el7.centos.x86_64 (@CentOS) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : wget-1.14-18.el7_6.1.x86_64 1/1 install-info: No such file or directory for /usr/share/info/wget.info.gz Verifying : wget-1.14-18.el7_6.1.x86_64 1/1 Installed: wget.x86_64 0:1.14-18.el7_6.1 Complete! + wget https://github.com/tianon/gosu/releases/download/1.14/gosu-amd64 --2022-10-09 07:43:31-- https://github.com/tianon/gosu/releases/download/1.14/gosu-amd64 Resolving github.com (github.com)... 20.205.243.166 Connecting to github.com (github.com)|20.205.243.166|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/19708981/82f5cda4-dad5-4537-ace2-fb61e8c1a25a?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A/20221009/us-east-1/s3/aws4_request&X-Amz-Date=20221009T074332Z&X-Amz-Expires=300&X-Amz-Signature=9b00f8879f4fa6823a42ab5aa0ccfb0c261ca849c281eb0460eb2b4022cc2a51&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=19708981&response-content-disposition=attachment;%20filename=gosu-amd64&response-content-type=application/octet-stream [following] --2022-10-09 07:43:32-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/19708981/82f5cda4-dad5-4537-ace2-fb61e8c1a25a?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A/20221009/us-east-1/s3/aws4_request&X-Amz-Date=20221009T074332Z&X-Amz-Expires=300&X-Amz-Signature=9b00f8879f4fa6823a42ab5aa0ccfb0c261ca849c281eb0460eb2b4022cc2a51&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=19708981&response-content-disposition=attachment;%20filename=gosu-amd64&response-content-type=application/octet-stream Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.109.133, 185.199.111.133, 185.199.108.133, ... Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.109.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2289664 (2.2M) [application/octet-stream] Saving to: 'gosu-amd64' 0K .......... .......... .......... .......... .......... 2% 200K 11s 50K .......... .......... .......... .......... .......... 4% 231K 10s 100K .......... .......... .......... .......... .......... 6% 256K 9s ... ... 2100K .......... .......... .......... .......... .......... 96% 172K 0s 2150K .......... .......... .......... .......... .......... 98% 133K 0s 2200K .......... .......... .......... ...... 100% 128K=12s 2022-10-09 07:43:45 (183 KB/s) - 'gosu-amd64' saved [2289664/2289664] + wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/x86/openGauss-3.1.0-CentOS-64bit.tar.bz2 --2022-10-09 07:43:45-- https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/x86/openGauss-3.1.0-CentOS-64bit.tar.bz2 Resolving opengauss.obs.cn-south-1.myhuaweicloud.com (opengauss.obs.cn-south-1.myhuaweicloud.com)... 139.159.208.230, 139.159.208.64, 121.37.63.38, ... Connecting to opengauss.obs.cn-south-1.myhuaweicloud.com (opengauss.obs.cn-south-1.myhuaweicloud.com)|139.159.208.230|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 89822788 (86M) [application/x-bzip2] Saving to: 'openGauss-3.1.0-CentOS-64bit.tar.bz2' 0K .......... .......... .......... .......... .......... 0% 622K 2m21s 50K .......... .......... .......... .......... .......... 0% 1.67M 96s ... ... 87600K .......... .......... .......... .......... .......... 99% 1.81M 0s 87650K .......... .......... .......... .......... .......... 99% 1.73M 0s 87700K .......... ....... 100% 5.79M=61s 2022-10-09 07:44:47 (1.40 MB/s) - 'openGauss-3.1.0-CentOS-64bit.tar.bz2' saved [89822788/89822788] Removing intermediate container 81f2e272d525 ---> 4b6c7c242126 Step 3/12 : FROM centos:7.6.1810 ---> f1cb7c7d58b7 Step 4/12 : COPY --from=builder /gosu-amd64 /usr/local/bin/gosu ---> 5a697e587c2a Step 5/12 : COPY --from=builder /openGauss-3.1.0-CentOS-64bit.tar.bz2 /tmp ---> 4e3b98ce48f4 Step 6/12 : COPY entrypoint.sh /usr/local/bin/ ---> dcea341c1684 Step 7/12 : ENV LANG en_US.utf8 ---> Running in 0f5406729bd9 Removing intermediate container 0f5406729bd9 ---> 42975b6f1ad0 Step 8/12 : ENV PGDATA /var/lib/opengauss/data ---> Running in 75cfae77f1a9 Removing intermediate container 75cfae77f1a9 ---> bcf8821abff1 Step 9/12 : RUN set -eux; yum install -y bzip2 bzip2-devel libaio-devel && groupadd -g 70 omm; useradd -u 70 -g omm -m -s /bin/bash omm; mkdir -p /var/lib/opengauss && mkdir -p /usr/local/opengauss && mkdir -p /var/run/opengauss && mkdir /docker-entrypoint-initdb.d && tar -xf /tmp/openGauss-3.1.0-CentOS-64bit.tar.bz2 -C /usr/local/opengauss && chown -R omm:omm /var/lib/opengauss /home/omm /var/run/opengauss /docker-entrypoint-initdb.d /usr/local/opengauss/ && chmod 755 -R /usr/local/opengauss && rm -f /tmp/openGauss-3.1.0-CentOS-64bit.tar.bz2 && yum clean all && echo "export GAUSSHOME=/usr/local/opengauss" >> /home/omm/.bashrc && echo "export PATH=\$GAUSSHOME/bin:\$PATH " >> /home/omm/.bashrc && echo "export LD_LIBRARY_PATH=\$GAUSSHOME/lib:\$LD_LIBRARY_PATH" >> /home/omm/.bashrc && echo "export GAUSSLOG=/var/lib/opengauss/data/pg_log" >> /home/omm/.bashrc && echo "export PGDATA=/var/lib/opengauss/data" >> /home/omm/.bashrc && echo "\set PROMPT1 'openGauss%R%#'" >> /home/omm/.gsqlrc && echo "\set PROMPT2 '#'" >> /home/omm/.gsqlrc && echo "\set PROMPT3 '>'" >> /home/omm/.gsqlrc && chown -R omm:omm /home/omm && chmod +x /usr/local/bin/gosu && chmod 755 /usr/local/bin/entrypoint.sh && ln -s /usr/local/bin/entrypoint.sh / ---> Running in ca8ec1b08a8b + yum install -y bzip2 bzip2-devel libaio-devel Loaded plugins: fastestmirror, ovl Determining fastest mirrors * base: mirrors.bupt.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.bupt.edu.cn Resolving Dependencies --> Running transaction check ---> Package bzip2.x86_64 0:1.0.6-13.el7 will be installed ---> Package bzip2-devel.x86_64 0:1.0.6-13.el7 will be installed ---> Package libaio-devel.x86_64 0:0.3.109-13.el7 will be installed --> Processing Dependency: libaio(x86-64) = 0.3.109-13.el7 for package: libaio-devel-0.3.109-13.el7.x86_64 --> Running transaction check ---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: bzip2 x86_64 1.0.6-13.el7 base 52 k bzip2-devel x86_64 1.0.6-13.el7 base 218 k libaio-devel x86_64 0.3.109-13.el7 base 13 k Installing for dependencies: libaio x86_64 0.3.109-13.el7 base 24 k Transaction Summary ================================================================================ Install 3 Packages (+1 Dependent package) Total download size: 307 k Installed size: 510 k Downloading packages: warning: /var/cache/yum/x86_64/7/base/packages/bzip2-1.0.6-13.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for bzip2-1.0.6-13.el7.x86_64.rpm is not installed -------------------------------------------------------------------------------- Total 1.1 MB/s | 307 kB 00:00 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) " Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-6.1810.2.el7.centos.x86_64 (@CentOS) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libaio-0.3.109-13.el7.x86_64 1/4 Installing : libaio-devel-0.3.109-13.el7.x86_64 2/4 Installing : bzip2-1.0.6-13.el7.x86_64 3/4 Installing : bzip2-devel-1.0.6-13.el7.x86_64 4/4 Verifying : bzip2-devel-1.0.6-13.el7.x86_64 1/4 Verifying : libaio-0.3.109-13.el7.x86_64 2/4 Verifying : libaio-devel-0.3.109-13.el7.x86_64 3/4 Verifying : bzip2-1.0.6-13.el7.x86_64 4/4 Installed: bzip2.x86_64 0:1.0.6-13.el7 bzip2-devel.x86_64 0:1.0.6-13.el7 libaio-devel.x86_64 0:0.3.109-13.el7 Dependency Installed: libaio.x86_64 0:0.3.109-13.el7 Complete! + groupadd -g 70 omm + useradd -u 70 -g omm -m -s /bin/bash omm + mkdir -p /var/lib/opengauss + mkdir -p /usr/local/opengauss + mkdir -p /var/run/opengauss + mkdir /docker-entrypoint-initdb.d + tar -xf /tmp/openGauss-3.1.0-CentOS-64bit.tar.bz2 -C /usr/local/opengauss + chown -R omm:omm /var/lib/opengauss /home/omm /var/run/opengauss /docker-entrypoint-initdb.d /usr/local/opengauss/ + chmod 755 -R /usr/local/opengauss + rm -f /tmp/openGauss-3.1.0-CentOS-64bit.tar.bz2 + yum clean all Loaded plugins: fastestmirror, ovl Cleaning repos: base extras updates Cleaning up list of fastest mirrors + echo 'export GAUSSHOME=/usr/local/opengauss' + echo 'export PATH=$GAUSSHOME/bin:$PATH ' + echo 'export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH' + echo 'export GAUSSLOG=/var/lib/opengauss/data/pg_log' + echo 'export PGDATA=/var/lib/opengauss/data' + echo '\set PROMPT1 '\''openGauss%R%#'\''' + echo '\set PROMPT2 '\''#'\''' + echo '\set PROMPT3 '\''>'\''' + chown -R omm:omm /home/omm + chmod +x /usr/local/bin/gosu + chmod 755 /usr/local/bin/entrypoint.sh + ln -s /usr/local/bin/entrypoint.sh / Removing intermediate container ca8ec1b08a8b ---> 0e364541b2f6 Step 10/12 : ENTRYPOINT ["entrypoint.sh"] ---> Running in dcda8e469e67 Removing intermediate container dcda8e469e67 ---> af95fbd45f53 Step 11/12 : EXPOSE 5432 ---> Running in 466dbb3f7d47 Removing intermediate container 466dbb3f7d47 ---> b3bdd285b2c7 Step 12/12 : CMD ["gaussdb"] ---> Running in 692f1ab11a8a Removing intermediate container 692f1ab11a8a ---> b1953c88b748 Successfully built b1953c88b748 Successfully tagged opengauss:3.1.0 openGauss Docker Image 3.1.0 is ready to be extended: --> opengauss:3.1.0 Build completed in 144 seconds.4. 启动测试大小[root@ecs-lee 3.1.0]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE opengauss 3.1.0 b1953c88b748 4 minutes ago 633MBrun[root@ecs-lee dockerfiles]# docker run --name opengauss --privileged=true -d opengauss:3.1.0 149952b8dca92dd08c9795da196aba92751badc3aa7b0aced0727cd8c0f4ca57 [root@ecs-lee dockerfiles]# docker logs -f opengauss ******************************************************************************** Message: Default GS_XLOGDIR is /var/lib/opengauss/data/xlog. Message: Default GS_NODENAME is opengauss. Message: Default ENCODING is UTF-8. Message: Default LOCALE is --no-locale. Message: Default DBCOMPATIBILITY is PG. Message: Default GS_PASSWORD is sHZ3Aa1!. ******************************************************************************** Message: The supplied GS_PASSWORD sHZ3Aa1! is meet requirements. The files belonging to this database system will be owned by user "omm". This user must also own the server process. The database cluster will be initialized with locale "C". The default text search configuration will be set to "english". fixing permissions on existing directory /var/lib/opengauss/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 32MB creating configuration files ... ok Begin init undo subsystem meta. [INIT UNDO] Init undo subsystem meta successfully. creating template1 database in /var/lib/opengauss/data/base/1 ... The core dump path is an invalid directory 2022-10-09 07:46:18.999 [unknown] [unknown] localhost 140028811486336 0[0:0#0] [BACKEND] WARNING: macAddr is 578/2886795267, sysidentifier is 37923857/208181, randomNum is 2805673269 ok initializing pg_authid ... ok setting password ... ok initializing dependencies ... ok loading PL/pgSQL server-side language ... ok creating system views ... ok creating performance views ... ok loading system objects' descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok initialize global configure for bucketmap length ... ok creating information schema ... ok loading foreign-data wrapper for distfs access ... ok loading foreign-data wrapper for log access ... ok ... ... ACTION: Please refer to backend log for more details. ^C测试 ```s [root@ecs-lee dockerfiles]# docker exec -it opengauss bash [root@149952b8dca9 /]# su - omm [omm@149952b8dca9 ~]$ gsql -d postgres -p5432 -r gsql ((openGauss 3.1.0 build 4e931f9a) compiled at 2022-09-29 14:19:24 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.openGauss=#select version(); version(openGauss 3.1.0 build 4e931f9a) compiled at 2022-09-29 14:19:24 commit 0 last mr on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit (1 row)openGauss=### 5. 主备脚本测试 ```s [root@ecs-lee dockerfiles]# sh create_master_slave.sh Please input OG_SUBNET (容器所在网段) [172.11.0.0/24]: OG_SUBNET set 172.11.0.0/24 Please input GS_PASSWORD (定义数据库密码)[Enmo@123]: GS_PASSWORD set Enmo@123 Please input MASTER_IP (主库IP)[172.11.0.101]: MASTER_IP set 172.11.0.101 Please input SLAVE_1_IP (备库IP)[172.11.0.102]: SLAVE_1_IP set 172.11.0.102 Please input MASTER_HOST_PORT (主库数据库服务端口)[5432]: MASTER_HOST_PORT set 5432 Please input MASTER_LOCAL_PORT (主库通信端口)[5434]: MASTER_LOCAL_PORT set 5434 Please input SLAVE_1_HOST_PORT (备库数据库服务端口)[6432]: SLAVE_1_HOST_PORT set 6432 Please input SLAVE_1_LOCAL_PORT (备库通信端口)[6434]: SLAVE_1_LOCAL_PORT set 6434 Please input MASTER_NODENAME [opengauss_master]: MASTER_NODENAME set opengauss_master Please input SLAVE_NODENAME [opengauss_slave1]: SLAVE_NODENAME set opengauss_slave1 Please input openGauss VERSION [1.0.1]: openGauss VERSION set 1.0.1 starting 41cc302ad46e9d13015684bbdfd28105cac7c1b0f3dd1ba3b73d95f87de45bb7 OpenGauss Database Network Created. Unable to find image 'opengauss:1.0.1' locally ^C [root@ecs-lee dockerfiles]# docker network rm opengaussnetwork opengaussnetwork [root@ecs-lee dockerfiles]# sh create_master_slave.sh Please input OG_SUBNET (容器所在网段) [172.11.0.0/24]: OG_SUBNET set 172.11.0.0/24 Please input GS_PASSWORD (定义数据库密码)[Enmo@123]: GS_PASSWORD set Enmo@123 Please input MASTER_IP (主库IP)[172.11.0.101]: MASTER_IP set 172.11.0.101 Please input SLAVE_1_IP (备库IP)[172.11.0.102]: SLAVE_1_IP set 172.11.0.102 Please input MASTER_HOST_PORT (主库数据库服务端口)[5432]: MASTER_HOST_PORT set 5432 Please input MASTER_LOCAL_PORT (主库通信端口)[5434]: MASTER_LOCAL_PORT set 5434 Please input SLAVE_1_HOST_PORT (备库数据库服务端口)[6432]: SLAVE_1_HOST_PORT set 6432 Please input SLAVE_1_LOCAL_PORT (备库通信端口)[6434]: SLAVE_1_LOCAL_PORT set 6434 Please input MASTER_NODENAME [opengauss_master]: MASTER_NODENAME set opengauss_master Please input SLAVE_NODENAME [opengauss_slave1]: SLAVE_NODENAME set opengauss_slave1 Please input openGauss VERSION [1.0.1]: 3.1.0 openGauss VERSION set 3.1.0 starting aa0b66ab132d25d70c94e65641ea5cabb02f2ac3e56def4b65f9a4f07b848580 OpenGauss Database Network Created. 8f4a6be903997764b4bcf9f7d3117ed9f1ddd0c7e303d06b71657bb27386489d OpenGauss Database Master Docker Container created. 845434cdb53f8c64b396ec46db2d83cbc9da0ade52389a65ad2b498016ebb3c5 OpenGauss Database Slave1 Docker Container created. [root@ecs-lee dockerfiles]# docker exec -it opengauss_master bash [root@opengauss_master /]# su - omm Last login: Sun Oct 9 07:57:32 UTC 2022 on pts/0 [omm@opengauss_master ~]$ gs_ctl query -D /var/lib/opengauss/data/ [2022-10-09 07:58:03.329][429][][gs_ctl]: gs_ctl query ,datadir is /var/lib/opengauss/data HA state: local_role : Primary static_connections : 1 db_state : Normal detail_information : Normal Senders info: sender_pid : 339 local_role : Primary peer_role : Standby peer_state : Normal state : Streaming sender_sent_location : 0/40001C8 sender_write_location : 0/40001C8 sender_flush_location : 0/40001C8 sender_replay_location : 0/40001C8 receiver_received_location : 0/40001C8 receiver_write_location : 0/40001C8 receiver_flush_location : 0/40001C8 receiver_replay_location : 0/40001C8 sync_percent : 100% sync_state : Sync sync_priority : 1 sync_most_available : On channel : 172.11.0.101:5434-->172.11.0.102:51754 Receiver info: No information四、pr提交1. clone[root@ecs-lee lee]# git clone https://gitee.com/lee1002/openGauss-server.git Cloning into 'openGauss-server'... remote: Enumerating objects: 67552, done. remote: Counting objects: 100% (20832/20832), done. remote: Compressing objects: 100% (6840/6840), done. remote: Total 67552 (delta 15061), reused 17403 (delta 13878), pack-reused 46720 Receiving objects: 100% (67552/67552), 207.48 MiB | 1.37 MiB/s, done. Resolving deltas: 100% (47377/47377), done.2. 添加你的代码[root@ecs-lee lee]# cd openGauss-server/docker/dockerfiles/ [root@ecs-lee dockerfiles]# ls 3.0.0 buildDockerImage.sh create_master_slave.sh [root@ecs-lee dockerfiles]# ls 3.0.0 3.1.0 buildDockerImage.sh create_master_slave.sh [root@ecs-lee dockerfiles]# ls 3.1.0/ dockerfile_amd entrypoint.sh sha256_file_amd643. add && commit && push[root@ecs-lee dockerfiles]# git add . [root@ecs-lee dockerfiles]# git commit -m "add 3.1.0 amd container" [master f3676fd] add 3.1.0 amd container 3 files changed, 519 insertions(+) create mode 100644 docker/dockerfiles/3.1.0/dockerfile_amd create mode 100644 docker/dockerfiles/3.1.0/entrypoint.sh create mode 100644 docker/dockerfiles/3.1.0/sha256_file_amd64 [root@ecs-lee dockerfiles]# git push origin master Username for 'https://gitee.com': *********** Password for 'https://***********@gitee.com': Counting objects: 11, done. Delta compression using up to 4 threads. Compressing objects: 100% (8/8), done. Writing objects: 100% (8/8), 6.38 KiB | 0 bytes/s, done. Total 8 (delta 2), reused 0 (delta 0) remote: Powered by GITEE.COM [GNK-6.4] To https://gitee.com/lee1002/openGauss-server.git 6f87123..f3676fd master -> master4. 社区提交Pull Requests 创建 Pull Request 等待commit审查合入 五 优化总结提供openGauss 3.1.0版本amd容器打包方式通过builder两阶段构建减少镜像大小通过wget和builder方式优化了必须在本地存放相应安装包问题删除部分无效代码通过entrypoint.sh添加自定义参数并给予默认值参数名默认值功能GS_XLOGDIR${PGDATA}/xlogxlog目录默认值为GS_NODENAMEopengauss安装时nodenameENCODINGUTF-8字符集编码LOCALE--no-localeLOCALEDBCOMPATIBILITYPG数据库兼容性GS_PASSWORD8 位数随机密码密码
-
一、 下载源码[root@node3 ~]# git clone https://gitee.com/opengauss/openGauss-server.git Cloning into 'openGauss-server'... remote: Enumerating objects: 67538, done. remote: Counting objects: 100% (21733/21733), done. remote: Compressing objects: 100% (7802/7802), done. remote: Total 67538 (delta 15955), reused 17513 (delta 13814), pack-reused 45805 Receiving objects: 100% (67538/67538), 203.25 MiB | 9.94 MiB/s, done. Resolving deltas: 100% (47623/47623), done.二、原容器镜像制作1. 下载介质[root@node3 dockerfiles]# cd 3.0.0/ [root@node3 3.0.0]# ls dockerfile_amd dockerfile_arm entrypoint.sh gosu-amd64 gosu-arm64 openEuler_aarch64.repo sha256_file_amd64 sha256_file_arm64 [root@node3 3.0.0]# wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/x86/openGauss-3.0.0-CentOS-64bit.tar.bz22. 安装dockeryum[root@node3 dockerfiles]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo Loaded plugins: fastestmirror, langpacks adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo [root@node3 dockerfiles]# yum install docker-ce docker-ce-cli containerd.io -y国内加速[root@node3 dockerfiles]# cat /etc/docker/daemon.json { "registry-mirrors":[ "https://9cpn8tt6.mirror.aliyuncs.com", "https://registry.docker-cn.com" ] } [root@node3 dockerfiles]# systemctl restart docker3. buildDockerImage.sh[root@node3 dockerfiles]# sh buildDockerImage.sh -v 3.0.0 Checking Docker version. Checking if required packages are present and valid... openGauss-3.0.0-CentOS-64bit.tar.bz2: OK ========================== DOCKER info: Client: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., v0.9.1-beta3) buildx: Docker Buildx (Docker Inc., v0.9.1-docker) scan: Docker Scan (Docker Inc., v0.17.0) Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 20.10.18 Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 1 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc Default Runtime: runc Init Binary: docker-init containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6 runc version: v1.1.4-0-g5fd4c4d init version: de40ad0 Security Options: seccomp Profile: default Kernel Version: 3.10.0-957.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 7.62GiB Name: node3 ID: RPLL:AKDC:SMRS:XLID:E2UB:Y6WU:HAUI:FX66:IKXO:TNZD:SRNY:TDDL Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false ========================== Building image 'opengauss:3.0.0' ... Sending build context to Docker daemon 101.2MB Step 1/14 : FROM centos:7.6.1810 7.6.1810: Pulling from library/centos ac9208207ada: Downloading [======> ] 9.104MB/75.16MB ^C [root@node3 dockerfiles]# vi /etc/docker/daemon.json [root@node3 dockerfiles]# systemctl restart docker [root@node3 dockerfiles]# cat /etc/docker/daemon.json { "registry-mirrors":[ "https://9cpn8tt6.mirror.aliyuncs.com", "https://registry.docker-cn.com" ] } [root@node3 dockerfiles]# systemctl restart docker [root@node3 dockerfiles]# sh buildDockerImage.sh -v 3.0.0 Checking Docker version. Checking if required packages are present and valid... openGauss-3.0.0-CentOS-64bit.tar.bz2: OK ========================== DOCKER info: Client: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., v0.9.1-beta3) buildx: Docker Buildx (Docker Inc., v0.9.1-docker) scan: Docker Scan (Docker Inc., v0.17.0) Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 20.10.18 Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 1 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux Default Runtime: runc Init Binary: docker-init containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6 runc version: v1.1.4-0-g5fd4c4d init version: de40ad0 Security Options: seccomp Profile: default Kernel Version: 3.10.0-957.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 7.62GiB Name: node3 ID: RPLL:AKDC:SMRS:XLID:E2UB:Y6WU:HAUI:FX66:IKXO:TNZD:SRNY:TDDL Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://9cpn8tt6.mirror.aliyuncs.com/ https://registry.docker-cn.com/ Live Restore Enabled: false ========================== Building image 'opengauss:3.0.0' ... Sending build context to Docker daemon 101.2MB Step 1/14 : FROM centos:7.6.1810 7.6.1810: Pulling from library/centos ac9208207ada: Pull complete Digest: sha256:62d9e1c2daa91166139b51577fe4f4f6b4cc41a3a2c7fc36bd895e2a17a3e4e6 Status: Downloaded newer image for centos:7.6.1810 ---> f1cb7c7d58b7 Step 2/14 : COPY openGauss-3.0.0-CentOS-64bit.tar.bz2 . ---> 1d0cbd868984 Step 3/14 : COPY gosu-amd64 /usr/local/bin/gosu ---> 928758582360 Step 4/14 : ENV LANG en_US.utf8 ---> Running in 9aa647847dd5 Removing intermediate container 9aa647847dd5 ---> e221f4ad7757 Step 5/14 : RUN set -eux; yum install -y bzip2 bzip2-devel curl libaio&& groupadd -g 70 omm; useradd -u 70 -g omm -d /home/omm omm; mkdir -p /var/lib/opengauss && mkdir -p /usr/local/opengauss && mkdir -p /var/run/opengauss && mkdir /docker-entrypoint-initdb.d && tar -jxf openGauss-3.0.0-CentOS-64bit.tar.bz2 -C /usr/local/opengauss && chown -R omm:omm /var/run/opengauss && chown -R omm:omm /usr/local/opengauss && chown -R omm:omm /var/lib/opengauss && chown -R omm:omm /docker-entrypoint-initdb.d && chmod 2777 /var/run/opengauss && rm -rf openGauss-3.0.0-CentOS-64bit.tar.bz2 && yum clean all ---> Running in c24660db34d1 + yum install -y bzip2 bzip2-devel curl libaio Loaded plugins: fastestmirror, ovl Determining fastest mirrors * base: mirrors.bupt.edu.cn * extras: mirrors.bupt.edu.cn * updates: mirrors.bupt.edu.cn Resolving Dependencies --> Running transaction check ---> Package bzip2.x86_64 0:1.0.6-13.el7 will be installed ---> Package bzip2-devel.x86_64 0:1.0.6-13.el7 will be installed ---> Package curl.x86_64 0:7.29.0-51.el7 will be updated ---> Package curl.x86_64 0:7.29.0-59.el7_9.1 will be an update --> Processing Dependency: libcurl = 7.29.0-59.el7_9.1 for package: curl-7.29.0-59.el7_9.1.x86_64 ---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed --> Running transaction check ---> Package libcurl.x86_64 0:7.29.0-51.el7 will be updated ---> Package libcurl.x86_64 0:7.29.0-59.el7_9.1 will be an update --> Processing Dependency: libssh2(x86-64) >= 1.8.0 for package: libcurl-7.29.0-59.el7_9.1.x86_64 --> Running transaction check ---> Package libssh2.x86_64 0:1.4.3-12.el7 will be updated ---> Package libssh2.x86_64 0:1.8.0-4.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: bzip2 x86_64 1.0.6-13.el7 base 52 k bzip2-devel x86_64 1.0.6-13.el7 base 218 k libaio x86_64 0.3.109-13.el7 base 24 k Updating: curl x86_64 7.29.0-59.el7_9.1 updates 271 k Updating for dependencies: libcurl x86_64 7.29.0-59.el7_9.1 updates 223 k libssh2 x86_64 1.8.0-4.el7 base 88 k Transaction Summary ================================================================================ Install 3 Packages Upgrade 1 Package (+2 Dependent packages) Total download size: 876 k Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. warning: /var/cache/yum/x86_64/7/base/packages/bzip2-devel-1.0.6-13.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for bzip2-devel-1.0.6-13.el7.x86_64.rpm is not installed Public key for curl-7.29.0-59.el7_9.1.x86_64.rpm is not installed -------------------------------------------------------------------------------- Total 2.3 MB/s | 876 kB 00:00 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) " Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-6.1810.2.el7.centos.x86_64 (@CentOS) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : libssh2-1.8.0-4.el7.x86_64 1/9 Updating : libcurl-7.29.0-59.el7_9.1.x86_64 2/9 Updating : curl-7.29.0-59.el7_9.1.x86_64 3/9 Installing : libaio-0.3.109-13.el7.x86_64 4/9 Installing : bzip2-1.0.6-13.el7.x86_64 5/9 Installing : bzip2-devel-1.0.6-13.el7.x86_64 6/9 Cleanup : curl-7.29.0-51.el7.x86_64 7/9 Cleanup : libcurl-7.29.0-51.el7.x86_64 8/9 Cleanup : libssh2-1.4.3-12.el7.x86_64 9/9 Verifying : bzip2-devel-1.0.6-13.el7.x86_64 1/9 Verifying : curl-7.29.0-59.el7_9.1.x86_64 2/9 Verifying : libssh2-1.8.0-4.el7.x86_64 3/9 Verifying : bzip2-1.0.6-13.el7.x86_64 4/9 Verifying : libcurl-7.29.0-59.el7_9.1.x86_64 5/9 Verifying : libaio-0.3.109-13.el7.x86_64 6/9 Verifying : curl-7.29.0-51.el7.x86_64 7/9 Verifying : libssh2-1.4.3-12.el7.x86_64 8/9 Verifying : libcurl-7.29.0-51.el7.x86_64 9/9 Installed: bzip2.x86_64 0:1.0.6-13.el7 bzip2-devel.x86_64 0:1.0.6-13.el7 libaio.x86_64 0:0.3.109-13.el7 Updated: curl.x86_64 0:7.29.0-59.el7_9.1 Dependency Updated: libcurl.x86_64 0:7.29.0-59.el7_9.1 libssh2.x86_64 0:1.8.0-4.el7 Complete! + groupadd -g 70 omm + useradd -u 70 -g omm -d /home/omm omm + mkdir -p /var/lib/opengauss + mkdir -p /usr/local/opengauss + mkdir -p /var/run/opengauss + mkdir /docker-entrypoint-initdb.d + tar -jxf openGauss-3.0.0-CentOS-64bit.tar.bz2 -C /usr/local/opengauss + chown -R omm:omm /var/run/opengauss + chown -R omm:omm /usr/local/opengauss + chown -R omm:omm /var/lib/opengauss + chown -R omm:omm /docker-entrypoint-initdb.d + chmod 2777 /var/run/opengauss + rm -rf openGauss-3.0.0-CentOS-64bit.tar.bz2 + yum clean all Loaded plugins: fastestmirror, ovl Cleaning repos: base extras updates Cleaning up list of fastest mirrors Removing intermediate container c24660db34d1 ---> f4ae499280cf Step 6/14 : RUN set -eux; echo "export GAUSSHOME=/usr/local/opengauss" >> /home/omm/.bashrc && echo "export PATH=\$GAUSSHOME/bin:\$PATH " >> /home/omm/.bashrc && echo "export LD_LIBRARY_PATH=\$GAUSSHOME/lib:\$LD_LIBRARY_PATH" >> /home/omm/.bashrc ---> Running in 2476e733860c + echo 'export GAUSSHOME=/usr/local/opengauss' + echo 'export PATH=$GAUSSHOME/bin:$PATH ' + echo 'export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH' Removing intermediate container 2476e733860c ---> d3ef4604a117 Step 7/14 : ENV GOSU_VERSION 1.12 ---> Running in f9651ff17661 Removing intermediate container f9651ff17661 ---> 09120578b30d Step 8/14 : RUN set -eux; chmod +x /usr/local/bin/gosu ---> Running in f3e98497815c + chmod +x /usr/local/bin/gosu Removing intermediate container f3e98497815c ---> 49ea79f289ca Step 9/14 : ENV PGDATA /var/lib/opengauss/data ---> Running in 8904d7dd69f7 Removing intermediate container 8904d7dd69f7 ---> e7bd16787dd3 Step 10/14 : COPY entrypoint.sh /usr/local/bin/ ---> a76ddb916acd Step 11/14 : RUN chmod 755 /usr/local/bin/entrypoint.sh;ln -s /usr/local/bin/entrypoint.sh / # backwards compat ---> Running in f9d0c641357b Removing intermediate container f9d0c641357b ---> ddd27afee5a5 Step 12/14 : ENTRYPOINT ["entrypoint.sh"] ---> Running in f5b70bbdc217 Removing intermediate container f5b70bbdc217 ---> cd3a184c91ad Step 13/14 : EXPOSE 5432 ---> Running in 82b77be1ebe9 Removing intermediate container 82b77be1ebe9 ---> 1ebed742aefc Step 14/14 : CMD ["gaussdb"] ---> Running in 66fc27eca766 Removing intermediate container 66fc27eca766 ---> 18f4347e4d04 Successfully built 18f4347e4d04 Successfully tagged opengauss:3.0.0 openGauss Docker Image 3.0.0 is ready to be extended: --> opengauss:3.0.0 Build completed in 90 seconds.4. 启动容器image[root@node3 dockerfiles]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE opengauss 3.0.0 18f4347e4d04 11 seconds ago 663MB centos 7.6.1810 f1cb7c7d58b7 3 years ago 202MBrun[root@node3 dockerfiles]# docker run --name opengauss_3.0.0 --privileged=true -d -e GS_PASSWORD=GaussDB@123 opengauss:3.0.0 77e79f91e71082fd0fff3376adb8de2dbfc4eb257ec0fd5c60d4b110c79e8d9f [root@node3 dockerfiles]# docker logs opengauss_3.0.0 -f Message: The supplied GS_PASSWORD is meet requirements. The files belonging to this database system will be owned by user "omm". This user must also own the server process. The database cluster will be initialized with locale "en_US.utf8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". fixing permissions on existing directory /var/lib/opengauss/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 32MB creating configuration files ... ok Begin init undo subsystem meta. [INIT UNDO] Init undo subsystem meta successfully. creating template1 database in /var/lib/opengauss/data/base/1 ... The core dump path is an invalid directory 2022-10-09 01:40:26.710 [unknown] [unknown] localhost 140475676310592 0[0:0#0] [BACKEND] WARNING: macAddr is 578/2886795266, sysidentifier is 37923857/137466, randomNum is 593369338 ok initializing pg_authid ... ok setting password ... ok initializing dependencies ... ok loading PL/pgSQL server-side language ... ok creating system views ... ok creating performance views ... ok loading system objects' descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok initialize global configure for bucketmap length ... ok creating information schema ... ok loading foreign-data wrapper for distfs access ... ok loading foreign-data wrapper for hdfs access ... ok loading foreign-data wrapper for log access ... ok loading hstore extension ... ok loading foreign-data wrapper for MOT access ... ok loading security plugin ... ok update system tables ... ok creating snapshots catalog ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok freezing database template0 ... ok freezing database template1 ... ok freezing database postgres ... ok ... ... [0:0#0] 0 [EXECUTOR] ACTION: Please refer to backend log for more details.gsql[root@node3 dockerfiles]# docker exec -it opengauss_3.0.0 bash [root@77e79f91e710 /]# su - omm [omm@77e79f91e710 ~]$ gsql -d postgres -p5432 -r gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# select version(); version ------------------------------------------------------------------------------------------------------------------------------------------------------ (openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit (1 row) 由于篇幅限制,新容器镜像制作、PR提交及优化总结请继续阅读 优化openGauss官方容器源码(二)
-
前言2022年8月30日华为鲲鹏应用大赛openGauss赛道上海赛区第三名获奖作品开源分享,我们团队参加本次比赛的时候想了很多方案,但是最终还是决定用自己最擅长的项目参赛方案介绍系统实现学生在线考试管理的基本功能,包括学生登录、查看自己的个人信息及考试信息;提供了在线考试的界面;后台管理员有管理员添加学生、管理学生、管理成绩、添加课程、添加题库题目和组建试卷等功能。本次的学生在线考试管理系统采用Python Django做后端、前端框架采用Bootstrap4实现,实现学生考试的动态管理,使得对信息的管理更加及时、高效,提高了效率。同时还对系统的开发原理、功能特点和设计方案进行了介绍。关键词:考试管理 openGuass数据库 Python Django Web系统需求分析系统需求分析(1)学生用户是主要的需求者,主要需求功能是查看当前自己的考试信息、查看考试成绩并可导出以及进行在线考试等。(2)教师用户主要需求功能是为自己所教授的课程组建题库和相对应的试卷,并可以查看学生的考试信息等。(3)管理员用户的功能需求较为复杂,包括对学生信息、教师信息、考试信息进行管理。主要功能模块(1)用户登录:实现简单的登录及验证(2)个人信息展示:展示考生个人信息(3)考试管理:展示可以考试的试卷,考试及自动计算考试成绩。(4)考试成绩管理:展示考试结果、导出考试信息(5)后台基础数据管理:试卷,试题,考生等信息更新维护。设计思路设计思路系统设计包括三部分:数据库设计,功能函数视图设计,前端页面设计数据库设计根据对系统需求分析,得出该考试管理系统大致需要六个实体,他们的实体属性如下图所示:根据上面的实体联系图可以得出以下几个表:学院表:Academy专业表:Major课程表:Course学生表:Student题库表:QuestionBank试卷表:TestPaper学生成绩表:Record1.学院---序号、名称2.专业---序号、名称3.课程---课程号、课程名4.学生---学号、密码、姓名、性别、班级、邮箱5.试卷---标题、科目、使用专业、考试时常、开始时间6.题库---序号、专业、科目、备选项、题目、答案、难度、分值、题目类型字段基本数据分析页面及功能设计1、登录页面:其中需要登录,校验,登录后同时需要存储用户信息在Session中,以备登录后的页面使用。2、首页(考试信息页):页面需要显示当前用户可以参考的考试试卷信息,在此页面点击开始考试可以跳转到考试页面。3、考试页面:展示对应试卷的题目和选项信息,同时可以进行答题,交卷后可以自动计算考试分数并存入数据库。4、成绩显示页面:展示对应考试的考试结果5、后台管理:用于管理我们的专业,考生,试卷,题库等基础信息,为了快速实现系统将直接启用Django自带的Admin管理功能。6、个人详情:用于展示个人详情信息。功能函数视图设计功能函数视图设计学生在线考试系统是实现学生在线考试、查看相关信息的一个平台,整个学生在线考试系统共分为3个大模块:管理员模块,学生模块和公有模块,其中复杂的方法和模块的详细设计流程图如下。技术亮点及优势openGuass是基于PostgreSQL9.2版本开发的,基本包括了PostgreSQL9.4的功能。所以可以采用连接postgresql的方式连接openGauss数据库。django项目下的setting中的DATABASES下进行以下配置:DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3','ENGINE': 'django.db.backends.postgresql_psycopg2','NAME': 'postgres', #数据库名'USER': 'andy', #用户名'PASSWORD': 'xxxxxxx', #密码'HOST': 'xxx.xxx.xxx.xxx',#虚拟机ip'PORT': xxxx #openGauss数据口的端口}}Django项目框架搭建起来后,我们所有对系统的前后台所有的程序开发都可以在这个项目中进行了,一个典型的Django项目模块功能的开发包括如下几个步骤:(1)创建app(2)注册app(3)定义模型(4)定义视图函数(5)配置访问路由URL(6)静态资源准备及配置(7)前端模板开发(8)测试及运行商业模式及市场前景国外数据库占据国内大部分市场,关注国际局势的每个人都明白,核心技术掌握在自己手里的重要性,所以说我们要提倡使用属于我们自己的核心技术,这对于我们是很重要的!功能测试 登录测试 查询测试 考试测试 项目总结我们团队通过这次openguass开发,进一步掌握数据库的方法和技术,提高软件开发的实际能力,培养设计能力和综合分析、解决问题的能力。学习和实践了分析和设计软件系统的各种知识,包括面向对象的系统分析与设计,编码和测试方面的知识。熟悉了如何根据实际需要分析实体关系,画出ER图从而设计出符合要求的数据库表。学习和实践的数据库的增删改查功能在具体功能开发中的使用。熟悉了openGuass数据库的相关操作。
-
为什么别人的查询只要几秒,而你的查询语句少则十多秒,多则十几分钟甚至几个小时?与你的查询语句是否高效有很大关系。今天我们来看看如何写出比较高效的查询语句。1.尽量不要使用NULL当默认值在有索引的列上如果存在NULL值会使得索引失效,降低查询速度,该如何优化呢?例如:SELECT * FROM [Sales].[Temp_SalesOrder] WHERE UnitPrice IS NULL我们可以将NULL的值设置成0或其他固定数值,这样保证索引能够继续有效。SELECT * FROM [Sales].[Temp_SalesOrder] WHERE UnitPrice =0这是改写后的查询语句,效率会比上面的快很多。2.尽量不要在WHERE条件语句中使用!=或<>在WHERE语句中使用!=或<>也会使得索引失效,进而进行全表扫描,这样就会花费较长时间了。3.应尽量避免在 WHERE子句中使用 OR遇到有OR的情况,我们可以将OR使用UNION ALL来进行改写例如:SELECT * FROM T1 WHERE NUM=10 OR NUM=20可以改写成SELECT * FROM T1 WHERE NUM=10UNION ALLSELECT * FROM T1 WHERE NUM=204.IN和NOT IN也要慎用遇到连续确切值的时候 ,我们可以使用BETWEEN AND来进行优化例如:SELECT * FROM T1 WHERE NUM IN (5,6,7,8)可以改写成:SELECT * FROM T1 WHERE NUM BETWEEN 5 AND 8.5.子查询中的IN可以使用EXISTS来代替子查询中经常会使用到IN,如果换成EXISTS做关联查询会更快例如:SELECT * FROM T1 WHERE ORDER_ID IN (SELECT ORDER_ID FROM ORDER WHERE PRICE>20);可以改写成:SELECT * FROM T1 AS A WHERE EXISTS (SELECT 1 FROM ORDER AS B WHERE A.ORDER_ID=B.ORDER_ID AND B.PRICE>20)虽然代码量可能比上面的多一点,但是在使用效果上会优于上面的查询语句。6.模糊匹配尽量使用前缀匹配在进行模糊查询,使用LIKE时尽量使用前缀匹配,这样会走索引,减少查询时间。例如:SELECT * FROM T1 WHERE NAME LIKE '%李四%'或者SELECT * FROM T1 WHERE NAME LIKE '%李四'均不会走索引,只有当如下情况SELECT * FROM T1 WHERE NAME LIKE '李四%'才会走索引。上述这些都是平常经常会遇到的,就直接告诉大家怎么操作了,具体可以下去做试验尝试一下。来源:SQL数据库开发
-
RDS for MySQL实例支持绑定多个安全组(为了更好的网络性能,建议不超过5个)。此时,实例的访问规则遵循几个安全组规则的并集。什么是安全组?安全组是一个逻辑上的分组,为同一个VPC内具有相同安全保护需求,并相互信任的ECS和云数据库RDS实例提供访问策略。用户可以在安全组中定义各种访问规则,当实例加入该安全组后,即受到这些访问规则的保护。您也可以根据需要创建自定义的安全组,或使用默认安全组。系统会为每个用户默认创建一个默认安全组,默认安全组的规则是在出方向上的数据报文全部放行,入方向访问受限,安全组内的ECS无需添加规则即可互相访问。如何绑定多个安全组?购买实例时绑定多安全组:在“实例管理”页面,单击“购买数据库实例”。在“安全组”下拉框,选择多个安全组。购买后绑定多安全组:在“实例管理”页面,选择对应的主实例或只读实例,单击实例名称。在 “安全组”处,单击“管理”,选择多个安全组。配置安全组规则示例为了保障数据库的安全性和稳定性,在使用云数据库RDS实例之前,您需要设置安全组,开通需访问数据库的IP地址和端口。场景1:RDS与ECS在相同安全组,直接连接。场景2:RDS与ECS在不同安全组,需分别添加RDS安全组入方向规则,ECS安全组出方向规则(出方向规则可以全部放通),放通来自另一个安全组内的ECS的访问。入方向规则添加示例:方向协议/应用端口源地址入方向TCP3306单个IP地址、IP地址段或安全组。例如:192.168.20.6/53绑定多个安全组,实例的访问规则遵循几个安全组规则的并集。可以绑定配置了该入方向规则的安全组,即可放通RDS连接。
-
使用MTK迁移Mysql源库后主键自增列导致数据无法插入问题故障背景用户使用Mogdb 2.0.1版本进行业务上线测试,发现在插入数据时,应用日志中提示primary key冲突,用户自查业务SQL没有问题,接到通知后,招手处理故障。 故障描述及根源分析通过对用户数据表的检查,发现在id列上有一个primary key,并且制定了一个序列器作为自增主键的代替。初步怀疑是id中的值,已经超过了序列器的最大值,导致了故障的发生。 分别检查序列器和表.id字段的最大值,发现果然max(id)为474,序列器最大值刚刚44。file_manage=> \d file_table Table "file_manage.file_table" Column | Type | Modifiers ---------------+-----------------------------+--------------------------------------------------------- id | bigint | not null default nextval('file_table_id_seq'::regclass) type_id | bigint | column_name | character varying(32) | default NULL::character varying file_id | character varying(64) | default NULL::character varying file_name | character varying(100) | default NULL::character varying category_type | integer | default 0 pieces_id | bigint | flag | smallint | default (0)::smallint del_flag | smallint | default (0)::smallint create_time | timestamp without time zone | default pg_systimestamp() update_time | timestamp without time zone | default pg_systimestamp() file_manage=> \d file_table_id_seq Sequence "file_manage.file_table_id_seq" Column | Type | Value ---------------+---------+--------------------- sequence_name | name | file_table_id_seq last_value | bigint | 44 start_value | bigint | 1 increment_by | bigint | 1 max_value | bigint | 9223372036854775807 min_value | bigint | 1 cache_value | bigint | 1 log_cnt | bigint | 32 is_cycled | boolean | f is_called | boolean | t uuid | bigint | 0 Owned by: file_manage.file_table.id同时查看报错的id对应值是否在file_table表中是否存在:file_manage=> select count(*) from file_table where id=43; count ------- 1 (1 row) file_manage=> select count(*) from file_table where id=44; count ------- 1 (1 row)由此,基本上可以确定故障原因在于表中主键列已经保存了一定数量的值,在操作过程中,序列器并没有进行累加,导致序列器nextval已经远远小于主节列值,从而引发主键冲突。咨询用户后,用户确实使用过insert into语句为数据表插入了部分测试数据库上的数据。故障处理流程使用语句重新为序列器重置currvalfile_manage=> select setval('file_table_id_seq',(select max(id) from file_table)); setval -------- 474 (1 row)通知用户重新启动应用进行测试,故障现象消失。故障总结分析本次故障的成因是通过MTK进行数据数据迁移时,如果源库是MySQL,MTK会通过判断MySQL数据表是否存在自增主键,如果存在泽辉建立一个序列器模拟MySQL自增主键效果。 但是如果在此类表上进行手动gs_dump或者insert into操作时,由于在操作过程中指定了主键列的值,并不会推搞序列器的currval,最会导致在正常的数据增删改之后,出现类似主键冲突的问题。 对应的处理办法是需要在数据插入后,手动进行序列器的currval的重置,指向当前主键最大值。
推荐直播
-
HDC深度解读系列 - Serverless与MCP融合创新,构建AI应用全新智能中枢2025/08/20 周三 16:30-18:00
张昆鹏 HCDG北京核心组代表
HDC2025期间,华为云展示了Serverless与MCP融合创新的解决方案,本期访谈直播,由华为云开发者专家(HCDE)兼华为云开发者社区组织HCDG北京核心组代表张鹏先生主持,华为云PaaS服务产品部 Serverless总监Ewen为大家深度解读华为云Serverless与MCP如何融合构建AI应用全新智能中枢
回顾中 -
关于RISC-V生态发展的思考2025/09/02 周二 17:00-18:00
中国科学院计算技术研究所副所长包云岗教授
中科院包云岗老师将在本次直播中,探讨处理器生态的关键要素及其联系,分享过去几年推动RISC-V生态建设实践过程中的经验与教训。
回顾中 -
一键搞定华为云万级资源,3步轻松管理企业成本2025/09/09 周二 15:00-16:00
阿言 华为云交易产品经理
本直播重点介绍如何一键续费万级资源,3步轻松管理成本,帮助提升日常管理效率!
回顾中
热门标签