OceanBase常用命令集合

1 资源管理

1.1 资源单元unit

#创建unit
CREATE RESOURCE UNIT unit1 max_cpu 1, max_memory '1G', max_iops 128,max_disk_size '10G', max_session_num 64, MIN_CPU=1, MIN_MEMORY='1G', MIN_IOPS=128;
#查看创建unit
MySQL [oceanbase]> select * from __all_unit_config\G
.......
*************************** 2. row ***************************gmt_create: 2021-09-17 10:43:21.476628gmt_modified: 2021-09-17 10:43:21.476628unit_config_id: 1003name: unit1   <=====max_cpu: 1min_cpu: 1max_memory: 1073741824min_memory: 1073741824max_iops: 128min_iops: 128max_disk_size: 10737418240
max_session_num: 64
2 rows in set (0.005 sec)

1.2 资源池pool

# 创建资源池pool 
CREATE RESOURCE POOL pool1 unit='unit1', unit_num=1, zone_list=('zone1','zone2','zone3');

#查看创建pool
MySQL [oceanbase]> select * from __all_resource_pool\G
.....
*************************** 2. row ***************************gmt_create: 2021-09-17 11:25:46.359917gmt_modified: 2021-09-17 11:25:46.359917resource_pool_id: 1002name: pool1unit_count: 1unit_config_id: 1003zone_list: zone1;zone2;zone3tenant_id: -1replica_type: 0
is_tenant_sys_pool: 0

#查看系统资源分布 资源池创建之后,系统会分配相应的资源
MySQL [oceanbase]> select * from __all_unit;
.....
*************************** 4. row ***************************gmt_create: 2021-09-17 11:25:46.367016gmt_modified: 2021-09-17 11:25:46.367016unit_id: 1004resource_pool_id: 1002group_id: 0zone: zone1svr_ip: 192.168.20.142svr_port: 2882migrate_from_svr_ip: 
migrate_from_svr_port: 0manual_migrate: 0status: ACTIVEreplica_type: 0
*************************** 5. row ***************************gmt_create: 2021-09-17 11:25:46.373779gmt_modified: 2021-09-17 11:25:46.373779unit_id: 1005resource_pool_id: 1002group_id: 0zone: zone2svr_ip: 192.168.20.143svr_port: 2882migrate_from_svr_ip: 
migrate_from_svr_port: 0manual_migrate: 0status: ACTIVEreplica_type: 0
*************************** 6. row ***************************gmt_create: 2021-09-17 11:25:46.377005gmt_modified: 2021-09-17 11:25:46.377005unit_id: 1006resource_pool_id: 1002group_id: 0zone: zone3svr_ip: 192.168.20.144svr_port: 2882migrate_from_svr_ip: 
migrate_from_svr_port: 0manual_migrate: 0status: ACTIVEreplica_type: 0
6 rows in set (0.002 sec)

1.3 租户tenant

#创建租户
CREATE TENANT IF NOT EXISTS test_tenant 
    charset='utf8mb4', 
    replica_num=3, 
    zone_list=('zone1','zone2','zone3'), 
    primary_zone='RANDOM', 
    resource_pool_list=('pool1')
    SET ob_tcp_invited_nodes='%'
;
#设置口令 mysql模式
[root@obcontrol ~]# obclient -h192.168.20.141 -uroot@test_tenant#ob_cluster -P2883 -A
MySQL [(none)]> set password=password('123456');

[root@obcontrol ~]# obclient -h192.168.20.141 -uroot@test_tenant#ob_cluster -P2883 -A -p
Enter password: 

#设置口令 oracle模式
[root@obcontrol ~]# obclient -h192.168.20.141 -usys@test_tenant#ob_cluster -P2883 -c --prompt "\u > "
SYS > alter user sys identified by oracle;

[root@obcontrol ~]# obclient -h192.168.20.141 -usys@test_tenant#ob_cluster -P2883 -c --prompt "\u > " -poracle
#查看创建租户
MySQL [oceanbase]> select * from __all_tenant\G
......
*************************** 2. row ***************************
                 gmt_create: 2021-09-17 13:40:01.450647
               gmt_modified: 2021-09-17 13:40:01.450647
                  tenant_id: 1002
                tenant_name: test_tenant
                replica_num: -1
                  zone_list: zone1;zone2;zone3
               primary_zone: RANDOM
                     locked: 0
             collation_type: 0
                       info: 
                  read_only: 0
      rewrite_merge_version: 0
                   locality: FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3
        logonly_replica_num: 0
          previous_locality: 
     storage_format_version: 0
storage_format_work_version: 0
      default_tablegroup_id: -1
         compatibility_mode: 0
           drop_tenant_time: -1
                     status: TENANT_STATUS_NORMAL
              in_recyclebin: 0
2 rows in set (0.002 sec)

1.4 observer资源使用

# 以observer维度查看
SELECT
    zone,
    concat(svr_ip, ':', svr_port) observer,
    cpu_total,
    cpu_assigned,
    cpu_assigned_percent,
    round(mem_total/1024/1024/1024) mem_total,
    round(mem_assigned/1024/1024/1024) mem_assigned,
    mem_assigned_percent,
    unit_Num,
  leader_count 
FROM
    __all_virtual_server_stat
ORDER BY
    zone,
    svr_ip;