网站做支付宝支付接口,做网站包括什么软件,网站建设国外,wordpress图片懒加载整理了一些在OceanBase使用过程中常用的SQL语句#xff0c;这些语句均适用于4.x版本#xff0c;并将持续进行更新。后续还将分享一些V4.x版本常用的操作指南#xff0c;以便更好地帮助大家使用OceanBase数据库。 集群信息
版本查看
show variables like version_comment; …整理了一些在OceanBase使用过程中常用的SQL语句这些语句均适用于4.x版本并将持续进行更新。后续还将分享一些V4.x版本常用的操作指南以便更好地帮助大家使用OceanBase数据库。 集群信息
版本查看
show variables like version_comment;
集群ID和集群名查看
show parameters like %cluster%;
当前服务器信息查看
select * from DBA_OB_SERVERS;
集群的zone信息查看
SELECT * FROM dba_ob_zones;
集群所支持的字符集列表查看
select * from information_schema.collations; 租户信息
查看租户创建基本信息
show create tenant xxx; 查看对应 Unit 的配置。
SELECT * FROM oceanbase.dba_ob_units; 查看租户对应的资源池可以加 tenant_id 筛选。
SELECT * FROM oceanbase.dba_ob_resource_pools; 查看租户基本信息。
SELECT * FROM oceanbase.dba_ob_tenants; 当前集群内的租户
select tenant_id,tenant_name,primary_zone,compatibility_mode from oceanbase.__all_tenant; RS 相关
切换rs leader
alter system switch rootservice leader zonez1; 查看 RS 任务
select * from __all_rootservice_event_history order by 1 desc limit 10; 查看 rs 列表
show parameters like %rootservice_list%; 查看 rs leaderWITH_ROOTSERVERyes
SELECT * FROM oceanbase.DBA_OB_SERVERS; 资源分配
资源分配查询
服务器资源分配
select * from GV$OB_SERVERS; 各租户资源分配
select t1.name resource_pool_name, t2.name unit_config_name,
t2.max_cpu, t2.min_cpu,
round(t2.memory_size/1024/1024/1024,2) mem_size_gb,
round(t2.log_disk_size/1024/1024/1024,2) log_disk_size_gb, t2.max_iops,
t2.min_iops, 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_idt2.unit_config_id)
join __all_unit t3 on (t1.resource_pool_id t3.resource_pool_id)
left join __all_tenant t4 on (t1.tenant_idt4.tenant_id)
order by t1.resource_pool_id, t2.unit_config_id, t3.unit_id; 查看 observer 内存、磁盘配置大小
select zone,svr_ip,svr_port,name,value
from __all_virtual_sys_parameter_stat
where
name in (memory_limit,memory_limit_percentage,system_memory,datafile_size,datafile_disk_percentage)
order by svr_ip,svr_port; 容量使用统计
默认情况下统计的是三/多副本的大小可以通过增加 role 来获取单副本大小。 统计租户的大小
select t.tenant_name,
round(sum(t2.data_size)/1024/1024/1024,2) as data_size_gb,
round(sum(t2.required_size)/1024/1024/1024,2) as required_size_gb
from dba_ob_tenants t,cdb_ob_table_locations t1,cdb_ob_tablet_replicas t2
where t.tenant_idt1.tenant_id
and t1.svr_ipt2.svr_ip
and t1.tenant_idt2.tenant_id
and t1.ls_idt2.ls_id
and t1.tablet_idt2.tablet_id
-- and t1.roleleader
group by t.tenant_name
order by 3 desc; 统计库的大小
select t1.database_name,
round(sum(t2.data_size)/1024/1024/1024,2) as data_size_gb,
round(sum(t2.required_size)/1024/1024/1024,2) as required_size_gb
from dba_ob_tenants t,cdb_ob_table_locations t1,cdb_ob_tablet_replicas t2
where t.tenant_idt1.tenant_id
and t1.svr_ipt2.svr_ip
and t1.tenant_idt2.tenant_id
and t1.ls_idt2.ls_id
and t1.tablet_idt2.tablet_id
-- and t1.roleleader
and t.tenant_nametest1
group by t1.database_name
order by 3 desc; 统计表/索引的大小
select t1.table_name,
round(sum(t2.data_size)/1024/1024/1024,2) as data_size_gb,
round(sum(t2.required_size)/1024/1024/1024,2) as required_size_gb
from dba_ob_tenants t,cdb_ob_table_locations t1,cdb_ob_tablet_replicas t2
where t.tenant_idt1.tenant_id
and t1.svr_ipt2.svr_ip
and t1.tenant_idt2.tenant_id
and t1.ls_idt2.ls_id
and t1.tablet_idt2.tablet_id
-- and t1.roleleader
and t.tenant_nametest1
and t1.database_namesbtest
and t1.table_namesbtest1
group by t1.table_name
order by 3 desc; 统计表对应的分区大小
select t1.table_name,t1.partition_name,
round(sum(t2.data_size)/1024/1024/1024,2) as data_size_gb,
round(sum(t2.required_size)/1024/1024/1024,2) as required_size_gb
from dba_ob_tenants t,cdb_ob_table_locations t1,cdb_ob_tablet_replicas t2
where t.tenant_idt1.tenant_id
and t1.svr_ipt2.svr_ip
and t1.tenant_idt2.tenant_id
and t1.ls_idt2.ls_id
and t1.tablet_idt2.tablet_id
and t1.roleleader
and t.tenant_nametest1
and t1.database_namesbtest
and t1.table_namesbtest1_part
group by t1.table_name,t1.partition_name; 内存占用
租户内存参数
show parameters where name in (memstore_limit_percentage,freeze_trigger_percentage); 租户内存持有
select TENANT_ID,SVR_IP,SVR_PORT,HOLD/1024/1024/1024,FREE/1024/1024/1024
from oceanbase.GV$OB_TENANT_MEMORY
where tenant_id 1002; 租户内存模块占用
select * from V$OB_MEMORY where tenant_id1002; memstore占用
select * from V$OB_MEMSTORE where tenant_id1002; 总体实际占用的memory 大小以及大小限制
select * from oceanbase.GV$OB_SERVERS;
memory_limit字段代表实际的memory_limit大小。
MEM_CAPACITY 是 memory_limit - system_memory
内存资源包括两个配置MIN_MEMORY和MAX_MEMORY他们含义如下 MIN_MEMORY表示为租户分配的最小内存规格observer上所有租户的MIN_MEMORY的总和不能超过物理可用内存大小MEM_CAPACITYMAX_MEMORY表示为租户分配的最大内存规格observer上所有租户的MAX_MEMORY的总和不能超过物理可用内存的超卖值MEM_CAPACITY * resource_hard_limit 表分区和日志流分布
表及分区
查看当前所有表详情
select * from __all_table 查看所有分区详情
select * from __all_part 查看表及分区leader分布
select * from oceanbase.DBA_OB_TABLE_LOCATIONS where ROLELEADER and table_namexxx 查看表及分区的预估数据量
select * from OCEANBASE.DBA_TAB_STATISTICS 日志流
日志流分布
select SVR_IP,ROLE,count(*) from CDB_OB_LS_LOCATIONS group by SVR_IP,ROLE; 查看日志流状态
select * from GV$OB_LOG_STAT; 查看日志流详情
select svr_ip,svr_port,tenant_id,ls_id,replica_type,ls_state,tablet_count from __all_virtual_ls_info; 常用hint
OceanBase Hint 用法
支持不带参数如 /* FUNC */支持带参数如 /* FUNC(param) */多个hint可以写到同一个注释中用逗号分隔如/* FUNC1, FUNC2(param) */SELECT语句的hint必须近接在关键字SELECT之后其他词之前。如SELECT /* FUNC */ …UPDATE, DELETE 语句的 hint 必须紧接在关键字 UPDATEDELETE 之后
Hint 参数
Hint 相关参数名称、语义和语法如下表所示。
名称语法语义NO_REWRITENO_REWRITE禁止 SQL 改写。READ_CONSISTENCYREAD_CONSISTENCY (WEAK[STRONGFROZEN])读一致性设置弱/强。INDEX_HINT/* INDEX(table_name index_name) */设置表索引。QUERY_TIMEOUTQUERY_TIMEOUT(INTNUM)设置超时时间。LOG_LEVELLOG_LEVEL([]log_level[])设置日志级别当设置模块级别语句时候以第一个单引号作为开始第二个单引号作为结束例如DEBUG。LEADINGLEADING([qb_name] TBL_NAME_LIST)设置联接顺序。ORDEREDORDERED设置按照 SQL 中的顺序进行联接。FULLFULL([qb_name] TBL_NAME)设置表访问路径为主表等价于 INDEX(TBL_NAME PRIMARY)。USE_PLAN_CACHEUSE_PLAN_CACHE(NONE[DEFAULT])设置是否使用计划缓存NONE表示不使用计划缓存。DEFAULT表示按照服务器本身的设置来决定是否使用计划缓存。USE_MERGEUSE_MERGE([qb_name] TBL_NAME_LIST)设置指定表在作为右表时使用 Merge Join。USE_HASHUSE_HASH([qb_name] TBL_NAME_LIST)设置指定表在作为右表时使用 Hash Join。NO_USE_HASHNO_USE_HASH([qb_name] TBL_NAME_LIST)设置指定表在作为右表时不使用 Hash Join。USE_NLUSE_NL([qb_name] TBL_NAME_LIST)设置指定表在作为右表时使用 Nested Loop Join。USE_BNLUSE_BNL([qb_name] TBL_NAME_LIST)设置指定表在作为右表时使用 Block Nested Loop JoinUSE_HASH_AGGREGATIONUSE_HASH_AGGREGATION([qb_name])设置聚合算法为 Hash。例如 Hash Group By 或者 Hash Distinct。NO_USE_HASH_AGGREGATIONNO_USE_HASH_AGGREGATION([qb_name])设置 Aggregate 方法不使用 Hash Aggregate使用 Merge Group By 或者 Merge Distinct。USE_LATE_MATERIALIZATIONUSE_LATE_MATERIALIZATION设置使用晚期物化。NO_USE_LATE_MATERIALIZATIONNO_USE_LATE_MATERIALIZATION设置不使用晚期物化。TRACE_LOGTRACE_LOG设置收集 Trace 记录用于 SHOW TRACE 展示。QB_NAMEQB_NAME( NAME )设置 Query Block 的名称。PARALLELPARALLEL(INTNUM)设置分布式执行并行度。TOPKTOPK(PRECISION MINIMUM_ROWS)设置模糊查询的精度和最小行数。 其中 PRECSION 为整型取值范围[0100]表示模糊查询的行数百分比MINIMUM_ROWS 为最小返回行数。 sql audit
查询资源占用最多的SQL
select SQL_ID, avg(ELAPSED_TIME),
avg(QUEUE_TIME),
avg(ROW_CACHE_HIT BLOOM_FILTER_CACHE_HIT BLOCK_CACHE_HIT DISK_READS) avg_logical_read,
avg(execute_time) avg_exec_time,
count(*) cnt,
avg(execute_time - TOTAL_WAIT_TIME_MICRO ) avg_cpu_time,
avg( TOTAL_WAIT_TIME_MICRO ) avg_wait_time,
WAIT_CLASS, avg(retry_cnt) from v$OB_SQL_AUDIT
group by 1
order by avg_exec_time * cnt desc
limit 10; 最近100s某个租户的TOP SQL耗时监控
select /*read_consistency(weak),query_timeout(100000000)*/ SQL_ID,count(1),avg(ELAPSED_TIME),avg(EXECUTE_TIME),avg(QUEUE_TIME),avg(AFFECTED_ROWS),avg(GET_PLAN_TIME)
from gv$ob_sql_audit
where time_to_usec(now(6))-request_time 1000000000
and tenant_nametest_tenant
group by SQL_ID order by avg(ELAPSED_TIME)*count(1) desc limit 20; 某个时间段请求次数排在 TOP-N 的 SQL
select SQL_ID, count(*) as QPS, avg(t1.elapsed_time) RT
from oceanbase.gv$ob_sql_audit t1
where tenant_id 1001 and IS_EXECUTOR_RPC 0
and request_time (time_to_usec(now()) - 10000000)
and request_time time_to_usec(now())
group by t1.sql_id order by QPS desc limit 10; 定位所有SQL中消耗CPU最多的sql(或者不做聚合直接查询)
select sql_id, substr(query_sql, 1, 200) as query_sql, sum(elapsed_time - queue_time) sum_t, count(*) cnt, avg(get_plan_time), avg(execute_time)
from oceanbase.gv$ob_sql_audit
where tenant_id 1001 and request_time (time_to_usec(now()) - 10000000) and request_time time_to_usec(now())
group by sql_id order by sum_t desc limit 10;巡检、运维相关
自增值
获取每张表的自增值下一个自增值
select a.table_name,b.AUTO_INCREMENT_VALUE
from oceanbase.__all_table a, oceanbase.DBA_OB_AUTO_INCREMENT b
where a.table_idb.AUTO_INCREMENT_KEY and a.autoinc_column_idb.COLUMN_ID and a.TABLE_NAMEt3; DDL
查询DDL进度
mysql select * from oceanbase.gv$session_longops\G;
sid现在没有填值为默认的 -1。trace_id: OBServer 程序日志的ID可以用该ID来搜索相关的日志文件。opname建索引时会展示 create index 信息。target建索引时展示正在创建的索引名。svr_ip: 调度任务在哪个 OBServer 执行。svr_port调度任务在哪个 OBServer 执行。start_time索引构建开始时间这里只精确到日期跟 Oracle 是兼容的。elapsed_seconds: 索引构建执行的时间单位为秒。time_remaining: 兼容 Oracle 的字段暂时还没有实现剩余时间预测的能力。last_update_time: 统计信息收集的时间也是精确到日期跟 Oracle 是兼容的。message里面包含了多个信息ENANT_ID为租户 IDTASK_ID为DDL 的任务 IDSTATUS 为 DDL 执行到的状态REPLICA BUILD 指的是数据补全阶段索引数据补全主要分为扫描主表数据排序写入到索引表阶段三个阶段处理的行数分别对应于ROW_SCANNED, ROW_SORTED 和 ROW_INSERTED因排序阶段可能会进行多轮归并所以ROW_SORTED 的行数通常比 ROW_SCANNED 和 ROW_INSERTED 要多。