一、版本信息
language
select * from information_schema.GLOBAL_VARIABLES WHERE VARIABLE_NAME like 'version%';
二、集群状态
language
select * from oceanbase.v$ob_cluster;
三、服务器状态
检查所有服务器的状态,包括这个 Server 的 IP 地址和端口号,它隶属于哪个 zone,是否运行 root service 服务,以及当前状态等信息。
language
select * from oceanbase.__all_server;
四、集群资源分配
查看集群中的整体资源分配情况,
创建了租户后,管理员也需要看下整个资源池情况,已经用了多少,还剩多少等。根据这些情况,来给新租户分配资源,或者考虑扩容等。管理员可以查询"_all_virtual-server-stat"表来查询。
language
select
zone,
concat(svr_ip, ':', svr_port) as observer,
concat(cpu_assigned, ' : ', cpu_total) as cpu_summary,
concat(mem_assigned/(1024*1024*1024),' : ', mem_total/(1024*1024*1024)) as mem_summary_gb,
concat(disk_assigned/(1024*1024*1024),' : ', disk_total/(1024*1024*1024)) as disk_summary_gb,
cast(cpu_weight as decimal(5,2)) as c_weight,
cast(memory_weight as decimal(5,2)) as m_weight,
cast(disk_weight as decimal(5,2)) as d_weight,
unit_num
from oceanbase.__all_virtual_server_stat;
order by zone,observer;
五、resource unit规格
language
select * from oceanbase.__all_unit_config;
六、分配的resource unit
language
select * from oceanbase.__all_unit;
七、租户resource unit
将已经分配的resource unit和具体的租户对应起来
language
select * from oceanbase.__all_resource_pool;
八、memstore的使用情况
查看memstore的使用情况
language
select
tenant_name,
svr_ip,
memstore_limit/(1024*1024*1024) as memstore_limit,
major_freeze_trigger/(1024*1024*1024) as freeze_trigger_gb,
total_memstore_used/(1024*1024*1024) as memstore_used_gb,
concat((total_memstore_used*100/memstore_limit),'%') as memstore_used_percent,
active_memstore_used/(1024*1024*1024) as active_memstore_used_gb,
freeze_cnt
from oceanbase.__all_virtual_tenant_memstore_info memstore_info
inner join oceanbase.__all_tenant tenant
on memstore_info.tenant_id=tenant.tenant_id
where tenant.tenant_id > 1000
order by
tenant.tenant_name,svr_ip;
九、非memstore内存
查看非memstore内存分类情况,按租户区分
language
select
Zone ,
svr_ip,
case
when tenant.tenant_name is not null then tenant.tenant_name
else concat( 'tenant ', cast(memory_info.tenant_id as char(6)))
end as tenant_name,
sum(hold)/(1024*1024*1024) as hold_gb ,
sum(used)/(1024*1024*1024) as used_gb ,
(sum(used) / sum(hold))*100 as used_percent,
sum(alloc_count) as alloc_count,
sum(count) as used_count,
sum(free_count) as free_count
from oceanbase.__all_virtual_memory_info memory_info
left join oceanbase.__all_tenant tenant
on memory_info.tenant_id = tenant.tenant_id
group by zone,
svr_ip,
case
when tenant.tenant_name is not null then tenant.tenant_name
else concat( 'tenant ', cast(memory_info.tenant_id as char(6)))
end
order by 4 desc,zone,svr_ip
limit 30;
十、查看非memstore按租户和模块(mod_name)区分
查看非memstore内存分类情况,按租户和模块(mod_name)区分
language
select
Zone ,
svr_ip,
case
when tenant.tenant_name is not null then tenant.tenant_name
else concat( 'tenant ', cast(memory_info.tenant_id as char(6)))
end as tenant_name,
mod_name,
sum(hold)/(1024*1024*1024) as hold_gb ,
sum(used)/(1024*1024*1024) as used_gb ,
(sum(used) / sum(hold))*100 as used_percent,
sum(alloc_count) as alloc_count,
sum(count) as used_count,
sum(free_count) as free_count
from oceanbase.__all_virtual_memory_info memory_info
left join oceanbase.__all_tenant tenant
on memory_info.tenant_id = tenant.tenant_id
group by zone,
svr_ip,
case
when tenant.tenant_name is not null then tenant.tenant_name
else concat( 'tenant ', cast(memory_info.tenant_id as char(6)))
end,
mod_name
order by 5 desc,zone,svr_ip
limit 30;
十一、数据盘的使用情况
统计每台机器上数据盘的使用情况
language
select
svr_ip,
total_size/(1024*1024*1024) as total_gb,
(total_size - free_size)/(1024*1024*1024) as used_gb
from oceanbase.__all_virtual_disk_stat
order by svr_ip;
十二、zone数据盘的使用情况
language
select
zone,
sum(total_size)/(1024*1024*1024) as total_gb,
sum((total_size - free_size))/(1024*1024*1024) as used_gb
from oceanbase.__all_virtual_disk_stat disk_stat
inner join oceanbase.__all_server all_server
on disk_stat.svr_ip = all_server.svr_ip
group by zone
order by zone;
十三、集群合并状态
language
select * from oceanbase.__all_zone d where d.`name`='merge_status';
十四、所有租户
language
select * from oceanbase.__all_tenant;
十五、所有用户
language
select * from mysql.user;
十六、数据库基础信息
language
SELECT now() now_date,
USER() user, -- USER()、 SYSTEM_USER()、 SESSION_USER()、
CURRENT_USER() CURRENT_USER1,
CONNECTION_ID() CONNECTION_ID,
DATABASE() db_name, -- SCHEMA(),
version() Server_version,
-- ( SELECT @@tx_isolation ) tx_isolation, -- SELECT @@transaction_isolation tx_isolation
( SELECT @@autocommit ) autocommit,
( SELECT @@server_id ) server_id;
十七、数据库对象
language
select db as db_name ,type as ob_type,cnt as sums from
(select 'TABLE' type,table_schema db, count(*) cnt from information_schema.`TABLES` a where table_type='BASE TABLE' group by table_schema
-- union all
-- select 'EVENTS' type,event_schema db,count(*) cnt from information_schema.`EVENTS` b group by event_schema
union all
select 'TRIGGERS' type,trigger_schema db,count(*) cnt from information_schema.`TRIGGERS` c group by trigger_schema
union all
select 'PROCEDURE' type,routine_schema db,count(*) cnt from information_schema.ROUTINES d where`ROUTINE_TYPE` = 'PROCEDURE' group by db
union all
select 'FUNCTION' type,routine_schema db,count(*) cnt from information_schema.ROUTINES d where`ROUTINE_TYPE` = 'FUNCTION' group by db
union all
select 'VIEWS' type,TABLE_SCHEMA db,count(*) cnt from information_schema.VIEWS f group by table_schema ) t
order by db,type;
十八、当前连接到数据库的用户和Host
language
SELECT DISTINCT USER,HOST FROM `information_schema`.`PROCESSLIST` P WHERE P.USER NOT in ('repl','system user') limit 100;
十九、所有线程
language
select * from information_schema.`PROCESSLIST` a where a.command<>'Sleep' and a.id<>CONNECTION_id();
二十、sleep线程TOP20
language
select * from information_schema.`PROCESSLIST` a where a.command='Sleep' order by time desc limit 20;
二十一、最大的前10张大表
language
SELECT
table_schema AS db_name,
table_name AS table_name,
a.TABLE_TYPE,
a.`ENGINE`,
a.CREATE_TIME,
a.UPDATE_TIME,
a.TABLE_COLLATION,
table_rows AS table_rows,
TRUNCATE(a.DATA_LENGTH / 1024 / 1024, 2 ) AS tb_size_mb,
TRUNCATE( index_length / 1024 / 1024, 2 ) AS index_size_mb,
TRUNCATE( ( data_length + index_length ) / 1024 / 1024, 2 ) AS all_size_mb,
TRUNCATE( a.DATA_FREE / 1024 / 1024, 2 ) AS free_size_mb,
truncate(f.filesize_M,2) AS disk_size_mb
FROM information_schema.TABLES a
left outer join
(select substring(b.file_name,3,locate('/',b.file_name,3)-3) as db_name,
substring(b.file_name,locate('/',b.file_name,3)+1,(LENGTH(b.file_name)-locate('/',b.file_name,3)-4)) as tb_name,
b.file_name,
(total_extents*extent_size)/1024/1024 filesize_M
from information_schema.FILES b
order by filesize_M desc limit 20 ) f
on ( a.TABLE_SCHEMA= f.db_name and a.TABLE_NAME=f.tb_name )
ORDER BY ( data_length + index_length ) DESC
LIMIT 10;
二十二、所有字符集
language
select * from information_schema.CHARACTER_SETS;
二十三、重要的参数
language
select * from information_schema.GLOBAL_VARIABLES WHERE VARIABLE_NAME in ('datadir','SQL_MODE','socket','TIME_ZONE','tx_isolation','autocommit','innodb_lock_wait_timeout','max_connections','max_user_connections','slow_query_log','log_output','slow_query_log_file','long_query_time','log_queries_not_using_indexes','log_throttle_queries_not_using_indexes','log_throttle_queries_not_using_indexes','pid_file','log_error','lower_case_table_names','innodb_buffer_pool_size','innodb_flush_log_at_trx_commit','read_only', 'log_slave_updates','innodb_io_capacity','query_cache_type','query_cache_size','max_connect_errors','server_id','innodb_file_per_table')) V;
二十四、无主键或唯一键的表(前100条)
language
select table_schema, table_name
from information_schema.tables
where table_type='BASE TABLE'
and (table_schema, table_name) not in ( select /*+ subquery(materialization) */ a.TABLE_SCHEMA,a.TABLE_NAME
from information_schema.TABLE_CONSTRAINTS a
where a.CONSTRAINT_TYPE in ('PRIMARY KEY','UNIQUE')
and table_schema not in ('OceanBase', 'information_schema', 'sys', 'performance_schema') )
AND table_schema not in ('OceanBase', 'information_schema', 'sys', 'performance_schema')
limit 100;
二十五、自增ID的使用情况(前20条)
language
SELECT table_schema,table_name,engine, Auto_increment
FROM information_schema.tables a
where TABLE_SCHEMA not in ('OceanBase', 'information_schema', 'sys', 'performance_schema')
and a.Auto_increment<>''
order by a.AUTO_INCREMENT desc
limit 20;
二十六、所有数据库及其容量大小
language
select a.SCHEMA_NAME, a.DEFAULT_CHARACTER_SET_NAME,a.DEFAULT_COLLATION_NAME,
sum(table_rows) as table_rows,
truncate(sum(data_length)/1024/1024, 2) as data_size_mb,
truncate(sum(index_length)/1024/1024, 2) as index_size_mb,
truncate(sum(data_length+index_length)/1024/1024, 2) as all_size_mb,
truncate(sum(max_data_length)/1024/1024, 2) as max_size_mb,
truncate(sum(data_free)/1024/1024, 2) as free_size_mb,
max(f.filesize_M) as disk_size_mb
from INFORMATION_SCHEMA.SCHEMATA a
left outer join information_schema.tables b
on a.SCHEMA_NAME=b.TABLE_SCHEMA
left outer join
(select substring(b.file_name,3,locate('/',b.file_name,3)-3) as db_name,
truncate(sum(total_extents*extent_size)/1024/1024,2) filesize_M
from information_schema.FILES b
group by substring(b.file_name,3,locate('/',b.file_name,3)-3)) f
on ( a.SCHEMA_NAME= f.db_name)
group by a.SCHEMA_NAME, a.DEFAULT_CHARACTER_SET_NAME,a.DEFAULT_COLLATION_NAME
order by sum(data_length) desc, sum(index_length) desc;