Skip to content

Commit e923d93

Browse files
committed
Version 1.2.0
1 parent 586e77d commit e923d93

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Users, roles, profiles, quotas, grants:
5858
Tables:
5959
- Tables compress ratio;
6060
- Top tables by size;
61-
- Top tables MergeTree families by size;
61+
- Parts of tables MergeTree families;
6262
- Tables in memory (Memory engine);
6363
- Detached parts of MergeTree tables.
6464

@@ -71,7 +71,8 @@ Replication:
7171
- Mutations of MergeTree tables and their progress.
7272

7373
Queries:
74-
- Longest running queries.
74+
- Longest running queries;
75+
- Queries by memory consumption.
7576

7677
System activity (from system.metric_log table):
7778
- last 14 days;
@@ -99,13 +100,13 @@ Activity:
99100

100101
As user **root**, download the latest version of the scripts collection (see [Releases](https://github.com/Azmodey/ch_dba_scripts/releases) page):
101102
```
102-
# wget https://github.com/Azmodey/ch_dba_scripts/archive/1.1.0.tar.gz
103+
# wget https://github.com/Azmodey/ch_dba_scripts/archive/1.2.0.tar.gz
103104
```
104105

105106
Extract script files to separate directory (for example **~scripts/**) and grant the necessary execution rights:
106107
```
107-
# tar xvzf 1.1.0.tar.gz
108-
# mv ch_dba_scripts-1.1.0/scripts ~/scripts
108+
# tar xvzf 1.2.0.tar.gz
109+
# mv ch_dba_scripts-1.2.0/scripts ~/scripts
109110
# chmod 700 ~/scripts/*.sh
110111
```
111112

@@ -205,7 +206,7 @@ Users, roles, profiles, quotas, grants:
205206
Tables:
206207
- Tables compress ratio;
207208
- Top tables by size;
208-
- Top tables MergeTree families by size;
209+
- Parts of tables MergeTree families;
209210
- Tables in memory (Memory engine);
210211
- Detached parts of MergeTree tables.
211212

@@ -218,7 +219,8 @@ Replication:
218219
- Mutations of MergeTree tables and their progress.
219220

220221
Queries:
221-
- Longest running queries.
222+
- Longest running queries;
223+
- Queries by memory consumption.
222224

223225
System activity (from system.metric_log table):
224226
- last 14 days;

scripts/clickhouse_information.sh

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,28 +151,28 @@ SELECT database, table, count(*) AS parts,
151151
round((sum(data_compressed_bytes) / sum(data_uncompressed_bytes)) * 100., 2) AS percentage
152152
FROM system.parts WHERE active='1'
153153
GROUP BY database, table
154-
ORDER BY database, rows DESC
154+
ORDER BY rows DESC
155155
LIMIT 50 FORMAT PrettyCompact"
156156
echo
157157

158158
echo "Top tables by size:"
159159
clickhouse-client --query "
160-
SELECT database, name, engine, is_temporary, metadata_modification_time, storage_policy, total_rows, round(sum(total_bytes) / 1024/1024/1024, 2) as size_gb
160+
SELECT database, name, engine, storage_policy, total_rows as rows, formatReadableSize(sum(total_bytes)) as size, is_temporary, metadata_modification_time
161161
FROM system.tables
162-
WHERE database != 'system'
162+
--WHERE database != 'system'
163+
WHERE total_rows > 0
163164
GROUP BY database, name, engine, is_temporary, metadata_modification_time, storage_policy, total_rows, total_bytes
164-
ORDER BY database, total_bytes DESC
165-
LIMIT 10 FORMAT PrettyCompact"
165+
ORDER BY sum(total_bytes) DESC
166+
LIMIT 20 FORMAT PrettyCompact"
166167
echo
167168

168-
echo "Top tables MergeTree families by size:"
169+
echo "Parts of tables MergeTree families:"
169170
clickhouse-client --query "
170-
SELECT database, table, engine, disk_name, sum(rows) as rows, round(sum(bytes) / 1024/1024/1024, 2) as size_gb, countIf(active) data_parts_active, countIf(not active) data_parts_not_active
171+
SELECT database, table, engine, disk_name, countIf(active) data_parts_active, countIf(not active) data_parts_not_active
171172
FROM system.parts
172-
-- WHERE active
173173
GROUP BY database, table, engine, disk_name
174-
ORDER BY size_gb DESC
175-
LIMIT 10 FORMAT PrettyCompact"
174+
ORDER BY database, table DESC
175+
LIMIT 20 FORMAT PrettyCompact"
176176
echo
177177

178178
echo "Tables in memory (Memory engine):"
@@ -189,7 +189,6 @@ clickhouse-client --query "SELECT * FROM system.detached_parts ORDER BY database
189189
echo
190190

191191

192-
193192
echo -e "${CYANLIGHT}---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
194193

195194
echo "Replicated tables located on the local server:"
@@ -252,6 +251,28 @@ SELECT user,
252251
echo
253252

254253

254+
echo "Queries by memory consumption:"
255+
clickhouse-client --query "
256+
SELECT user,
257+
--client_hostname AS host,
258+
--client_name AS client,
259+
--formatDateTime(query_start_time, '%T') AS started,
260+
query_duration_ms / 1000 AS dur_sec,
261+
round(memory_usage / 1048576) AS mem_mb,
262+
result_rows,
263+
formatReadableSize(result_bytes) AS result_size,
264+
read_rows,
265+
formatReadableSize(read_bytes) AS read_size,
266+
written_rows as write_rows,
267+
formatReadableSize(written_bytes) AS write_size,
268+
query_id,
269+
substring(query,1,30) as query
270+
FROM system.query_log
271+
WHERE type = 2
272+
ORDER BY mem_mb DESC
273+
LIMIT 10 FORMAT PrettyCompact"
274+
echo
275+
255276

256277
echo -e "${CYANLIGHT}---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
257278

@@ -339,8 +360,8 @@ echo -e "${CYANLIGHT}-----------------------------------------------------------
339360

340361
echo "Queries that is being processed. Ordered by elapsed time:"
341362
echo "- full SQL text by query_id: SELECT distinct query FROM system.query_log WHERE query_id='' FORMAT TabSeparatedRaw"
342-
echo "- kill: KILL QUERY WHERE query_id='2-857d-4a57-9ee0-327da5d60a90'"
343-
echo "- kill: KILL QUERY WHERE user='username' SYNC"
363+
echo "- kill by query_id: KILL QUERY WHERE query_id=''"
364+
echo "- kill all queries by user: KILL QUERY WHERE user='' SYNC"
344365
clickhouse-client --query "SELECT elapsed as time_seconds, formatReadableSize(memory_usage) as memory, formatReadableSize(read_bytes) as read, read_rows, total_rows_approx as total_rows, user, address as client, query_id, substring(query,1,48) as query
345366
FROM system.processes
346367
ORDER BY elapsed desc FORMAT PrettyCompact"

0 commit comments

Comments
 (0)