国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

MySQL實(shí)踐——sys schema介紹及使用

這篇具有很好參考價(jià)值的文章主要介紹了MySQL實(shí)踐——sys schema介紹及使用。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

sys schema介紹
說(shuō)到診斷MySQL的性能問(wèn)題,都知道從performance_schema去獲取想要的數(shù)據(jù),但是其復(fù)雜程度讓使用人員使用起來(lái)很不方便。在MySQL5.7中,performance_schema已經(jīng)有80多張表,每張表都是各種統(tǒng)計(jì)信息的羅列。另外這些表和information_schema中的部分表也有關(guān)聯(lián),導(dǎo)致使用人員使用起來(lái)非常不便。
在MySQL5.7中新增了sys Schema。MySQL sys Schema是一個(gè)由一系列對(duì)象(視圖、存儲(chǔ)過(guò)程、存儲(chǔ)方法、表和觸發(fā)器)組成的database schema,它本身不采集和存儲(chǔ)什么信息,而是將performance_schema和information_schema中的數(shù)據(jù)以更容易理解的方式總結(jié)出來(lái)歸納為“視圖”。DBA和開發(fā)人員可以通過(guò)sys Schema方便、快速地讀取Performance Schema收集的數(shù)據(jù)。接下來(lái)看一下sys Schema的視圖中的數(shù)據(jù)是從哪里來(lái)的,如圖12.1所示,舉例說(shuō)明如下。

通過(guò)視圖定義可以看出,數(shù)據(jù)主要來(lái)源于information_schema中的COLUMNS和TABLES表。利用JOIN的方式連接查詢,然后進(jìn)行處理、過(guò)濾等,來(lái)展示實(shí)例中的自增量情況。sys Schema可用于典型的調(diào)優(yōu)和診斷用例,這些對(duì)象包括如下三個(gè)。

  • 將性能模式數(shù)據(jù)匯總到更易于理解的視圖。
  • 諸如性能模式配置和生成診斷報(bào)告等操作的存儲(chǔ)過(guò)程。
  • 用于查詢性能模式配置并提供格式化服務(wù)的存儲(chǔ)函數(shù)。

MySQL sys Schema默認(rèn)包含在MySQL5.7中,并提供摘要視圖以回答諸如下面所列的常見問(wèn)題。

  • 誰(shuí)占了數(shù)據(jù)庫(kù)服務(wù)的所有資源?
  • 哪些主機(jī)對(duì)數(shù)據(jù)庫(kù)服務(wù)器的訪問(wèn)量最大?
  • 實(shí)例上的內(nèi)存都去哪里了?
mysql> use sys;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show create table schema_auto_increment_columns\G
*************************** 1. row ***************************
                View: schema_auto_increment_columns
         Create View: CREATE ALGORITHM=MERGE DEFINER=`mysql.sys`@`localhost` SQL SECURITY INVOKER VIEW `schema_auto_increment_columns` AS select `information_schema`.`COLUMNS`.`TABLE_SCHEMA` AS `table_schema`,`information_schema`.`COLUMNS`.`TABLE_NAME` AS `table_name`,`information_schema`.`COLUMNS`.`COLUMN_NAME` AS `column_name`,`information_schema`.`COLUMNS`.`DATA_TYPE` AS `data_type`,`information_schema`.`COLUMNS`.`COLUMN_TYPE` AS `column_type`,(locate('unsigned',`information_schema`.`COLUMNS`.`COLUMN_TYPE`) = 0) AS `is_signed`,(locate('unsigned',`information_schema`.`COLUMNS`.`COLUMN_TYPE`) > 0) AS `is_unsigned`,((case `information_schema`.`COLUMNS`.`DATA_TYPE` when 'tinyint' then 255 when 'smallint' then 65535 when 'mediumint' then 16777215 when 'int' then 4294967295 when 'bigint' then 18446744073709551615 end) >> if((locate('unsigned',`information_schema`.`COLUMNS`.`COLUMN_TYPE`) > 0),0,1)) AS `max_value`,`information_schema`.`TABLES`.`AUTO_INCREMENT` AS `auto_increment`,(`information_schema`.`TABLES`.`AUTO_INCREMENT` / ((case `information_schema`.`COLUMNS`.`DATA_TYPE` when 'tinyint' then 255 when 'smallint' then 65535 when 'mediumint' then 16777215 when 'int' then 4294967295 when 'bigint' then 18446744073709551615 end) >> if((locate('unsigned',`information_schema`.`COLUMNS`.`COLUMN_TYPE`) > 0),0,1))) AS `auto_increment_ratio` from (`INFORMATION_SCHEMA`.`COLUMNS` join `INFORMATION_SCHEMA`.`TABLES` on(((`information_schema`.`COLUMNS`.`TABLE_SCHEMA` = `information_schema`.`TABLES`.`TABLE_SCHEMA`) and (`information_schema`.`COLUMNS`.`TABLE_NAME` = `information_schema`.`TABLES`.`TABLE_NAME`)))) where ((`information_schema`.`COLUMNS`.`TABLE_SCHEMA` not in ('mysql','sys','INFORMATION_SCHEMA','performance_schema')) and (`information_schema`.`TABLES`.`TABLE_TYPE` = 'BASE TABLE') and (`information_schema`.`COLUMNS`.`EXTRA` = 'auto_increment')) order by (`information_schema`.`TABLES`.`AUTO_INCREMENT` / ((case `information_schema`.`COLUMNS`.`DATA_TYPE` when 'tinyint' then 255 when 'smallint' then 65535 when 'mediumint' then 16777215 when 'int' then 4294967295 when 'bigint' then 18446744073709551615 end) >> if((locate('unsigned',`information_schema`.`COLUMNS`.`COLUMN_TYPE`) > 0),0,1))) desc,((case `information_schema`.`COLUMNS`.`DATA_TYPE` when 'tinyint' then 255 when 'smallint' then 65535 when 'mediumint' then 16777215 when 'int' then 4294967295 when 'bigint' then 18446744073709551615 end) >> if((locate('unsigned',`information_schema`.`COLUMNS`.`COLUMN_TYPE`) > 0),0,1))
character_set_client: utf8
collation_connection: utf8_general_ci
1 row in set (0.00 sec)

sys Schema視圖摘要

sys Schema中包含了很多以各種方式總結(jié)Performance Schema表的視圖。這些視圖大多數(shù)都是成對(duì)出現(xiàn),使得每組視圖中的一個(gè)成員具有與另一成員相同的名稱,加上一個(gè) x$ 前綴。例如,host_summary_by_file_io視圖匯總按主機(jī)分組的文件I/O及延遲。沒(méi)有 x$ 前綴的視圖提供了更加友好且容易閱讀的數(shù)據(jù),x$ 前綴的視圖提供了原始數(shù)據(jù),更多用于需要對(duì)數(shù)據(jù)進(jìn)行處理的其他工具。
視圖按照展示信息可以分為如下幾類。

  • 主機(jī)相關(guān)信息:以host_summary開頭的視圖,主要匯總了IO延遲的信息,從主機(jī)、文件事件類型、語(yǔ)句類型等角度展示文件IO的信息。
  • innodb相關(guān)信息:以innodb開頭的視圖,匯總了innodb buffer page信息和事務(wù)等待InnoDB鎖信息。
  • io使用情況:以io開頭的視圖,總結(jié)了io使用者的信息,包括等待I/O的情況、I/O使用量情況,從各個(gè)角度分組展示。
  • 內(nèi)存使用情況:以memory開頭的視圖,從主機(jī)、線程、用戶、事件角度展示內(nèi)存使用情況。
  • 連接與會(huì)話信息:其中,processlist和session相關(guān)的視圖,總結(jié)了會(huì)話相關(guān)信息。
  • 表相關(guān)信息:以schema_table開頭的視圖,從全表掃描、InnoDB緩沖池等方面展示了表統(tǒng)計(jì)信息。
  • 索引信息:其中包含index的視圖,統(tǒng)計(jì)了索引使用情況,以及重復(fù)索引和未使用的索引情況。
  • 語(yǔ)句相關(guān)信息:以statement開頭的視圖,統(tǒng)計(jì)的規(guī)范化后的語(yǔ)句使用情況,包括錯(cuò)誤數(shù)、警告數(shù)、執(zhí)行全表掃描的、使用臨時(shí)表、執(zhí)行排序等信息。
  • 用戶的相關(guān)信息:以u(píng)ser開頭的視圖,統(tǒng)計(jì)了用戶使用的文件IO、執(zhí)行的語(yǔ)句統(tǒng)計(jì)信息等。
  • 等待事件相關(guān)信息:以wait開頭的視圖,從主機(jī)和事件角度展示等待類事件的延遲情況。

查看表的訪問(wèn)量

在一般的運(yùn)維中,DBA維護(hù)了大量的數(shù)據(jù)庫(kù)。每個(gè)業(yè)務(wù)上線某些SQL也許不會(huì)通知DBA,突然間某個(gè)實(shí)例的QPS上升,DBA如何查看問(wèn)題并快速定位到底是哪個(gè)業(yè)務(wù)引起的QPS上升,或者說(shuō)業(yè)務(wù)方上線一個(gè)業(yè)務(wù),需要評(píng)估涉及的表訪問(wèn)量的增長(zhǎng)情況,這時(shí)該怎么辦? 在sys Schema中的schema_table_statistics視圖,可以幫助我們定位到表的訪問(wèn)量情況。

mysql>  SELECT table_schema, table_name, sum(io_read_requests+io_write_requests) FROM `schema_table_statistics`;
+--------------+------------------------+-----------------------------------------+
| table_schema | table_name             | sum(io_read_requests+io_write_requests) |
+--------------+------------------------+-----------------------------------------+
| info_collect | google_detail_tbsget_0 |                                  110572 |
+--------------+------------------------+-----------------------------------------+
1 row in set (0.13 sec)

我們可以監(jiān)控每張表訪問(wèn)量的變化情況,或者監(jiān)控某個(gè)庫(kù)的訪問(wèn)量變化等。如果某個(gè)庫(kù)、某個(gè)表發(fā)生變化,DBA能夠及時(shí)知道每個(gè)表的訪問(wèn)情況。

冗余索引與未使用的索引檢查

線上使用數(shù)據(jù)庫(kù)實(shí)例越來(lái)越多,每個(gè)表中都會(huì)創(chuàng)建索引,導(dǎo)致每個(gè)實(shí)例的索引非常多。一般都會(huì)有索引使用率很低或者是冗余索引的情況,這些索引是完全沒(méi)有必要建立的。它們不僅消耗磁盤空間,而且還影響數(shù)據(jù)庫(kù)的性能,DBA需要實(shí)時(shí)關(guān)注是否有該類索引的出現(xiàn),出現(xiàn)時(shí)需要立即處理。那么時(shí),sys Schema中的schema_redundant_indexes和schema_unused_indexes可以幫助我們快速查看索引情況。

tbs@localhost:[(none)]>select * from sys.schema_redundant_indexes \G
*************************** 1. row ***************************
              table_schema: dbt3
                table_name: a
      redundant_index_name: inx_a
   redundant_index_columns: a
redundant_index_non_unique: 1
       dominant_index_name: PRIMARY
    dominant_index_columns: a
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`a` DROP INDEX `inx_a`
*************************** 2. row ***************************
              table_schema: dbt3
                table_name: lineitem
      redundant_index_name: i_l_orderkey
   redundant_index_columns: l_orderkey
redundant_index_non_unique: 1
       dominant_index_name: i_l_orderkey_quantity
    dominant_index_columns: l_orderkey,l_quantity
 dominant_index_non_unique: 1
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`lineitem` DROP INDEX `i_l_orderkey`
*************************** 3. row ***************************
              table_schema: dbt3
                table_name: lineitem
      redundant_index_name: i_l_partkey
   redundant_index_columns: l_partkey
redundant_index_non_unique: 1
       dominant_index_name: i_l_suppkey_partkey
    dominant_index_columns: l_partkey,l_suppkey
 dominant_index_non_unique: 1
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`lineitem` DROP INDEX `i_l_partkey`
*************************** 4. row ***************************
              table_schema: dbt3
                table_name: lineitem
      redundant_index_name: i_l_orderkey
   redundant_index_columns: l_orderkey
redundant_index_non_unique: 1
       dominant_index_name: PRIMARY
    dominant_index_columns: l_orderkey,l_linenumber
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`lineitem` DROP INDEX `i_l_orderkey`
*************************** 5. row ***************************
              table_schema: dbt3
                table_name: orders
      redundant_index_name: idx_cust_date_status_80
   redundant_index_columns: o_custkey,o_orderDATE,o_orderstatus
redundant_index_non_unique: 1
       dominant_index_name: idx_a_b_c
    dominant_index_columns: o_custkey,o_orderDATE,o_orderstatus
 dominant_index_non_unique: 1
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`orders` DROP INDEX `idx_cust_date_status_80`
*************************** 6. row ***************************
              table_schema: dbt3
                table_name: orders
      redundant_index_name: i_o_custkey
   redundant_index_columns: o_custkey
redundant_index_non_unique: 1
       dominant_index_name: idx_a_b_c
    dominant_index_columns: o_custkey,o_orderDATE,o_orderstatus
 dominant_index_non_unique: 1
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`orders` DROP INDEX `i_o_custkey`
*************************** 7. row ***************************
              table_schema: dbt3
                table_name: orders
      redundant_index_name: i_o_custkey
   redundant_index_columns: o_custkey
redundant_index_non_unique: 1
       dominant_index_name: idx_cust_date_status_80
    dominant_index_columns: o_custkey,o_orderDATE,o_orderstatus
 dominant_index_non_unique: 1
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`orders` DROP INDEX `i_o_custkey`
*************************** 8. row ***************************
              table_schema: dbt3
                table_name: orders
      redundant_index_name: i_o_custkey
   redundant_index_columns: o_custkey
redundant_index_non_unique: 1
       dominant_index_name: inx_cust_date_status
    dominant_index_columns: o_custkey,o_orderdate2,o_orderstatus
 dominant_index_non_unique: 1
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`orders` DROP INDEX `i_o_custkey`
*************************** 9. row ***************************
              table_schema: dbt3
                table_name: partsupp
      redundant_index_name: i_ps_partkey
   redundant_index_columns: ps_partkey
redundant_index_non_unique: 1
       dominant_index_name: PRIMARY
    dominant_index_columns: ps_partkey,ps_suppkey
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`partsupp` DROP INDEX `i_ps_partkey`
*************************** 10. row ***************************
              table_schema: dbt3
                table_name: sougou
      redundant_index_name: cname
   redundant_index_columns: cname
redundant_index_non_unique: 1
       dominant_index_name: inx_dict_type
    dominant_index_columns: cname,dict_type
 dominant_index_non_unique: 1
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`sougou` DROP INDEX `cname`
*************************** 11. row ***************************
              table_schema: dbt3
                table_name: sougou
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dbt3`.`sougou` DROP INDEX `id`
*************************** 12. row ***************************
              table_schema: dpfm
                table_name: article_info
      redundant_index_name: periodical_id
   redundant_index_columns: article_id
redundant_index_non_unique: 1
       dominant_index_name: article_id
    dominant_index_columns: article_id
 dominant_index_non_unique: 1
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dpfm`.`article_info` DROP INDEX `periodical_id`
*************************** 13. row ***************************
              table_schema: dpfm
                table_name: operation_log
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dpfm`.`operation_log` DROP INDEX `id`
*************************** 14. row ***************************
              table_schema: dpfm
                table_name: operation_process
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dpfm`.`operation_process` DROP INDEX `id`
*************************** 15. row ***************************
              table_schema: dpfm
                table_name: operation_process_log
      redundant_index_name: task_id
   redundant_index_columns: task_id
redundant_index_non_unique: 1
       dominant_index_name: task_id_2
    dominant_index_columns: task_id,step_code
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dpfm`.`operation_process_log` DROP INDEX `task_id`
*************************** 16. row ***************************
              table_schema: dpfm
                table_name: operation_table
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dpfm`.`operation_table` DROP INDEX `id`
*************************** 17. row ***************************
              table_schema: dpfm
                table_name: operation_task
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dpfm`.`operation_task` DROP INDEX `id`
*************************** 18. row ***************************
              table_schema: dpfm
                table_name: operation_type
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dpfm`.`operation_type` DROP INDEX `id`
*************************** 19. row ***************************
              table_schema: dpfm
                table_name: task_chain_statistics
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `dpfm`.`task_chain_statistics` DROP INDEX `id`
*************************** 20. row ***************************
              table_schema: kmm
                table_name: attribute
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `kmm`.`attribute` DROP INDEX `id`
*************************** 21. row ***************************
              table_schema: kmm
                table_name: attribute_category
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `kmm`.`attribute_category` DROP INDEX `id`
*************************** 22. row ***************************
              table_schema: kmm
                table_name: attribute_tree
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `kmm`.`attribute_tree` DROP INDEX `id`
*************************** 23. row ***************************
              table_schema: kmm
                table_name: concept
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `kmm`.`concept` DROP INDEX `id`
*************************** 24. row ***************************
              table_schema: kmm
                table_name: concept_category
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `kmm`.`concept_category` DROP INDEX `id`
*************************** 25. row ***************************
              table_schema: kmm
                table_name: concept_tree
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `kmm`.`concept_tree` DROP INDEX `id`
*************************** 26. row ***************************
              table_schema: kmm
                table_name: neo4j_task
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `kmm`.`neo4j_task` DROP INDEX `id`
*************************** 27. row ***************************
              table_schema: kmm
                table_name: noumenon
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `kmm`.`noumenon` DROP INDEX `id`
*************************** 28. row ***************************
              table_schema: kmm
                table_name: noumenon_category
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `kmm`.`noumenon_category` DROP INDEX `id`
*************************** 29. row ***************************
              table_schema: tbsdrmt
                table_name: operation_log
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `tbsdrmt`.`operation_log` DROP INDEX `id`
*************************** 30. row ***************************
              table_schema: tbsrdps
                table_name: operation_log
      redundant_index_name: id
   redundant_index_columns: id
redundant_index_non_unique: 0
       dominant_index_name: PRIMARY
    dominant_index_columns: id
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `tbsrdps`.`operation_log` DROP INDEX `id`
30 rows in set, 2 warnings (0.82 sec)
tbs@localhost:[(none)]>select * from sys.schema_unused_indexes limit 0,1;
+---------------+-------------+------------+
| object_schema | object_name | index_name |
+---------------+-------------+------------+
| dbt3          | a           | inx_a      |
+---------------+-------------+------------+
1 row in set (0.10 sec)

針對(duì)冗余索引,DBA應(yīng)該及時(shí)清理掉。針對(duì)長(zhǎng)期未使用的索引,DBA應(yīng)該與使用方溝通是否以后有使用該索引的SQL語(yǔ)句等情況,如果沒(méi)有或暫時(shí)不使用的,可以刪除掉該索引,減少磁盤壓力,提高數(shù)據(jù)庫(kù)性能。

表自增ID監(jiān)控

隨著DBA維護(hù)的數(shù)據(jù)庫(kù)實(shí)例越來(lái)越多,表信息也越來(lái)越多,可能某張表自增量快要超過(guò)閾值了,繼而導(dǎo)致業(yè)務(wù)出現(xiàn)問(wèn)題。這時(shí)需要DBA清楚地知道每個(gè)表的增量列的情況。那么這時(shí)候如何查詢呢?以前都是分別去查詢每個(gè)表信息,或者通過(guò)INFROMATION SCHEMA來(lái)獲取信息。從MySQL5.7以后可以用sys Schema中的schema_auto_increment_columns視圖,就能很簡(jiǎn)單地查到每個(gè)表的自增量使用情況,甚至可以精確到某個(gè)表的自增量情況。

mysql> SELECT * FROM sys.schema_auto_increment_columns limit 0,2 \G
*************************** 1. row ***************************
        table_schema: gjts
          table_name: wenzhang_lingyu
         column_name: id
           data_type: tinyint
         column_type: tinyint(4)
           is_signed: 1
         is_unsigned: 0
           max_value: 127
      auto_increment: 29
auto_increment_ratio: 0.2283
*************************** 2. row ***************************
        table_schema: tbsdict
          table_name: language_type
         column_name: language_id
           data_type: tinyint
         column_type: tinyint(3)
           is_signed: 1
         is_unsigned: 0
           max_value: 127
      auto_increment: 29
auto_increment_ratio: 0.2283
2 rows in set, 10 warnings (3.75 sec)

在該視圖中,詳細(xì)地展示了表的自增量列名、數(shù)據(jù)類型、當(dāng)前使用量、最大值及使用率情況。極大地方便了DBA快速了解數(shù)據(jù)庫(kù)自增量的使用情況。甚至可以監(jiān)控該使用率,如果超過(guò)某個(gè)閾值,可以通過(guò)告警的方式自動(dòng)化的告知DBA某張表的自增量可能要出現(xiàn)問(wèn)題了,達(dá)到預(yù)警的作用,DBA可以快速處理這些問(wèn)題。

監(jiān)控全表掃描的SQL語(yǔ)句

線上數(shù)據(jù)庫(kù)每天跑的SQL語(yǔ)句會(huì)有很多,有部分SQL會(huì)由于未使用索引而導(dǎo)致全表掃描,這些SQL中的很大一部分會(huì)導(dǎo)致數(shù)據(jù)庫(kù)性能急劇下降,甚至?xí)?dǎo)致數(shù)據(jù)庫(kù)并發(fā)上升,從而使數(shù)據(jù)庫(kù)響應(yīng)變慢,直到夯住。這對(duì)DBA來(lái)說(shuō)是非??膳碌氖虑?。DBA需要盡早發(fā)現(xiàn)這些SQL,關(guān)注其是否可以優(yōu)化。那么在sys Schema的statements_with_full_table_scans視圖中,也許能夠幫助我們定位哪些SQL語(yǔ)句走了全表掃描。

mysql> SELECT * FROM sys.statements_with_full_table_scans where db ='gjts' limit 0,2\G
*************************** 1. row ***************************
                   query: SELECT COUNT (?) AS `num` FROM ...  WHERE ( ( `title` LIKE ? ) ) 
                      db: gjts
              exec_count: 21
           total_latency: 9.31 ms
     no_index_used_count: 21
no_good_index_used_count: 0
       no_index_used_pct: 100
               rows_sent: 21
           rows_examined: 609
           rows_sent_avg: 1
       rows_examined_avg: 29
              first_seen: 2023-08-01 08:04:07
               last_seen: 2023-08-01 11:32:53
                  digest: 5b59d502d9fdfe1d226ae87886a9a451
*************************** 2. row ***************************
                   query: SELECT * FROM `gjts` . `academic_papers` LIMIT ?, ... 
                      db: gjts
              exec_count: 1
           total_latency: 8.97 ms
     no_index_used_count: 1
no_good_index_used_count: 0
       no_index_used_pct: 100
               rows_sent: 708
           rows_examined: 708
           rows_sent_avg: 708
       rows_examined_avg: 708
              first_seen: 2023-08-01 10:23:43
               last_seen: 2023-08-01 10:23:43
                  digest: c7c69d6e9fba968ff2b839adf4342c72
2 rows in set (0.01 sec)

查看實(shí)例消耗的磁盤l/0

數(shù)據(jù)庫(kù)造成磁盤IO的消耗,對(duì)我們來(lái)說(shuō)是需要關(guān)心的。業(yè)務(wù)方經(jīng)常抱怨數(shù)據(jù)庫(kù)慢了,這時(shí)DBA需要關(guān)心數(shù)據(jù)庫(kù)到底慢在哪里?如果這時(shí)磁盤IO消耗過(guò)大,那么DBA需要知道在哪些數(shù)據(jù)庫(kù)文件上消耗了大量的磁盤IO。如果DBA能夠快速知道具體的文件消耗磁盤IO量,排查問(wèn)題時(shí)就會(huì)簡(jiǎn)單很多。這時(shí),sys Schema中的io_global_by_file_by_bytes視圖也許可以幫助我們定位一下問(wèn)題。

mysql> SELECT file, avg_read+avg_write as avg_io FROM io_global_by_file_by_bytes order by avg_io desc limit 10;
+-------------------------------------------------------+--------+
| file                                                  | avg_io |
+-------------------------------------------------------+--------+
| @@datadir/ebs_log/log20230801.frm                     |   1105 |
| @@datadir/sys/schema_tables_with_full_table_scans.frm |   1023 |
| @@datadir/jzqb/company_tudizhuanrang.frm              |   1019 |
| @@datadir/jzqb/company_xingzhengxukegongshangju.frm   |   1016 |
| @@datadir/kjdsj/baike.frm                             |   1015 |
| @@datadir/jzqb/company_gongsigongshi.frm              |   1015 |
| @@datadir/jzqb/company_gudongjichuzixinxi.frm         |   1015 |
| @@datadir/ctt/test_merge_data.frm                     |   1013 |
| @@datadir/gjts/books_yearbooks_1.frm                  |   1013 |
| @@datadir/jzqb/company_qianshuigonggao.frm            |   1013 |
+-------------------------------------------------------+--------+
10 rows in set (4.27 sec)

DBA可以通過(guò)該查詢來(lái)大致地了解磁盤IO消耗在哪里,哪些文件消耗的最多。DBA可以根據(jù)該信息,針對(duì)某些表、某些庫(kù)進(jìn)行針對(duì)性的優(yōu)化,提高數(shù)據(jù)庫(kù)性能。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-621238.html

到了這里,關(guān)于MySQL實(shí)踐——sys schema介紹及使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 實(shí)用數(shù)據(jù)庫(kù)開發(fā)實(shí)踐MySQL——數(shù)據(jù)模型

    實(shí)用數(shù)據(jù)庫(kù)開發(fā)實(shí)踐MySQL——數(shù)據(jù)模型

    目錄 第1關(guān) 關(guān)系模型 關(guān)系型數(shù)據(jù)模型 關(guān)系模型基本術(shù)語(yǔ) 關(guān)系模型的數(shù)據(jù)操縱與完整性約束 數(shù)據(jù)操縱 完整性約束 關(guān)系模型優(yōu)缺點(diǎn) 優(yōu)點(diǎn) 缺點(diǎn) 實(shí)驗(yàn) 頭歌實(shí)驗(yàn)代碼 第2關(guān) 層次模型 層次型數(shù)據(jù)模型 層次模型的數(shù)據(jù)操縱與完整性約束 數(shù)據(jù)操縱 完整性約束 層次模型優(yōu)缺點(diǎn) 優(yōu)點(diǎn) 缺

    2024年02月07日
    瀏覽(21)
  • 云數(shù)據(jù)庫(kù)MySQL多人協(xié)同開發(fā)實(shí)踐

    本文分享自天翼云開發(fā)者社區(qū)《云數(shù)據(jù)庫(kù)MySQL多人協(xié)同開發(fā)實(shí)踐》,作者:不知不覺(jué) 隨著云計(jì)算技術(shù)的快速發(fā)展,云數(shù)據(jù)庫(kù)作為云計(jì)算的重要組成部分,為企業(yè)提供了高效、靈活和可靠的數(shù)據(jù)存儲(chǔ)和管理服務(wù)。其中,MySQL作為一款流行的開源關(guān)系型數(shù)據(jù)庫(kù),在云數(shù)據(jù)庫(kù)領(lǐng)域具

    2024年02月04日
    瀏覽(29)
  • MySQL數(shù)據(jù)庫(kù)介紹流程(最新mysql)

    MySQL數(shù)據(jù)庫(kù)介紹流程(最新mysql)

    1、下載地址: http://dev,mysql.com/downloads/windows/installer/8.0html 2、就是直接搜索:mysql官方 ?msyql官方網(wǎng)站 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?這里就安裝成功 ? ? ? ? ? ? ? ?點(diǎn)擊鼠標(biāo)右鍵,點(diǎn)擊屬性 ? 沒(méi)有話在這里,搜索高級(jí)系統(tǒng)打開這個(gè) ? ? ? ? ? 安裝mysql找到文件 ? ? ? ?

    2024年02月13日
    瀏覽(32)
  • 【MySQL】MySQL 數(shù)據(jù)庫(kù)的介紹與操作

    【MySQL】MySQL 數(shù)據(jù)庫(kù)的介紹與操作

    目錄 1. 登錄 MySQL 數(shù)據(jù)庫(kù) 2. MySQL 介紹 3. 操作數(shù)據(jù)庫(kù) 1、創(chuàng)建數(shù)據(jù)庫(kù) 2、刪除數(shù)據(jù)庫(kù) 3、插入數(shù)據(jù) 4、查找 5、修改數(shù)據(jù)庫(kù) 4. 表的操作 1、創(chuàng)建表 2、查看表 3、修改表 4、刪除表 寫在最后: 指令: 這里我來(lái)介紹一下他的選項(xiàng),-h 表示指明登錄部署 MySQL 服務(wù)的主機(jī),-P 表示我們要

    2024年02月14日
    瀏覽(18)
  • mysql數(shù)據(jù)庫(kù)介紹

    mysql數(shù)據(jù)庫(kù)介紹

    ?? 今天對(duì)mysql的一些基礎(chǔ)概念進(jìn)行講誒橫掃,如概念、特點(diǎn)、優(yōu)勢(shì)、發(fā)展歷史等等。對(duì)之前內(nèi)容感興趣的同學(xué)可以參考??: 鏈接: mysql學(xué)習(xí)之?dāng)?shù)據(jù)系統(tǒng)概述 ?? 讓我們開始今日份的學(xué)習(xí)吧! 數(shù)據(jù)庫(kù)(database)就是一個(gè)存儲(chǔ)數(shù)據(jù)庫(kù)的倉(cāng)庫(kù),為了方便數(shù)據(jù)的存儲(chǔ)和管理,它將數(shù)據(jù)

    2024年01月23日
    瀏覽(29)
  • mysql 數(shù)據(jù)庫(kù)引擎介紹

    mysql 數(shù)據(jù)庫(kù)引擎介紹

    一、數(shù)據(jù)庫(kù)引擎 ? ? 數(shù)據(jù)庫(kù)引擎是用于存儲(chǔ)、處理和保護(hù)數(shù)據(jù)的核心服務(wù)。利用數(shù)據(jù)庫(kù)引擎可控制訪問(wèn)權(quán)限并快速處理事務(wù),從而滿足企業(yè)內(nèi)大多數(shù)需要處理大量數(shù)據(jù)的應(yīng)用程序的要求。 使用數(shù)據(jù)庫(kù)引擎創(chuàng)建用于聯(lián)機(jī)事務(wù)處理或聯(lián)機(jī)分析處理數(shù)據(jù)的關(guān)系數(shù)據(jù)庫(kù)。這包括創(chuàng)建

    2024年02月14日
    瀏覽(89)
  • mysql 數(shù)據(jù)庫(kù) 基本介紹

    mysql 數(shù)據(jù)庫(kù) 基本介紹

    描述事物的符號(hào)記錄 包括數(shù)字,文字、圖形、圖像、聲音、檔案記錄氣 以“記錄”形式按統(tǒng)一的格式進(jìn)行存儲(chǔ) 1,結(jié)構(gòu)化的數(shù)據(jù) 即有固定格式和有限長(zhǎng)度的數(shù)據(jù)。例如填的表格就是結(jié)構(gòu)化的數(shù)據(jù),國(guó)籍:中華人民共和國(guó),民族:漢,性別:男,這都叫結(jié)構(gòu)化數(shù)據(jù) 2,非結(jié)構(gòu)化

    2024年03月23日
    瀏覽(24)
  • 【數(shù)據(jù)庫(kù)遷移系列】從MySQL到openGauss的數(shù)據(jù)庫(kù)對(duì)象遷移實(shí)踐

    【數(shù)據(jù)庫(kù)遷移系列】從MySQL到openGauss的數(shù)據(jù)庫(kù)對(duì)象遷移實(shí)踐

    在之前這一篇中我們分享過(guò)使用chameleon工具完成MySQL到openGauss的全量數(shù)據(jù)復(fù)制、實(shí)時(shí)在線復(fù)制。9.30新發(fā)布的openGauss 3.1.0版本 ,工具的全量遷移和增量遷移的性能不但有了全面提升,而且支持?jǐn)?shù)據(jù)庫(kù)對(duì)象視圖、觸發(fā)器、自定義函數(shù)、存儲(chǔ)過(guò)程的遷移。 本篇就來(lái)分享一下使用c

    2024年02月02日
    瀏覽(38)
  • python+django+mysql項(xiàng)目實(shí)踐二(前端及數(shù)據(jù)庫(kù))

    python+django+mysql項(xiàng)目實(shí)踐二(前端及數(shù)據(jù)庫(kù))

    Pycharm 開發(fā)環(huán)境 Django 前端 MySQL 數(shù)據(jù)庫(kù) Navicat 數(shù)據(jù)庫(kù)管理 添加模板 在templates下創(chuàng)建 views文件中添加 在setting文件中進(jìn)行配置 在Terminal輸入命令下發(fā)指令

    2024年02月14日
    瀏覽(23)
  • Python數(shù)據(jù)庫(kù)編程全指南SQLite和MySQL實(shí)踐

    本文分享自華為云社區(qū)《Python數(shù)據(jù)庫(kù)編程全指南SQLite和MySQL實(shí)踐》,作者: 檸檬味擁抱。 首先,我們需要安裝Python的數(shù)據(jù)庫(kù)驅(qū)動(dòng)程序,以便與SQLite和MySQL進(jìn)行交互。對(duì)于SQLite,Python自帶了支持;而對(duì)于MySQL,我們需要安裝額外的庫(kù),如 mysql-connector-python 。 SQLite是一種輕量級(jí)的

    2024年03月28日
    瀏覽(38)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包