当前位置:网站首页>MySQL与PostgreSQL抓取慢sql的方法
MySQL与PostgreSQL抓取慢sql的方法
2022-07-02 09:43:00 【alwaysonline819】
1. MySQL中抓取慢SQL
- 查看慢查询相关配置
show variables like '%quer%';
- slow_query_log: 表示是否开启慢查询日志
- slow_query_log_file: 指定慢查询日志存储在哪个日志文件中
- long_query_time: 表示多长时间的查询被认定为"慢查询"。默认值:10s
- log_queries_not_using_indexes: 表示如果运行的sql没有使用到索引,是否也被当做慢查询语句记录到慢查询日志中。
- log_throttle_queries_not_using_indexes:当log_queries_not_using_indexes设置为on时,该参数限制没有使用索引的查询语句每分钟记录到慢查询日志中的次数。
- 临时开启/关闭慢查询日志
set global slow_query_log = on
set global slow_query_log = off
- 查看慢查询日志
(1)刚开始使用慢查询,vi或cat命令还能使用,还能查询到,但是随着日志逐渐变多,查询起来可能会力不从心,这时就需要使用方式2
(2)MySQL内置的mysqldumpslow命令分析(具体使用方式可百度)
2. PostgreSQL抓取慢SQL
- 查看当前慢查询配置
show log_min_duration_statement;
- 在postgresql.conf中配置全局慢查询日志(毫秒)
log_min_duration_statement=10000;
- 慢查询日志位置存储
log_destination = 'csvlog' #开了这个后,下面log_filename指定的log后缀文件将不会有内容,全部在csv文件中
logging_collector = on
log_directory = 'pg_log' #当前目录下的pg_log文件夹
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
- 重新加载配置
select pg_reload_conf();
- 测试
begin TRANSACTION;
select pg_sleep(5);
select now() ;
END TRANSACTION;
- 查看csv文件,过滤duration字段
边栏推荐
- Leetcode14 longest public prefix
- How to Visualize Missing Data in R using a Heatmap
- uniapp uni-list-item @click,uniapp uni-list-item带参数跳转
- Orb-slam2 data sharing and transmission between different threads
- File operation (detailed!)
- [geek challenge 2019] upload
- Experiment of connecting mobile phone hotspot based on Arduino and esp8266 (successful)
- Log4j2
- Heap (priority queue)
- Differences between nodes and sharding in ES cluster
猜你喜欢
HOW TO ADD P-VALUES TO GGPLOT FACETS
ThreadLocal的简单理解
Take you ten days to easily finish the finale of go micro services (distributed transactions)
How to Easily Create Barplots with Error Bars in R
测试左移和右移
From scratch, develop a web office suite (3): mouse events
初始JDBC 编程
File operation (detailed!)
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
jenkins 凭证管理
随机推荐
子线程获取Request
Time format display
Leetcode topic [array] -540- single element in an ordered array
HOW TO ADD P-VALUES TO GGPLOT FACETS
(C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?
Gaode map test case
GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL
The blink code based on Arduino and esp8266 runs successfully (including error analysis)
CDH6之Sqoop添加数据库驱动
drools决策表的简单使用
Implementation of address book (file version)
5g era, learning audio and video development, a super hot audio and video advanced development and learning classic
Jenkins voucher management
[untitled] how to mount a hard disk in armbian
Flesh-dect (media 2021) -- a viewpoint of material decomposition
深入理解PyTorch中的nn.Embedding
Tas (file d'attente prioritaire)
Repeat, tile and repeat in pytorch_ The difference between interleave
浅谈sklearn中的数据预处理
全链路压测