当前位置:网站首页>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
- Log4j2
- From scratch, develop a web office suite (3): mouse events
- FastDateFormat为什么线程安全
- Depth filter of SvO2 series
- 求16以内正整数的阶乘,也就是n的阶层(0=<n<=16)。输入1111退出。
- Mish-撼动深度学习ReLU激活函数的新继任者
- Dynamic debugging of multi file program x32dbg
- Flesh-dect (media 2021) -- a viewpoint of material decomposition
- CDA data analysis -- Introduction and use of aarrr growth model
猜你喜欢
初始JDBC 编程
Read the Flink source code and join Alibaba cloud Flink group..
Sort---
YYGH-9-预约下单
刷题---二叉树--2
HR wonderful dividing line
ThreadLocal的简单理解
CDH存在隐患 : 该角色的进程使用的交换内存为xx兆字节。警告阈值:200字节
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
基于Arduino和ESP8266的连接手机热点实验(成功)
随机推荐
From scratch, develop a web office suite (3): mouse events
Small guide for rapid formation of manipulator (VII): description method of position and posture of manipulator
[geek challenge 2019] upload
Log4j2
倍增 LCA(最近公共祖先)
机械臂速成小指南(七):机械臂位姿的描述方法
(C语言)输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
深入理解PyTorch中的nn.Embedding
Brush questions --- binary tree --2
基于Arduino和ESP8266的Blink代码运行成功(包含错误分析)
SSH automatically disconnects (pretends to be dead) after a period of no operation
Input a three digit number and output its single digit, ten digit and hundred digit.
Jenkins用户权限管理
GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
Natural language processing series (II) -- building character level language model using RNN
PyTorch nn.RNN 参数全解析
Mish-撼动深度学习ReLU激活函数的新继任者
Mish shake the new successor of the deep learning relu activation function
Take you ten days to easily finish the finale of go micro services (distributed transactions)
BEAUTIFUL GGPLOT VENN DIAGRAM WITH R