문서번호 : 11-729498
Document Information
•
최초 작성일 : 2022.06.14
•
최종 수정일 : 2022.07.07
•
이 문서는 아래 버전을 기준으로 작성되었습니다.
◦
SinglestoreDB : 7.8
Goal
모니터링을 위한 SQL들을 모아 정리한다.
Solution
주의
본 문서는 참고용으로 작성된 것이며, 특히 발췌된 SQL은 작성일 이전의 것이므로, 현재 버전에 맞지 않을 수 있습니다.
1.
최근 쿼리 확인 (plancache 확인)
-- drop all from plancache; -- 필요시 누적된 plancache 삭제
SELECT last_executed, QUERY_TEXT FROM information_schema.PLANCACHE order by last_executed desc limit 40;
SQL
복사
2.
Cluster Usage
SELECT IP_ADDR, PORT, TYPE, NUM_CPUS, MAX_MEMORY_MB, MAX_TABLE_MEMORY_MB, MEMORY_USED_MB, TABLE_MEMORY_USED_MB, TOTAL_DATA_DISK_MB, AVAILABLE_DATA_DISK_MB, UPTIME, VERSION FROM INFORMATION_SCHEMA.MV_NODES ORDER BY TYPE DESC, PORT;
SQL
복사
3.
Database Usage
-- Columnstore table을 보유한 database만 DISK 용량 확인
SELECT DATABASE_NAME, SUM(COMPRESSED_SIZE) AS diskUsage FROM INFORMATION_SCHEMA.COLUMNAR_SEGMENTS GROUP BY DATABASE_NAME ORDER BY diskUsage DESC;
SQL
복사
4.
Columnstore table 상세 정보
-- 각 테이블별
SELECT DATABASE_NAME, TABLE_NAME, SUM(COMPRESSED_SIZE) AS compressedSize, SUM(UNCOMPRESSED_SIZE) AS uncompressedSize FROM INFORMATION_SCHEMA.COLUMNAR_SEGMENTS GROUP BY DATABASE_NAME, TABLE_NAME ORDER BY 1, 2;
-- 각 컬럼별
SELECT DATABASE_NAME, TABLE_NAME, COLUMN_NAME, SUM(COMPRESSED_SIZE) AS compressedSize, SUM(UNCOMPRESSED_SIZE) AS uncompressedSize FROM INFORMATION_SCHEMA.COLUMNAR_SEGMENTS GROUP BY DATABASE_NAME, TABLE_NAME, COLUMN_NAME ORDER BY 1, 2, 3;
SQL
복사
5.
Columnstore table 인덱스의 DISK 용량 확인
SELECT DATABASE_NAME, TABLE_NAME, INDEX_NAME, SUM(COMPRESSED_SIZE) AS totalSize FROM INFORMATION_SCHEMA.MV_COLUMNAR_SEGMENT_INDEX GROUP BY DATABASE_NAME, TABLE_NAME, INDEX_NAME;
SQL
복사
6.
Database 목록(파티션수, dr여부, replication sync/async 여부)
SELECT DATABASE_NAME, NUM_PARTITIONS, REMOTE_NAME != '' AS drReplica, IS_SYNC AS syncReplicated FROM INFORMATION_SCHEMA.DISTRIBUTED_DATABASES;
SQL
복사
7.
각 노드의 데이터베이스(파티션) 정보
SELECT HOST, PORT, DATABASE_NAME, ROLE, POSITION, STATE, DETAILS FROM INFORMATION_SCHEMA.MV_CLUSTER_STATUS;
SQL
복사
8.
파이프라인 상태
SELECT DATABASE_NAME, PIPELINE_NAME, sub.BATCH_STATE AS lastBatchState, FROM_UNIXTIME(sub.BATCH_START_UNIX_TIMESTAMP) AS lastBatchTimestamp, IFNULL(sub.BATCH_ROWS_WRITTEN, 0) AS lastBatchRowsWritten FROM ( SELECT DATABASE_NAME, PIPELINE_NAME, BATCH_STATE, BATCH_START_UNIX_TIMESTAMP, BATCH_ROWS_WRITTEN, ROW_NUMBER() OVER ( PARTITION BY DATABASE_NAME, PIPELINE_NAME ORDER BY BATCH_START_UNIX_TIMESTAMP DESC ) AS r FROM INFORMATION_SCHEMA.PIPELINES_BATCHES_METADATA) sub ORDER BY 1, 2, 4 DESC;
SQL
복사
9.
각 노드 정보 (+상태, 연결수)
SELECT HOST AS host, PORT AS port, AVAILABILITY_GROUP AS availabilityGroup, PAIR_HOST AS pairHost, PAIR_PORT AS pairPort, STATE AS state, OPENED_CONNECTIONS AS openedConnections, AVERAGE_ROUNDTRIP_LATENCY AS averageLatency FROM INFORMATION_SCHEMA.LEAVES;
SQL
복사
10.
파티션별 상태정보
SELECT HOST, PORT, DATABASE_NAME, ORDINAL, ROLE, IS_OFFLINE, STATE AS syncState FROM INFORMATION_SCHEMA.DISTRIBUTED_PARTITIONS ORDER BY 1, 3, 4, 5;
SQL
복사
11.
database 목록 (시스템 database 제외)
SELECT DATABASE_NAME AS databaseName FROM INFORMATION_SCHEMA.DISTRIBUTED_DATABASES;
SQL
복사
12.
인덱스별 상세정보 (+메모리 사용량)
SELECT TABLE_SCHEMA as databaseName, STATISTICS.TABLE_NAME, STATISTICS.INDEX_NAME, SUM(MEMORY_USE) AS memoryUse, INDEX_TYPE AS indexType, COLUMN_NAME, SEQ_IN_INDEX, ANY_VALUE(NON_UNIQUE) AS nonUnique
FROM information_schema.STATISTICS, information_schema.INDEX_STATISTICS
WHERE STATISTICS.TABLE_SCHEMA = INDEX_STATISTICS.DATABASE_NAME AND STATISTICS.TABLE_NAME = INDEX_STATISTICS.TABLE_NAME AND STATISTICS.INDEX_NAME = INDEX_STATISTICS.INDEX_NAME
GROUP BY STATISTICS.TABLE_SCHEMA, STATISTICS.TABLE_NAME, STATISTICS.INDEX_NAME, STATISTICS.COLUMN_NAME, STATISTICS.INDEX_TYPE ORDER BY 1, 2, 3, seq_in_index;
SQL
복사
13.
노드별 리소스 정보
SELECT NUM_CPUS, MAX_MEMORY_MB, MAX_TABLE_MEMORY_MB, MEMORY_USED_MB, TABLE_MEMORY_USED_MB, TOTAL_DATA_DISK_MB, AVAILABLE_DATA_DISK_MB, UPTIME, VERSION FROM INFORMATION_SCHEMA.LMV_NODES;
SELECT IP_ADDR, PORT, TYPE, NUM_CPUS, MAX_MEMORY_MB, MAX_TABLE_MEMORY_MB, MEMORY_USED_MB, TABLE_MEMORY_USED_MB, TOTAL_DATA_DISK_MB, AVAILABLE_DATA_DISK_MB, UPTIME, VERSION FROM INFORMATION_SCHEMA.MV_NODES ORDER BY TYPE DESC, PORT;
SQL
복사
14.
테이블별 상세정보 (table type, row count, memory use)
-- 주의) 모든 파티션 (Master/Slaver) 합산 : 클러스터 전체에 대한 현황
SELECT DATABASE_NAME, TABLE_NAME, STORAGE_TYPE, COUNT(*) AS numReplicas_or_Partitions, SUM(IFNULL(MEMORY_USE, 0)) AS memoryUse, SUM(CASE WHEN PARTITION_TYPE != '' THEN IFNULL(ROWS, 0) ELSE 0 END) AS rowCount FROM INFORMATION_SCHEMA.TABLE_STATISTICS WHERE `DATABASE_NAME` NOT IN ('') GROUP BY DATABASE_NAME, TABLE_NAME ORDER BY 1, 2;
-- 테이블 타입에 따른 row 계산 추가 예시
SELECT T.TABLE_NAME, T.STORAGE_TYPE, REPLACE(TS.PARTITION_TYPE, 'Master', '-') AS PARTITION_TYPE, TRUNC(SUM(TS.ROWS)/ (CASE TS.PARTITION_TYPE WHEN 'Reference' THEN COUNT(*) ELSE 1 END), 0) AS ROWS
FROM INFORMATION_SCHEMA.TABLES T
LEFT JOIN INFORMATION_SCHEMA.TABLE_STATISTICS TS
ON T.TABLE_SCHEMA = TS.DATABASE_NAME AND T.TABLE_NAME = TS.TABLE_NAME
WHERE T.TABLE_SCHEMA ='database_name'
AND T.TABLE_NAME LIKE 'table_%'
AND TS.PARTITION_TYPE <> 'Slave'
GROUP BY T.TABLE_NAME, T.STORAGE_TYPE, TS.PARTITION_TYPE
ORDER BY 1;
SQL
복사
15.
테이블별 Skew 지수 (rows > 10000 인 테이블)
SELECT
DATABASE_NAME,
TABLE_NAME,
FLOOR(AVG(ROWS)) AS avg_rows,
ROUND(STDDEV(ROWS)/AVG(ROWS),3) * 100 AS row_skew,
FLOOR(AVG(MEMORY_USE)) AS avg_memory,
ROUND(STDDEV(MEMORY_USE)/AVG(MEMORY_USE),3) * 100 AS memory_skew
FROM INFORMATION_SCHEMA.TABLE_STATISTICS
GROUP BY 1, 2
HAVING SUM(ROWS) > 10000
ORDER BY row_skew DESC;
-- 특정 테이블에 대한 상세 정보
SELECT
DATABASE_NAME,
TABLE_NAME,
ORDINAL AS PARTITION_ID,
ROWS,
MEMORY_USE
FROM INFORMATION_SCHEMA.
WHERE TABLE_NAME = 'domains';
-- 특정 테이블의 파티션별 rows 조회
SELECT PARTITION_ID(), COUNT(*) FROM domains GROUP BY 1;
SQL
복사
References
History
일자 | 작성자 | 비고 | |
2022.06.14 | kkh | 매뉴얼에서 발췌한 14종, studio 화면용 10종 정리 | |
2022.06.20 | kkh | 내용 분리 (studio 화면용.. 분리) | |
2022.07.04 | kkh | 2. 4. 13. 14. 번 쿼리 update | |
2022.07.07 | kkh | 제목 변경, 14번 쿼리 주석 추가 |