슬로우 쿼리 설정 방법

슬로우 쿼리 설정 방법

QA

슬로우 쿼리 설정 방법

본문

구글에서 슬로우 쿼리 설정 관련 글을 모두 보고 다 해봤는데 로그가 쌓이질 않습니다...

 

제 버전은 php7.3 centos7 마리아DB 10 입니다.

 

혹시 슬로우 쿼리 설치 방법에 대해 자세한 내용이 있는 사이트를 아시는 분 계실까요?

 

구글에서 CENTOS7 슬로우 쿼리 설정 방법 등등에 대한것들은 모두 해봤습니다..ㅠㅠ

 

그래도 로그가 쌓이질 않네요

 

MYSQL 등등 모두 리스타트 해놓았구요

이 질문에 댓글 쓰기 :

답변 2

다음 사항들을 확인해 보세요

 

my.cnf 파일 확인

다음과 같은 설정이 포함되어 있는지 확인해 보세요

포함되어 있지 않다면 추가


slow_query_log = 1
slow_query_log_file = /var/log/mariadb/slow_query.log
long_query_time = 2

 

로그 디렉토리 확인:

slow_query_log_file에 지정된 경로가 존재 여부 확인

 

슬로우 쿼리 로그를 강제로 생성


SET GLOBAL slow_query_log = 'ON';
SELECT SLEEP(3);

 

로그 파일 권한 확인, MariaDB 재시작, SELinux 확인, 로그 레벨 확인, 에러 로그 확인, 버전 호환성 확인

저 같은 경우는 마리아DB가 아니라 데이터 위치를 파악해보니
/var/log/mysql
입니다.

그렇다면 slow_query_log_file = /var/log/mariadb/slow_query.log

이부분을

slow_query_log_file = /var/log/mysql/slow_query.log

이렇게 변경해야 할까요?

그리고 slow_query.log 이 파일이 없다면 생성해주면 될까요?

SET GLOBAL slow_query_log = 'ON';
SELECT SLEEP(3);

이건 mysql -u root -p (나의 DB) 에 로그인후에 해주면 되는건가요?


기존것을 실행해서 보면

/usr/sbin/mysqld, Version: 10.3.39-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time     Id Command Argument
/usr/sbin/mysqld, Version: 10.3.39-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time     Id Command Argument


이렇게만 나오고 아무것도 로그가 쌓이질 않습니다.

네 맞습니다.

디렉토리 및 파일변경


slow_query_log_file = /var/log/mysql/slow_query.log


로그파일생성

설정 파일을 수정한 후에 로그 파일이 없다면  임의로 생성해 보세요

touch /var/log/mysql/slow_query.log


로그확인
파일을 확인하여 슬로우 쿼리 로그가 정상적으로 기록되었는지 확인 해보세요

cat /var/log/mysql/slow_query.log


마지막으로 에러 로그 확인 해보시면 될 것 같습니다.
로가 표시가 되어야 하는데 아무것도 표시가 되지 않다는 것은 설정에 오류가 있을 듯 하네요

/usr/sbin/mysqld, Version: 10.3.39-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time     Id Command Argument
/usr/sbin/mysqld, Version: 10.3.39-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time     Id Command Argument
/usr/sbin/mysqld, Version: 10.3.39-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time     Id Command Argument
/usr/sbin/mysqld, Version: 10.3.39-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time     Id Command Argument
/usr/sbin/mysqld, Version: 10.3.39-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time     Id Command Argument
/usr/sbin/mysqld, Version: 10.3.39-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time     Id Command Argument
/usr/sbin/mysqld, Version: 10.3.39-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time     Id Command Argument


이렇게 밖에 안나오고 아무런 로고가 쌓이질 않습니다...

일부러 지연되게도 해봤는데 안쌓이네요

재시작은 모두 해주었습니다..ㅠㅠ

TCP port 번호가 나와야 하고, Unix 소켓을 사용하는 경우라면 해당 소켓의 경로가 표시가 되어야 하는데 아무것도 표시가 되지 않다는 것은 설정에 오류가 있을 듯 하네요

설정에서 이부분 다시 검토해 보세요

추가로 레벨 설정도 확인해 보세요


[mysqld]
# 다른 설정...

# 로그 레벨 설정 (기본값은 Information)
log_error_verbosity=3

# 에러 로그 파일 경로 (원하는 경로로 수정)
log_error=/var/log/mysql/error.log

2023-11-28 20:57:59 0 [Note] Starting MariaDB 10.3.39-MariaDB-log source revision ca001cf2048f0152689e1895e2dc15486dd0b1af as process 19259
2023-11-28 20:57:59 0 [Note] InnoDB: Using Linux native AIO
2023-11-28 20:57:59 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-11-28 20:57:59 0 [Note] InnoDB: Uses event mutexes
2023-11-28 20:57:59 0 [Note] InnoDB: Compressed tables use zlib 1.2.7
2023-11-28 20:57:59 0 [Note] InnoDB: Number of pools: 1
2023-11-28 20:57:59 0 [Note] InnoDB: Using SSE2 crc32 instructions
2023-11-28 20:57:59 0 [Note] InnoDB: Initializing buffer pool, total size = 16G, instances = 8, chunk size = 128M
2023-11-28 20:58:00 0 [Note] InnoDB: Completed initialization of buffer pool
2023-11-28 20:58:00 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2023-11-28 20:58:00 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2023-11-28 20:58:00 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2023-11-28 20:58:00 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2023-11-28 20:58:00 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2023-11-28 20:58:00 0 [Note] InnoDB: Waiting for purge to start
2023-11-28 20:58:00 0 [Note] InnoDB: 10.3.39 started; log sequence number 254983305902; transaction id 367047077
2023-11-28 20:58:00 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2023-11-28 20:58:00 0 [Note] Plugin 'FEEDBACK' is disabled.
2023-11-28 20:58:00 0 [Note] Server socket created on IP: '::'.
2023-11-28 20:58:00 0 [Note] Reading of all Master_info entries succeeded
2023-11-28 20:58:00 0 [Note] Added new Master_info '' to hash table
2023-11-28 20:58:00 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.3.39-MariaDB-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
2023-11-28 20:58:01 0 [Note] InnoDB: Buffer pool(s) load completed at 231128 20:58:01

이렇게 나옵니다.

그리고 log_error_verbosity=3
이걸 넣으면 오류가 나오더라구요

그래서 log_error_verbosity=3 이부분은 빼고 리스타트 하였고 결과가 이렇게 나왔는데요

제가 이부분은 아예 모르다 보니 아예 감을 못잡겠습니다..ㅠㅠ

long_query_time = 2 2초면 슬로우쿼리 실행속도보다 저장할려는 속다가 작기때문에 넘어가버리죠 즉 
로그가 저장이 않될수 있습니다. 10초이상 늘려주세요
답변을 작성하시기 전에 로그인 해주세요.
전체 123,799 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT