返回首页

gbase数据、南大通用产品文档:GBase8a高可用性示例

更新日期:2024年09月11日

#ifdef WIN32
#include
#else
#include
#endif
#include
#include
#include
#include
#include
#define isSuc(result) ((result) == SQL_SUCCESS || (result) ==
SQL_SUCCESS_WITH_INFO)

char hosts[][100] = {"192.168.5.64",

GBase 8a 程序员手册ODBC 篇


- 56 -

南大通用数据技术股份有限公司
"192.168.5.65",
"192.168.5.64;192.168.5.65",
"192.168.5.65;192.168.5.64",
"192.168.5.64;192.168.5.64",
"192.168.5.64;192.168.5.64;192.168.5.65",
"192.168.5.64;192.168.5.65;192.168.5.64",
"192.168.5.65;192.168.5.64;192.168.5.64",
"192.168.5.65;192.168.5.66",
NULL};
int main(void)
{
char conn_format[200] = "DRIVER={GBase 8a ODBC 8.3 Driver};"
"SERVER={%s};UID=root;PWD=1;DATABASE=test;PORT=5258;";

char conn[200] = {'\0'};

int i = 0;

short sret; //返回代码

void* henv; //环境句柄

void* hdbc; //连接句柄

/** 申请环境句柄**/

sret =
SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&henv);

if(!isSuc(sret))printf("申请环境句柄出错\n");

/** 设置环境属性,声明ODBC 版本**/

sret =
SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
if(!isSuc(sret))printf("声明ODBC 版本出错\n");
/** 申请连接句柄**/
sret = SQLAllocHandle(SQL_HANDLE_DBC,henv,&hdbc);

if(!isSuc(sret))printf("申请连接句柄出错\n");
/** 设置连接属性**/
sret = SQLSetConnectAttr(hdbc,SQL_ATTR_AUTOCOMMIT,
(void*)SQL_AUTOCOMMIT_OFF,SQL_IS_INTEGER);
if(!isSuc(sret))printf("设置连接属性出错\n");

while(*hosts[i])

GBase 8a 程序员手册ODBC 篇
南大通用数据技术股份有限公司

- 57 -
{
sprintf(conn, conn_format, hosts[i]);
/** 连接数据源**/
sret = SQLDriverConnect(hdbc,NULL,(unsigned char *)conn,
SQL_NTS, NULL, 0, NULL, 0);
if(!isSuc(sret))printf("连接%s 出错\n", hosts[i]);
else printf("连接%s 成功\n", hosts[i]);
SQLDisconnect(hdbc);
memset(conn, '\0', strlen(conn));
i++;
}
return 0;
}

1.
用户优先级设定

语法:
grant usage on *.* to user_name with task_priority priority_value
priority_value 的取值范围为0,1,2,3 对应最小优先级,低优先级、中优先
级和高优先级,缺省为中优先级2。

权限要求:
有grant 权限的用户,推荐用户:root

示例:
gbase> create user uer1 ;
Query OK, 0 rows affected
gbase> grant usage on *.* to
uer1
with task_priority
1;
Query OK, 0 rows affected
gbase> select task_priority from user where user='user1';
+---------------+
| task_priority |

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1294
+---------------+
|
1 |
+---------------+
1 row in set
2.
用户资源组设定

语法:
grant usage on *.* to user_name with resource_group group_value
group_value 的取值范围为0-15,0 组为缺省组。

权限要求:
有grant 权限的用户,推荐用户:root。

示例:
gbase> create user user0 identified by 'user0';
Query OK, 0 rows affected
gbase> grant usage on *.* to user0 with resource_group 0;
Query OK, 0 rows affected
gbase> select resource_group from user where user='user0';
+----------------+
| resource_group |
+----------------+
|
0 |
+----------------+
1 row in set
3.
查询并行度设定

语法:
grant usage on *.* to user_name with max_cpus_used max_cpus_used_value
max_cpus_used_value 的取值范围为大于0 的整数,
该参数决定查询的并行度,
推荐值为用户所在资源组的可用CPU 数目。

权限要求:
有grant 权限的用户,推荐用户:root。

示例:
gbase> use gbase;
Query OK, 0 rows affected

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1295
gbase> create user user1;
Query OK, 0 rows affected
gbase> grant usage on *.* to
user1
with max_cpus_used
4;
Query OK, 0 rows affected
gbase> select max_cpus from user where user='user1';
+----------+
| max_cpus |
+----------+
|
4 |
+----------+
1 row in set
4.
用户优先级与任务调度配重设定

语法
Set
gcluster
global
gbase_high_priority_weight = weight_value(80-100)
Set
gcluster
global
gbase_mid_priority_weight = weight_value (60-80)
Set
gcluster
global
gbase_low_priority_weight = weight_value (40-60)
Set
gcluster
global
gbase_min_priority_weight = weight_value (20-40)

weight_value 取值按高、中、低、最小划分,具体范围如下:
高:80 – 100
中:60 - 80
低:40 - 60
最小:20 - 40

权限要求
有set 权限用户

示例
gbase> Set
gcluster
global
gbase_min_priority_weight = 20;
Query OK, 0 rows affected, 32 warnings (Elapsed: 00:00:00.01)
gbase> show variables like '%gbase_min_priority_weight%';
+---------------------------+-------+
| Variable_name
| Value |
+---------------------------+-------+
| gbase_min_priority_weight | 20
|

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1296
+---------------------------+-------+
1 row in set (Elapsed: 00:00:00.00)
说明
使用上述语句配重值不会持久化,即gnode 重新启动后会丢失。
要是需要持久化,则需要在执行该语句之前先执行:
set
gbase_global_variable_persistent = 1
执行该语句后执行:
set
gbase_global_variable_persistent = 0
配重参数可控制cpu.shares 与blkio.weight 参数。
表5- 165 具体可参考
参数
CGroup 最
小值
CGroup 最
大值
CGroup 缺
省值
集群
最小值
集群
最大值
集群比重
计算
cpu.shares
1

1024
1
2560
(2560 *
weight) /
100
Blkio.weig
ht
1
1000
300
1
1000
(1000 *
weight) /
100
5.
显示优先级状态
1)
语法
Show priorities [where conditions]
2)
显示
node_name:集群节点名称。
Group:资源组编号。
Priority:优先级编号。
priority_weight:优先级配重。
Status:优先级开启状态ON/OFF。
Description:优先级控制参数描述。
3)
权限要求
有show 权限用户。
4)
示例

需要配置cgconfig.conf 文件。在配置文件中为资源组0、1 进行设置。

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1297

启动cgconfig 服务。

重启gcware:
$gcluster_services gcware restart
完成以上配置操作后,再执行下面示例的命令,0、1 两个控制组的优先
级将为开启状态。

示例1:查看集群全部节点优先级状态。
gbase> show priorities;
+-----------+-------+----------+----------------+--------+-------------+
| node_name | group | priority | priority-weight | status | description|
+-----------+-------+----------+-----------------+-------+-------------+
| node1
|
0|
0 |
20 | ON
|......
|
| node1
|
0|
1 |
40 | ON
|......
|
| node1
|
0|
2 |
60 | ON
|......
|
| node1
|
0|
3 |
80 | ON
|......
|
| node1
|
1|
0 |
20 | ON
|......
|
| node1
|
1|
1 |
40 | ON
|......
|
| node1
|
1|
2 |
60 | ON
|......
|
| node1
|
1|
3 |
80 | ON
|......
|
| node1
|
2|
0 |
20 | OFF
|......
|
| node1
|
2|
1 |
40 | OFF
|......
|
| node1
|
2|
2 |
60 | OFF
|......
|
| node1
|
2|
3 |
80 | OFF
|......
|
......
| node2
|
15|
0 |
20 | OFF
|......
|
| node2
|
15|
1 |
40 | OFF
|......
|
| node2
|
15|
2 |
60 | OFF
|......
|
| node2
|
15|
3 |
80 | OFF
|......
|
+-----------+-------+----------+-----------------+-------+-------------+
128 rows in set

示例2:查看node1 节点的优先级状态信息。
gbase> show
priorities
where node_name = 'node1';
+-----------+-------+----------+----------------+--------+-------------+
| node_name | group | priority | priority-weight | status | description|
+-----------+-------+----------+-----------------+-------+-------------+
| node1
|
0|
0 |
20 | ON
|......
|

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1298
| node1
|
0|
1 |
40 | ON
|......
|
| node1
|
0|
2 |
60 | ON
|......
|
| node1
|
0|
3 |
80 | ON
|......
|
| node1
|
1|
0 |
20 | ON
|......
|
| node1
|
1|
1 |
40 | ON
|......
|
| node1
|
1|
2 |
60 | ON
|......
|
| node1
|
1|
3 |
80 | ON
|......
|
| node1
|
2|
0 |
20 | OFF
|......
|
| node1
|
2|
1 |
40 | OFF
|......
|
| node1
|
2|
2 |
60 | OFF
|......
|
| node1
|
2|
3 |
80 | OFF
|......
|
......
| node1
|
15|
0 |
20 | OFF
|......
|
| node1
|
15|
1 |
40 | OFF
|......
|
| node1
|
15|
2 |
60 | OFF
|......
|
| node1
|
15|
3 |
80 | OFF
|......
|
+-----------+-------+----------+-----------------+-------+-------------+
64 rows in set

示例3:查看状态为ON 的优先级信息。
gbase> show priorities where status ='ON';
+-----------+-------+----------+----------------+--------+-------------+
| node_name | group | priority | priority-weight | status | description|
+-----------+-------+----------+-----------------+-------+-------------+
| node1
|
0|
0 |
20 | ON
|......
|
| node1
|
0|
1 |
40 | ON
|......
|
| node1
|
0|
2 |
60 | ON
|......
|
| node1
|
0|
3 |
80 | ON
|......
|
| node1
|
1|
0 |
20 | ON
|......
|
| node1
|
1|
1 |
40 | ON
|......
|
| node1
|
1|
2 |
60 | ON
|......
|
| node1
|
1|
3 |
80 | ON
|......
|
+-----------+-------+----------+-----------------+-------+-------------+
8 rows in set

示例4:关闭node1 节点cgroup 配置服务(service cgconfig stop)。

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1299
# service cgconfig stop
Stopping cgconfig service: [
OK
]
# su - gbase
$ gcluster_services all restart
Stopping GCMonit success!
Signaling GCRECOVER (gcrecover) to terminate: [
OK
]
Waiting for gcrecover services to unload:...[
OK
]
Signaling GCSYNC (gc_sync_server) to terminate: [
OK
]
[
OK
]for gc_sync_server services to unload:[
OK
]
Signaling GCLUSTERD
to terminate: [
OK
]
.[
OK
]or gclusterd services to unload:...[
OK
]
Signaling GBASED
to terminate: [
OK
]
.[
OK
]or gbased services to unload:[
OK
]
Signaling GCWARE (gcware) to terminate: [
OK
]
Waiting for gcware services to unload:.[
OK
]
Starting GCWARE (gcwexec): [
OK
]
Starting GCMonit success!
Starting GBASED
: [
OK
]
Starting GCLUSTERD :
[
OK
]
Starting GCSYNC : [
OK
]
Starting GCRECOVER : [
OK
]
$ gccli -uroot
GBase client 9.5.3.17.117651. Copyright (c) 2004-2019, GBase.
All Rights Reserved.
gbase> show
priorities
where node_name = 'node1';
+-----------+-------+----------+----------------+--------+-------------+
| node_name | group | priority | priority-weight | status | description|
+-----------+-------+----------+-----------------+-------+-------------+
| node1
|
0|
0 |
20 | OFF
|......
|
| node1
|
0|
1 |
40 | OFF
|......
|
| node1
|
0|
2 |
60 | OFF
|......
|
| node1
|
0|
3 |
80 | OFF
|......
|
| node1
|
1|
0 |
20 | OFF
|......
|
| node1
|
1|
1 |
40 | OFF
|......
|
| node1
|
1|
2 |
60 | OFF
|......
|
| node1
|
1|
3 |
80 | OFF
|......
|

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1300
| node1
|
2|
0 |
20 | OFF
|......
|
| node1
|
2|
1 |
40 | OFF
|......
|
| node1
|
2|
2 |
60 | OFF
|......
|
| node1
|
2|
3 |
80 | OFF
|......
|
......
| node1
|
15|
0 |
20 | OFF
|......
|
| node1
|
15|
1 |
40 | OFF
|......
|
| node1
|
15|
2 |
60 | OFF
|......
|
| node1
|
15|
3 |
80 | OFF
|......
|
+-----------+-------+----------+-----------------+-------+-------------+
64 rows in set

示例5:重新开启node1 的cgroup 配置服务(service cgconfig start)。
# service cgconfig start
Starting cgconfig service: [
OK
]
# su - gbase
# gcluster_services all restart
Stopping GCMonit success!
Signaling GCRECOVER (gcrecover) to terminate: [
OK
]
Waiting for gcrecover services to unload:...[
OK
]
Signaling GCSYNC (gc_sync_server) to terminate: [
OK
]
[
OK
]for gc_sync_server services to unload:[
OK
]
Signaling GCLUSTERD
to terminate: [
OK
]
.[
OK
]or gclusterd services to unload:...[
OK
]
Signaling GBASED
to terminate: [
OK
]
.[
OK
]or gbased services to unload:[
OK
]
Signaling GCWARE (gcware) to terminate: [
OK
]
Waiting for gcware services to unload:.[
OK
]
Starting GCWARE (gcwexec): [
OK
]
Starting GCMonit success!
Starting GBASED
: [
OK
]
Starting GCLUSTERD :
[
OK
]
Starting GCSYNC : [
OK
]
Starting GCRECOVER : [
OK
]

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1301
$ gccli -uroot
GBase client 9.5.3.17.117651. Copyright (c) 2004-2019, GBase.
All Rights Reserved.
gbase> show
priorities
where node_name = 'node1';
+-----------+-------+----------+----------------+--------+-------------+
| node_name | group | priority | priority-weight | status | description|
+-----------+-------+----------+-----------------+-------+-------------+
| node1
|
0|
0 |
20 | ON
|......
|
| node1
|
0|
1 |
40 | ON
|......
|
| node1
|
0|
2 |
60 | ON
|......
|
| node1
|
0|
3 |
80 | ON
|......
|
| node1
|
1|
0 |
20 | ON
|......
|
| node1
|
1|
1 |
40 | ON
|......
|
| node1
|
1|
2 |
60 | ON
|......
|
| node1
|
1|
3 |
80 | ON
|......
|
| node1
|
2|
0 |
20 | OFF
|......
|
| node1
|
2|
1 |
40 | OFF
|......
|
| node1
|
2|
2 |
60 | OFF
|......
|
| node1
|
2|
3 |
80 | OFF
|......
|
......
| node1
|
15|
0 |
20 | OFF
|......
|
| node1
|
15|
1 |
40 | OFF
|......
|
| node1
|
15|
2 |
60 | OFF
|......
|
| node1
|
15|
3 |
80 | OFF
|......
|
+-----------+-------+----------+-----------------+-------+-------------+
64 rows in set
6.
配置优先级队列相关参数
通过在gcluster($GCLUSTER_BASE/config/gbase_8a_gcluster.cnf)与
gnode($GBASE_BASE/config/gbase_8a_gbase.cnf)的配置文件中修改下面几
个参数值来完成优先级队列的配置:

gbase_use_priority_queue:
参数设置为0,表示关闭优先级队列;
设置为1,表示开启优先级队列。

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1302

_gbase_priority_total_tasks:参数表示最大并行运行查询任务数目,包括
DML 的查询部分,本参数最大值不能超过128,缺省为本地CPU 核数2
倍;

_gbase_priority_tasks:
参数表示每个优先级队列可容纳最大任务数目
(即
可参加调度的数目),未能进入队列任务将阻塞等待,本参数最大值不
能超过64,缺省为本地CPU 核数;

gbase_use_res_ctrl_group:
本参数决定是不是启用资源控制组挂接。
参数
设置为0,表示不开启资源控制组挂接,缺省设置为不开启状态;设置
其他值为开启资源控制组挂接。
7.
指定查询SQL 优先级
资源组用户Session 可根据具体情况,通过使用hint (格式为
/*+PRIORITY(‘priority_value’)*/), 决定该SQL 运行级别
(即对应的优先级)

本命令只限于查询SQL。

语法:
Select /*+PRIORITY(‘priority_value’)*/ …
权限要求
有create,insert,drop,select 权限的用户。

备注:
优先级设定只能小于或等于该用户优先级别,设置错误会恢复到用户优先
级,并报出警告“can not upgrade to priority X”(X 是执行用户的优先级)。

示例:
gbase> create table t1(a int);
Query OK, 0 rows affected
gbase> insert into t1 values (1),(1),(2),(3),(5);
Query OK, 5 rows affected
Records: 5
Duplicates: 0
Warnings: 0
gbase> select
/*+PRIORITY(‘0’)*/ * from t1 group by a;
+------+
| a
|
+------+
|
1 |
|
2 |
|
3 |

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1303
|
5 |
+------+
4 rows in set

使用 DROP XADATASOURCE TYPE 语句从数据库在删除之前定义的符合 XA
的数据源类型。
该语句是 SQL ANSI/ISO 标准的扩展。
语法

元素
描述
限制
语法
xa_type 要删除的 XA 数据
源类型的名称
必须存在于 sysxasourcetypes
系统目录表中
标识符
用法
RESTRICT 关键字是必需的。如果虚拟表或索引存在并使用了此数据源,则您不
能删除 XA 数据源类型、您必须是用户 gbasedbt 或具有 DBA 特权才能删除
XA 数据源类型。
DROP XADATASOURCE TYPE 语句在高可用集群中的辅助服务器上不支持。
以下语句删除了名为 MQSeries
® 的 XA 数据源类型,它被用户 gbasedbt 拥有:
DROP XADATASOURCE TYPE gbasedbt.MQSeries RESTRICT;
您不能删除 XA 数据源类型,直到所有使用数据源类型的 XA 数据源实例都被
删除后,您才可以删除 XA 数据源类型。

GBase 8s SQL 指南:语法
南大通用数据技术股份有限公司 596
如果您包含可选的 IF EXISTS 关键字,则如果未在当前数据库中注册指定名称的
XA 数据源类型,则数据库服务器不采取任何操作(而不是向应用程序发送异
常)。