ITPub博客

首页 > 数据库 > 国内数据库 > OceanBase集群命令

OceanBase集群命令

原创 国内数据库 作者:wwjfeng 时间:2026-04-12 14:00:50 0 删除 编辑

1.启动与停止

#集群合并
alter system major freeze;
#停止集群:
obd cluster stop fgeduobce;
#启动集群:
obd cluster start fgeduobce;
#重启集群
obd cluster restart fgeduobce;
#查看集群状态
obd cluster display fgeduobce;
#停止节点服务
alter system stop(start) server '192.168.18.41:2882' ;
#检查OceanBase 集群各个节点进程信息
IPS="192.168.18.41 192.168.18.42 192.168.18.43"
for ob in $IPS;do echo $ob; ssh $ob "ps -ef | grep observer | grep -v grep "; 
done
#检查OceanBase 集群各个节点监听状况。
IPS="192.168.18.41 192.168.18.42 192.168.18.43"
for ob in $IPS;do echo $ob; ssh $ob "netstat -ntlp"; done

2.查看主备副本切换事件

SELECT DATE_FORMAT(gmt_create, '%b%d %H:%i:%s') gmt_create_,
module,
event,
name1,
value1,
name2,
value2,
rs_svr_ip,
name3,
value3,
name4,
value4
FROM __all_rootservice_event_history
WHERE 1 = 1
AND module IN ('leader_coordinator', 'balancer')
ORDER BY gmt_create DESC LIMIT 20;

3.查看节点状态

select a.zone,
concat(a.svr_ip, ':', a.svr_port) observer,
cpu_total,
(cpu_total - cpu_assigned) cpu_free,
round(mem_total / 1024 / 1024 / 1024) mem_total_gb,
round((mem_total - mem_assigned) / 1024 / 1024 / 1024)
mem_free_gb,
usec_to_time(b.last_offline_time) last_offline_time,
usec_to_time(b.start_service_time) start_service_time,
b.status,
usec_to_time(b.stop_time) stop_time,
b.build_version
from __all_virtual_server_stat a
join __all_server b
on (a.svr_ip = b.svr_ip and a.svr_port = b.svr_port)
order by a.zone, a.svr_ip;

4.登录和使用

#proxy连接
obclient -h 192.168.18.41 -uroot@sys#fgeduobce -P2883 -prootroot -c -A oceanbase

5.查看集群可用资源

#查看集群可用资源
select a.zone,
concat(a.svr_ip, ':', a.svr_port) observer,
cpu_total,
cpu_assigned,
(cpu_total - cpu_assigned) cpu_free,
mem_total / 1024 / 1024 / 1024 mem_total_gb,
mem_assigned / 1024 / 1024 / 1024 mem_assign_gb,
(mem_total - mem_assigned) / 1024 / 1024 / 1024 mem_free_gb
from __all_virtual_server_stat a
join __all_server b
on (a.svr_ip = b.svr_ip and a.svr_port = b.svr_port)
order by a.zone, a.svr_ip;
#查看资源分配细节
select t1.name resource_pool_name,
t2. name unit_config_name,
t2.max_cpu,
t2.min_cpu,
t2.max_memory / 1024 / 1024 / 1024 max_mem_gb,
t2.min_memory / 1024 / 1024 / 1024 min_mem_gb,
t3.unit_id,
t3.zone,
concat(t3.svr_ip, ':', t3. svr_port) observer,
t4.tenant_id,
t4.tenant_name
from __all_resource_pool t1
join __all_unit_config t2
on (t1.unit_config_id = t2.unit_config_id)
join __all_unit t3
on (t1. resource_pool_id = t3. resource_pool_id)
left join __all_tenant t4
on (t1.tenant_id = t4.tenant_id)
order by t1. resource_pool_id, t2. unit_config_id, t3.unit_id;

6.资源单元管理

#创建资源单元
CREATE resource unit unti_fgres1 max_cpu=3, min_cpu=3,
max_memory='1G', min_memory='1G', max_iops=10000,
min_iops=1000, max_session_num=1000000, max_disk_size='10G';
#查看资源单元
select * from __all_unit_config;
#确认是否还有资源池在使用旧 unit
SELECT name FROM __all_resource_pool
WHERE unit_config_id = (
  SELECT unit_config_id FROM __all_unit_config WHERE name = 'unti_fgres1'
);
#删除unit

7.资源池管理

create resource pool pool_fg1 unit='unit_fg1',unit_num=1,zone_list=('zone1' ,'zone2' ,'zone3') ;
SELECT * FROM oceanbase.__all_resource_pool;
ALTER RESOURCE POOL pool_fg4 unit='unit_fg2';
SELECT tenant_id,tenant_name,resource_pool_name FROM oceanbase.gv$unit
select t1.name resource_pool_name,
t2. name unit_config_name,
t2.max_cpu,
t2.min_cpu,
t2.max_memory / 1024 / 1024 / 1024 max_mem_gb,
t2.min_memory / 1024 / 1024 / 1024 min_mem_gb,
t3.unit_id,
t3.zone,
concat(t3.svr_ip, ':', t3. svr_port) observer,
t4.tenant_id,
t4.tenant_name
from __all_resource_pool t1
join __all_unit_config t2
on (t1.unit_config_id = t2.unit_config_id)
join __all_unit t3
on (t1. resource_pool_id = t3. resource_pool_id)
left join __all_tenant t4
on (t1.tenant_id = t4.tenant_id)
order by t1. resource_pool_id, t2. unit_config_id, t3.unit_id;

8.租户管理

#创建租户
CREATE TENANT tent_fgedu2
CHARSET='utf8mb4',ZONE_LIST=('zone1','zone2','zone3'),
PRIMARY_ZONE='zone1;zone2,zone3', RESOURCE_POOL_LIST=('pool_fg1')
SET ob_tcp_invited_nodes='%';
#查看集群内所有租户所使用的资源单元的配置信息。
SELECT * FROM gv$unit;
#查看某个租户的所有资源池中资源单元的个数,则可以执行以下命令查看。
SELECT resource_pool_id, name, unit_count, unit_config_id FROM
__all_resource_pool WHERE tenant_id='1001';
#查看租户会话
SHOW PROCESSLIST;
#终止租户会话
KILL [CONNECTION] 'session_id';
#查看和设置租户白名单
obclient> SHOW VARIABLES LIKE 'ob_tcp_invited_nodes';
obclient> SET GLOBAL ob_tcp_invited_nodes='%';
obclient> SET GLOBAL ob_tcp_invited_nodes='10.10.10.%';
#修改租户tenant3 的Locality,增加副本数。
ALTER TENANT tent_fgedu3 locality="F@zone1,F@zone2,F@zone3";
#删除租户
DROP TENANT tent_fgedu3 FORCE;
#查询租户状态
SELECT tenant_id, tenant_name, status 
FROM oceanbase.__all_tenant 
WHERE tenant_name = 'tent_fgedu1';

9.observer宕机恢复相关命令

#查看状态
$ obd cluster display fgeduobce
Get local repositories and plugins ok
Open ssh connection ok
Cluster status check ok
[ERROR] Some of the servers in the cluster have been stopped
obs1(192.168.18.41) oceanbase-ce is stopped
SELECT svr_ip, svr_port, zone, status, stop_time FROM oceanbase.__all_server;
#加入集群
$ obd cluster start fgeduobce --components oceanbase-ce --servers 192.168.18.41
Get local repositories and plugins ok
Open ssh connection ok
Load cluster param plugin ok
Cluster status check ok
Check before start observer ok
Start observer ok
observer program health check ok
Connect to observer ok
succeed
$ obd cluster start fgeduobce --components obproxy --servers 192.168.18.41
Get local repositories and plugins ok
Open ssh connection ok
Load cluster param plugin ok
Cluster status check ok
Check before start obproxy ok
Start obproxy ok
obproxy program health check ok
Connect to obproxy ok
succeed

10.修改参数

#修改集群参数
obd cluster edit-config fgeduobce
obd cluster reload fgeduobce
-- 修改所有节点的 SQL 审计开关,立即生效并持久化
ALTER SYSTEM SET enable_sql_audit = False SCOPE = BOTH;
-- 只修改 192.168.18.41 节点的参数
ALTER SYSTEM SET syslog_level = 'DEBUG' SERVER = '192.168.18.41:2882';
-- 修改 zone1 内所有节点的参数
ALTER SYSTEM SET memory_limit = '16G' ZONE = 'zone1';
-- 在 sys 租户中修改指定租户的参数
ALTER SYSTEM SET ob_query_timeout = 30000000 TENANT = 'your_tenant_name';
-- 将参数重置为默认值
ALTER SYSTEM RESET parameter_name;
-- 查看指定参数的当前值
SHOW PARAMETERS LIKE 'syslog_level';



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15412087/viewspace-3115683/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: OceanBase 安装
下一篇: OceanBase分区表
请登录后发表评论 登录
全部评论

注册时间:2010-03-27

  • 博文量
    57
  • 访问量
    199173