暂无图片
暂无图片
3
暂无图片
暂无图片
暂无图片

GBase 8a GDCA认证之系统表

原创 丽芳 2021-07-11
2076

       系统数据库在每个gcluster节点、gnode节点上都存在,系统表所查询的信息大多是本地信息。

一、information_schema库

       库内表为系统视图(MEMORY引擎表,只读),用于获取元数据信息,如库或表的名称、列的数据类型、访问权限、数据加载结果集状态信息、资源信息等。包括TABLES、COLUMNS、VIEWS、PROCESSLIST、GLOBAL_VARIABLES等。

  • 查询VC虚拟集群

select * from information_schema.vc;
或者
show vcs;

  • 查询数据库

select schema_name from information_schema.schemata;
或者
show databases;

  • 查询某个库的所有表和视图

select table_name,table_type from information_schema.tables where table_schema=‘test’;
或者
show tables from test like ‘t%’; --非临时表

  • 查询某个表中的列

select column_name,data_type,is_nullable,column_default from information_schema.columns where table_name = ‘customer’ and table_schema=‘ssbm’;
或者
show columns from test.t;
或者
desc test.t;

  • 查询存储过程和自定义函数

select routine_schema,routine_name,routine_type from information_schema.routines;
或者
show create procedure p_demo;

  • 查询索引信息

select table_name,index_name,seq_in_index,column_name,index_type from information_schema.statistics where table_schema=‘ssbm’;
或者
show index from test.t;

  • 查看test的建表语句

show create table test.t;

  • 判断分布表数据分布是否倾斜
    注:cluster_table_segments:记录每个分片的数据占用磁盘空间信息

select * from information_schema.cluster_table_segments where table_schema=‘库名’ and table_name =‘表名’;

  • 显示8a集群的系统变量值

select * from information_schema.global_variables where variable_name like ‘pattern’;
show variables [like ‘pattern’];

  • 设置系统变量值
    global全局变量值改变,只对新的session会话起作用
    session默认为会话变量,可不写

set [global|session] = value

  • 查询8a集群的默认压缩模式信息

show global variables like ‘%compress%’;
select * from information_schema.global_variables where variable_name like ‘%compress%’;

  • 查询当前节点正在运行的线程信息

show [full] processlist; --可以查看正在运行的线程
select id,user,host,db,command,time,state,info from information_schema.processlist;

二、performance_schema库

       库内表为系统视图(MEMORY引擎表,只读),用于监控数据库本地运行时的信息,包括运行状态信息、磁盘、内存使用情况等。包括DISK_USAGE_INFO、CLUTER_DISK_USAGE_INFO、TABLES、HEAP_USAGE_INFO、MEMORY_USAGE_INFO等。

  • 查询当前节点gcluster层磁盘空间使用信息

select * from performance_schema.DISK_USAGE_INFO;

  • 查询集群某节点的gcluster层和gnode层磁盘空间使用信息

select * from performance_schema.CLUSTER_DISK_USAGE_INFO where host=‘vm1’;

  • 查询表总条数
    table_row:为表所有分片的条数和,当表分片有一个副本时,时表条数的2倍;当表分片有两个副本时,时表条数的3倍。

select count(*) from 表名;
select table_schema,table_name,table_rows/2,storage_size/2 from performance_schema.tables where table_schema=‘库名’ and table_name = ‘表名’;

三、gbase库

       库内系统表为GsSYS引擎表,存储用户及权限、审计日志、函数/存储过程、UDF及引擎插件等信息。包括user、role_edges、table_distribution、audit_log、Nodedatamap等。

  • 查询数据库中的用户

select user from gbase.user;

  • 查询数据库的用户与用户组role的关联关系

select * from gbase.role_edges \G

  • 如何查看表或表类型

select dbname,tbname,isreplicate,hash_column from gbase.table_distribution where dbname=‘库名’ and tbname like ‘表名’;
show create table 表名;

四、gclusterdb库

       库内系统表为express引擎表,与普通表是同一种引擎,主要为dual、数据重分布、kafka-consumer流处理、temporary临时表对应的物理映射表等系统表。包括dual、rebalancing_status等。

  • 终止正在运行的线程(SQL语句)
    connection参数:用于终止指定的thread_id,默认参数。
    query参数:中止连接当前执行的语句,但是不中止该连接本身。

kill [connection|query] thread_id;

  • 暂停正在运行的线程

pause thread_id;

  • 继续已暂停的线程

continue thread_id;

  • 显示最后一条警告或错误信息

show warnings; --显示由最后一个语句产生的错误,警告和注意信息
show errors; --显示由最后一个语句产生的错误信息

  • 显示集群节点信息

show nodes; --如果有super权限,可以看到所有节点信息
show local node; --显示集群中客户端正在访问节点的信息

  • 使用系统函数,查看当前系统信息
    • 返回当前8a系统版本:version()
    • 返回当前VC名字:vc()
    • 返回当前数据库名字:database()
    • 返回当前用户名:user()
    • 返回字符串参数使用的字符集:charset(str)
  • 使用use切换当前VC/数据库
    • 切换到vc1虚拟集群:use vc vc1;
    • 切换到test数据库:use test;
最后修改时间:2021-07-11 00:43:44
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论