-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhealth-check.sql
1389 lines (1328 loc) · 50.2 KB
/
health-check.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- RedShift HealthCheck ToolKit
-- Version 1.0
-- Developed by Searce Data team
-- Updates: https://thedataguy.in/
-- Disable cache for this session
SET enable_result_cache_for_session = OFF;
-- Drop the temp table for storing the checklist results
DROP TABLE IF EXISTS rstk_metric_result;
-- Create temp table for storing the checklist results
create temp table rstk_metric_result
(
priority int,
category varchar(50),
finding varchar(300),
details varchar(65000),
url varchar(300),
value varchar(1000),
checkid int
);
-- Insert information row
INSERT INTO rstk_metric_result
VALUES (0,
current_timestamp,
'RedShift HealthCheck ToolKit',
'To get help or add you own contribution join us at https://github.com/BhuviTheDataGuy/RedShift-ToolKit',
'https://thedataguy.in',
NULL,
NULL);
-- Tables without sort keys
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 1,
'Design',
'Tables without sort key',
'https://thedataguy.in/rskit/sortkeys',
Count(*)
FROM pg_catalog.svv_table_info
WHERE sortkey1 IS NULL
AND "schema" not like 'pg_temp%';
-- Sort key column compressed
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 2,
'Design',
'Sort key column compressed',
'https://thedataguy.in/rskit/sortkeycompress',
Count(*)
FROM pg_catalog.svv_table_info
WHERE sortkey1 IS NOT NULL
AND sortkey1_enc <> 'none'
AND "schema" not like 'pg_temp%';
-- Sort key skew > 4
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 3,
'Design',
'Sort key skew',
'https://thedataguy.in/rskit/sortkeyskew',
Count(*)
FROM svv_table_info
WHERE sortkey1 IS NOT NULL
AND skew_sortkey1 > 4
AND "schema" not like 'pg_temp%';
-- Tables with high Skew
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 4,
'Design',
'Tables with high Skew',
'https://thedataguy.in/rskit/tableskew',
Count(*)
FROM svv_table_info
WHERE diststyle LIKE 'KEY%'
AND skew_rows > 3
AND "schema" not like 'pg_temp%';
-- Tables without compression
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 5,
'Design',
'Tables without compression',
'https://thedataguy.in/rskit/tablecompress',
Count(*)
FROM pg_catalog.svv_table_info
WHERE encoded <> 'Y'
AND "schema" not like 'pg_temp%';
-- WLM queue wait time > 1min
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 6,
'WLM',
'WLM queue wait time',
'https://thedataguy.in/rskit/queuewait',
Count(*)
FROM stl_wlm_query w
WHERE w.total_queue_time / 1000000 > 60;
-- WLM max connection hit
-- Credit: This query is taken from AWS RedShit Utilities with some changes to boost up performance on single node cluster.
-- Script name: wlm_apex_hourly
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
WITH generate_dt_series AS
(
SELECT SYSDATE - (n * interval '1 minute') AS dt
FROM (
SELECT row_number() over () AS n
FROM stl_scan limit 10080)), apex AS
(
SELECT iq.dt,
iq.service_class,
iq.num_query_tasks,
count(iq.slot_count) AS service_class_queries,
SUM(iq.slot_count) AS service_class_slots
FROM (
SELECT gds.dt,
wq.service_class,
wscc.num_query_tasks,
wq.slot_count
FROM stl_wlm_query wq
join stv_wlm_service_class_config wscc
ON (
wscc.service_class = wq.service_class
AND wscc.service_class > 4)
join generate_dt_series gds
ON (
wq.service_class_start_time <= gds.dt
AND wq.service_class_end_time > gds.dt)
WHERE wq.userid > 1
AND wq.service_class > 4) iq
GROUP BY iq.dt,
iq.service_class,
iq.num_query_tasks), maxes AS
(
SELECT apex.service_class,
trunc(apex.dt) AS d,
date_part(h,apex.dt) AS dt_h,
max(service_class_slots) max_service_class_slots
FROM apex
GROUP BY apex.service_class,
apex.dt,
date_part(h,apex.dt)) , final_result AS
(
SELECT apex.service_class,
apex.num_query_tasks AS max_wlm_concurrency,
maxes.d AS day,
maxes.dt_h
|| ':00 - '
|| maxes.dt_h
|| ':59' AS hour,
max(apex.service_class_slots) AS max_service_class_slots
FROM apex
join maxes
ON (
apex.service_class = maxes.service_class
AND apex.service_class_slots = maxes.max_service_class_slots)
GROUP BY apex.service_class,
apex.num_query_tasks,
maxes.d,
maxes.dt_h
ORDER BY apex.service_class,
maxes.d,
maxes.dt_h)
SELECT 7,
'WLM',
'WLM max connection hit',
'https://thedataguy.in/rskit/highconnection',
max(max_service_class_slots) AS maxv
FROM final_result
WHERE service_class >=6;
-- Number of WLM queue
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 8,
'WLM',
'Number of WLM queue',
'https://thedataguy.in/rskit/queue',
Count(*)
FROM stv_wlm_service_class_config
WHERE service_class BETWEEN 6 and 13;
-- Auto WLM enabled
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 9,
'WLM',
'Auto WLM enabled',
'https://thedataguy.in/rskit/autowlm',
Count(*)
FROM stv_wlm_service_class_config
WHERE service_class >= 100;
-- Max concurrency for a slot
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 10,
'WLM',
'Max concurrency for a slot',
'https://thedataguy.in/rskit/concurrencyslot',
Max(num_query_tasks)
FROM stv_wlm_service_class_config
WHERE service_class BETWEEN 6 AND 13;
-- WLM commit queue wait
INSERT INTO rstk_metric_result
(
checkid,
category,
finding,
url,
value
)
SELECT 11,
'WLM',
'WLM commit queue wait',
'https://thedataguy.in/rskit/commitqueue',
Max(queue_time)
FROM (SELECT Datediff(seconds, startqueue, startwork) AS queue_time
FROM stl_commit_stats
WHERE startqueue >= Dateadd(day, -7, current_date)
ORDER BY queue_time DESC);
-- Ghost rows
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
WITH raw_gh AS
(
SELECT query,
tbl,
perm_table_name ,
segment,
SUM(a.rows_pre_filter-a.rows_pre_user_filter)AS ghrows
FROM stl_scan a
WHERE a.starttime > current_timestamp - interval '5 days'
and perm_table_name NOT IN ('Internal Worktable',
'S3')
AND is_rlf_scan = 'f'
AND (
a.rows_pre_filter <> 0
AND a.rows_pre_user_filter <> 0 )
GROUP BY SEGMENT,
query,
tbl,
perm_table_name ), ran AS
(
SELECT *,
dense_rank() over (PARTITION BY tbl ORDER BY query DESC, SEGMENT DESC) AS rnk
FROM raw_gh ), final_cte AS
(
SELECT max(query),
SUM(ghrows)AS ghrows
FROM ran
WHERE rnk = 1
GROUP BY tbl)
SELECT 12,
'Vacuum',
'Ghost rows',
'https://thedataguy.in/rskit/ghostrows',
SUM(ghrows)
FROM final_cte;
-- Tables never performed vacuum (based on STL_Vacuum)
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 13,
'Vacuum',
'Tables never performed vacuum',
'https://thedataguy.in/rskit/vacuum',
count(*)
FROM pg_catalog.svv_table_info
WHERE table_id NOT IN (SELECT table_id
FROM stl_vacuum);
-- Table vacuum older than 5 days
INSERT INTO rstk_metric_result
(
checkid,
category,
finding,
url,
value
)
WITH cte AS
(
SELECT table_id,
Max(eventtime)AS eventtime1
FROM stl_vacuum
WHERE status LIKE '%Finished%'
GROUP BY table_id
)
SELECT 14,
'Vacuum',
'Table vacuum older than 5 days',
'https://thedataguy.in/rskit/vacuum',
Count(*)
FROM pg_catalog.svv_table_info
join cte
ON svv_table_info.table_id= cte.table_id
WHERE cte.eventtime1>= current_date - interval '5 day';
-- Tables with tombstone blocks
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
WITH cte
AS (SELECT Trim(name) AS tablename,
Count(CASE
WHEN tombstone > 0 THEN 1
ELSE NULL
END) AS tombstones
FROM svv_diskusage
GROUP BY 1
HAVING Count(CASE
WHEN tombstone > 0 THEN 1
ELSE NULL
END) > 0
ORDER BY 2 DESC)
SELECT 15,
'Vacuum',
'Tables with tombstone blocks',
'https://thedataguy.in/rskit/tombstone',
Count(tablename)
FROM cte;
-- Tables with missing stats
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 16,
'Vacuum',
'Tables with missing stats',
'https://thedataguy.in/rskit/stats',
Count(*)
FROM (SELECT plannode
FROM stl_explain
WHERE plannode LIKE '%missing statistics%'
AND plannode NOT LIKE '%redshift_auto_health_check_%'
GROUP BY plannode);
-- Tables with stale stats (> 5 percent)
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 17,
'Vacuum',
'Tables with stale stats',
'https://thedataguy.in/rskit/stats',
Count(*)
FROM svv_table_info
WHERE stats_off > 5;
-- Top sized tables
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 18,
'Table',
'Top sized tables',
'https://thedataguy.in/rskit/specturm',
Count(*)
FROM pg_catalog.svv_table_info
WHERE pct_used >= 40;
-- Table with high number of alerts (>3 alerts)
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 19,
'Table',
'Tables with high number of alerts',
'https://thedataguy.in/rskit/alert',
Count("table")
FROM (SELECT "table",
Count(*) AS count
FROM (SELECT Trim(s.perm_table_name) AS table,
Trim(Split_part(l.event, ':', 1)) AS event
FROM stl_alert_event_log AS l
left join stl_scan AS s
ON s.query = l.query
AND s.slice = l.slice
AND s.segment = l.segment
WHERE l.userid > 1
AND l.event_time >= Dateadd(day, -7, Getdate())
AND s.perm_table_name NOT LIKE 'volt_tt%'
AND s.perm_table_name NOT LIKE 'Internal Worktable'
GROUP BY 1,
2)
GROUP BY 1)
WHERE count >= 3;
-- Non scaned Tables (based on STL Scan)
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 20,
'Table',
'Non scaned Tables',
'https://thedataguy.in/rskit/unusedtable',
Count(*)
FROM pg_catalog.svv_table_info
WHERE "table" NOT IN (SELECT DISTINCT ( perm_table_name )
FROM pg_catalog.stl_scan);
-- Tables without backup
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 21,
'Table',
'Tables without backup',
'https://thedataguy.in/rskit/nobackup',
Count(*)
FROM stv_tbl_perm
WHERE BACKUP = 0 and temp=0;
-- Tables with fragmentation
-- Credit: This query is taken from AWS RedShit Utilities
-- Script name: v_fragmentation_info.sql
INSERT INTO rstk_metric_result
(
checkid,
category,
finding,
url,
value
)
SELECT 22,
'Table',
'Tables with fragmentation',
'https://thedataguy.in/rskit/fragmentation',
Count(tablename)
FROM (
SELECT tbl,
tablename,
dbname,
SUM(t_excess_blks) est_space_gain
FROM (SELECT tbl,
col,
node,
tablename,
Trim(datname) AS dbname,
SUM(excess_blks) * ( col + 1 ) AS t_excess_blks
FROM (SELECT tbl,
slice,
col,
Count(*) total_blks
FROM stv_blocklist
WHERE num_values > 0
GROUP BY 1,
2,
3) a
join (SELECT tbl,
slice,
Max(col) AS col
FROM stv_blocklist
GROUP BY 1,
2) b USING (tbl, slice, col)
join (SELECT tbl,
slice,
col,
Count(*) - Ceil(SUM(num_values) / 130994.0)
AS
excess_blks
FROM stv_blocklist
WHERE num_values > 0
AND num_values < 130994
GROUP BY 1,
2,
3) c USING (tbl, slice, col)
join stv_slices d USING (slice)
join (SELECT id,
Trim("name") AS tablename,
db_id
FROM stv_tbl_perm
WHERE slice = 0) f
ON b.tbl = f.id
join pg_database g
ON f.db_id = g.oid
WHERE excess_blks > 1
GROUP BY 1,
2,
3,
4,
5)
WHERE tbl > 1
AND t_excess_blks > (SELECT CASE
WHEN SUM(capacity) > 200000 THEN
1024
ELSE 102.4
END
FROM stv_partitions
WHERE host = owner
AND host = 0
GROUP BY host)
GROUP BY 1,
2,
3
ORDER BY 4 DESC);
-- Disk based queries
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 23,
'Performance',
'Disk based queries',
'https://thedataguy.in/rskit/diskquery',
Count(*)
FROM (SELECT query
FROM svl_query_summary
WHERE is_diskbased = 't'
GROUP BY query);
-- COPY not optimized
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 24,
'Performance',
'COPY not optimized',
'https://thedataguy.in/rskit/copy',
Count(*)
FROM (SELECT Count(*) AS n_files
FROM stl_s3client
WHERE http_method = 'GET'
AND query > 0
AND transfer_time > 0
GROUP BY query)
WHERE n_files % (SELECT Count(slice)
FROM stv_slices) != 0;
-- High CPU queries (>80 Percent)
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 25,
'Performance',
'High CPU queries',
'https://thedataguy.in/rskit/highcpu',
Count(*)
FROM (SELECT query,
Max(query_cpu_usage_percent) cpu
FROM svl_query_metrics
WHERE query_execution_time > 60
AND query_cpu_usage_percent IS NOT NULL
AND (service_class BETWEEN 6 AND 13 or service_class >100)
AND query_cpu_usage_percent > 80
AND query NOT IN(SELECT query
FROM stl_query
WHERE querytxt NOT LIKE 'Vacuum'
OR querytxt NOT LIKE 'vacuum')
GROUP BY query );
-- Most frequent Alert (> 500 times)
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 26,
'Performance',
'Most frequent Alert',
'https://thedataguy.in/rskit/alert',
Listagg(event, ' ,')
FROM (SELECT Trim(Split_part(event, ':', 1)) AS event,
Count(*)
FROM stl_alert_event_log
GROUP BY 1)
WHERE count > 500;
-- Long running queries (> 30mins)
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 27,
'Performance',
'Long running queries',
'https://thedataguy.in/rskit/slowquery',
Count(*)
FROM svl_query_metrics
WHERE query_execution_time >= 1800;
-- Max temp space used by queries
INSERT INTO rstk_metric_result
(checkid,
category,
finding,
url,
value)
SELECT 28,
'Performance',
'Max temp space used by queries',
'https://thedataguy.in/rskit/diskquery',
Max(gigabytes)
FROM (SELECT SUM(( bytes ) / 1024 / 1024 / 1024) AS GigaBytes
FROM stl_query q
join svl_query_summary qs
ON qs.query = q.query
WHERE qs.is_diskbased = 't'
AND q.starttime BETWEEN SYSDATE - 7 AND SYSDATE
GROUP BY q.query);
-- -------------------------------------
-- Adding the description and priority
-- -------------------------------------
-- Tables without sort keys
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 0 THEN 'There are '
|| value
||
' tables without sortkeys. This will result in scanning of all blocks for even range restricted predicates'
ELSE 'Awesome, all of your tables having sort keys!!!'
END AS details,
CASE
WHEN Cast(value AS INT) > 10 THEN 1
WHEN Cast(value AS INT) BETWEEN 1 AND 10 THEN 2
WHEN Cast(value AS INT) =0 then 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 1) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- Sort key column compressed
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 0 THEN 'There are '
|| value
||
' tables where sort key columns are compressed, this may lead to a slight performance degradation'
ELSE 'Awesome, none of your sort key columns are compressed'
END AS details,
CASE
WHEN Cast(value AS INT) > 10 THEN 1
WHEN Cast(value AS INT) BETWEEN 1 AND 10 THEN 2
WHEN Cast(value AS INT) =0 then 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 2) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- Sort key skew > 4
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 0 THEN value
||
' tables sort keys are skewed which indicates that you have to uncompress the sort key column or these columns may not be the right candidate for the sort keys. '
ELSE 'Your sort keys are does not have any skew.'
END AS details,
CASE
WHEN Cast(value AS INT) > 10 THEN 1
WHEN Cast(value AS INT) BETWEEN 1 AND 10 THEN 2
WHEN Cast(value AS INT) =0 then 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 3) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- Tables with high Skew
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 0 THEN value
||
' tables have skew in termns of distribution. This will result in more load on few nodes. Consider changing the dist key if required'
ELSE 'Seems the table distribution looks good'
END AS details,
CASE
WHEN Cast(value AS INT) > 10 THEN 1
WHEN Cast(value AS INT) BETWEEN 1 AND 10 THEN 2
WHEN Cast(value AS INT) = 0 then 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 4) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- Tables without compression
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 0 THEN value
||
' tables are not compressed yet, this is not a good practice and needs to be fixed immediately, please compress all the columns except the sort key'
ELSE 'Good Job!!! All the tables are compressed'
END AS details,
CASE
WHEN Cast(value AS INT) > 10 THEN 1
WHEN Cast(value AS INT) BETWEEN 1 AND 10 THEN 2
WHEN Cast(value AS INT) =0 then 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 5) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- WLM queue wait time > 1min
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 180 THEN ' Sometimes your cluster is spending more time on wait on the queue. The max wait time from last 7 days is '
|| value
||
' seconds. You have to tune your WLM to reduce the wait time.'
WHEN Cast(value AS INT) < 180 THEN
'We found that the wait time is less than 180 second ('||value||') which is Good. But still consider tuning WLM if need.'
ELSE 'Unknown - - Your system tables may not have enough data'
END AS details,
CASE
WHEN Cast(value AS INT) > 900 THEN 1
WHEN Cast(value AS INT) BETWEEN 180 AND 900 THEN 2
WHEN Cast(value AS INT) < 180 then 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 6) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- WLM max connection hit
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) BETWEEN 100 AND 400 THEN
' This cluster hits '
|| value
||
' as the high number of connections recently. RedShift supports 500 max connections, so please tune your WLM setting to reduce the wait time and boost the queries.'
WHEN Cast(value AS INT) < 100 THEN
'Great!!! This cluster never reach 100 connections (only '||value||') at any point of time, But to speed up concurrent queries in a queue, you may tune the WLM settings.'
ELSE 'Unknown - - Your system tables may not have enough data'
END AS details,
CASE
WHEN Cast(value AS INT) > 300 THEN 1
WHEN Cast(value AS INT) BETWEEN 100 AND 300 THEN 2
WHEN Cast(value AS INT) < 100 THEN 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 7) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- Number of WLM queue
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) = 1 THEN
' You are using Default queue only, its a Red Flag. At least keep minimum 2 Queues to balance the workload'
WHEN Cast(value AS INT)BETWEEN 2 AND 3 THEN 'OK! you have '
|| value
||
' queues, not bad. Still if you see any waiting process on the queue then tune WLM'
WHEN Cast(value AS INT)BETWEEN 3 AND 7 THEN 'OK! you have '
|| value
||
' queues, not bad. But make sure it should to eat much resources. For a generic workload 2 to 3 queues will work fine.'
WHEN Cast(value AS INT) =0 then 'You are using Auto WLM, so this check is not applicable'
ELSE 'Unknown - - Your system tables may not have enough data'
END AS details,
CASE
WHEN Cast(value AS INT)= 1 THEN 1
WHEN Cast(value AS INT) BETWEEN 3 AND 7 THEN 2
WHEN Cast(value AS INT) BETWEEN 2 AND 3 THEN 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 8) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- Auto WLM enabled
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) = 0 THEN
' You are using manual WLM, if you are aware about your workload and the manual WLM has more than 2 or 3 queues then may be it will fit. Or just give a try with Auto WLM and let RedShift decide to allocate the resource'
WHEN Cast(value AS INT) > 0 THEN
'You have Auto WLM enbled, Good!!! still you are not convinced then switch to Manual WLM and tune the queues properly.'
ELSE 'Unknown - - Your system tables may not have enough data'
END AS details,
CASE
WHEN Cast(value AS INT) = 0 THEN 2
WHEN Cast(value AS INT) > 0 THEN 2
END AS priority
FROM rstk_metric_result
WHERE checkid = 9) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- Max concurrency for a slot
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 20 THEN ' You have allocated'
|| value
||
' to your queue, generally more concurrey reduce the capacity. We recommed to use the slots between 15 to 20'
WHEN Cast(value AS INT) BETWEEN 10 AND 20 THEN 'You have '
|| value
||
' concurrent slots, Good!!! '
WHEN Cast(value AS INT) < 10 THEN 'You have '
|| value
||
' which is very less, it may allocate more resource per slot, but many sessions will go to waiting state iin the queue. Optimal value is 15 to 20'
WHEN value IS NULL then 'You are using Auto WLM, so this check is not applicable'
ELSE 'Unknown - - Your system tables may not have enough data'
END AS details,
CASE
WHEN Cast(value AS INT) > 20 THEN 1
WHEN Cast(value AS INT)BETWEEN 10 AND 20 THEN 2
WHEN Cast(value AS INT) < 10 THEN 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 10) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- WLM commit queue wait
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 120 THEN
'We found recently the commit was in the waiting queue for '
|| value
||
' seconds, many reasons for this, but an optimized WLM will make this process much better'
WHEN Cast(value AS INT) BETWEEN 60 AND 120 THEN
'We found recently the commit was in the waiting queue for '
|| value
||
' seconds, no flags in that. If you feel its a high numnber, then an optimized WLM will make this process much better '
WHEN Cast(value AS INT) < 60 THEN 'Great!!! the commit wait was '
|| value
|| ' seconds, this looks good'
ELSE 'Unknown - - Your system tables may not have enough data'
END AS details,
CASE
WHEN Cast(value AS INT) > 120 THEN 1
WHEN Cast(value AS INT) BETWEEN 60 AND 120 THEN 2
WHEN Cast(value AS INT) < 60 THEN 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 11) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- Ghost rows
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 100000 THEN
' You have more than 100K Ghost rows totally, it is a Red flag, please run vacuum on these tables.'
WHEN Cast(value AS INT) BETWEEN 1000 AND 100000 THEN 'You have '
|| value
||
' Ghost rows(marked for delete), please run vacuum to remove them'
WHEN Cast(value AS INT) < 1000 THEN
'Awesome!!! You have less than 1K Ghost rows(only '||value||'), but frequently running vacuum will help you to clean up the Ghost rows.'
ELSE 'Unknown - - Your system tables may not have enough data'
END AS details,
CASE
WHEN Cast(value AS INT) > 100000 THEN 1
WHEN Cast(value AS INT) BETWEEN 1000 AND 100000 THEN 2
WHEN Cast(value AS INT) < 1000 THEN 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 12) sq
WHERE rstk_metric_result.checkid = sq.checkid;
-- Tables never performed vacuum (based on STL_Vacuum)
UPDATE rstk_metric_result
SET details = sq.details,
priority = sq.priority
FROM (SELECT checkid,
CASE
WHEN Cast(value AS INT) > 5 THEN
' This cluster has '||value||' tables never vacuumed(from STL_Vacuum result), It is a RedFlag. Frequently running vacuum will make this count 0 and improve the overall process'
WHEN Cast(value AS INT)BETWEEN 1 AND 5 THEN
' This cluster has '||value||' tables where vacuum never run(from STL_Vacuum result), Frequently running vacuum will make this count 0 and improve the overall process'
WHEN Cast(value AS INT) = 0 THEN 'Good Job!!! all the tables are vacummed'
ELSE 'Unknown - - Your system tables may not have enough data'
END AS details,
CASE
WHEN Cast(value AS INT) > 5 THEN 1
WHEN Cast(value AS INT) BETWEEN 1 AND 5 THEN 2
WHEN Cast(value AS INT) = 0 THEN 3
END AS priority
FROM rstk_metric_result
WHERE checkid = 13) sq