大家好,这里是公众号 DBA学习之路,分享一些学习国产数据库路上的知识和经验。

前言

最近在测试 GBase 8s 国产数据库,翻阅官方网站,发现一个 Gbase 8s 数据库的巡检脚本以及巡检报告的模板,分享出来给大家,本文仅为转载,原文地址:GBase 8s数据库巡检报告及巡检脚本

1、概述

1.1 环境说明

序号配置项配置备注
1服务器类型  
2IP地址  
3操作系统  
4CPU数  
5物理内存  
6数据库版本  
7数据库名称  
8集群环境说明  
9业务系统名称  

1.2 巡检记录

序号记录项记录内容备注
1上次巡检日期  
2本次巡检日期  
3巡检工程师  
4负责人  

2、巡检

2.1 巡检总体结论

总体结论:
检查项检查记录检查结论建议/补充说明
系统cpu使用 正常 
系统内存使用 正常 
实例状态 正常 
集群状态 正常 
实例虚拟内存段 正常 
参数检查 正常 
逻辑日志使用 正常 
事务提交数 正常 
online.log 正常 
备份 正常 
空间状态 正常 
空间使用率 正常 
检查点 正常 
IO队列 正常 
数据库日志模式 正常 
表空间使用 正常 
锁等待及死锁 正常 
表顺序扫描 正常 
表锁粒度 正常 

2.2 操作系统资源使用

2.2.1 系统CPU使用率

检查项系统CPU资源使用
检查记录 
检查结论正常
补充说明 

2.2.2 系统内存使用率

检查项系统内存资源使用
检查记录 
检查结论正常
补充说明 

2.3 实例运行概况

2.3.1 实例状态检查

检查项数据库实例状态
检查记录 
检查结论正常
补充说明 

2.3.2 集群状态检查

检查项数据库集群状态
检查记录 
检查结论正常
补充说明 

2.3.3 运行时间检查

检查项数据库实例运行时间
检查记录 
检查结论正常
补充说明 

2.3.4 实例虚拟内存段检查

检查项实例内存
检查记录 
检查结论正常
补充说明 

2.3.5 参数检查

检查项实例参数变更
检查记录 
检查结论正常
补充说明 

2.3.6 运行状态统计检查

检查项实例运行状态计数器
检查记录 
检查结论正常
补充说明

如ovlock >0 需要增加locks 

如ovbuff >0 需要增加Buffers

如ovuserthread > 0 需要增加Users

2.3.7  逻辑日志使用检查

检查项逻辑日志使用
检查记录 
检查结论正常
补充说明 

2.3.8 事务数及成功率检查

检查项事务成功率
检查记录 
检查结论正常
补充说明 

2.3.9 online.log 日志检查

检查项检查online.log
检查记录 
检查结论正常
补充说明 

2.3.10 备份检查

检查项数据库备份
检查记录 
检查结论正常
补充说明 

2.4 空间与磁盘 IO

2.4.1 空间状态

检查项数据库空间状态
检查记录 
检查结论正常
补充说明 

2.4.2 空间使用率

检查项数据库空间使用率
检查记录
DBSNum空间名空间类型空间总大小空间剩余大小空间使用率空间页大小空间chunk个数上次巡检剩余变化趋势
1rootdbsDbspace      
2logdbsDbspace      
3physdbsDbspace      
4tempdbsTempDbspace      

 

检查结论关注
补充说明数据库空间cbsdbs使用率超过90%,需关注及时扩容,或新增新的数据库空间用于存放新建表。

2.4.3 磁盘写入方式检查

检查项磁盘写入方式
检查记录 
检查结论正常
补充说明 

2.4.4 检查点执行时间检查

检查项检查点执行时间
检查记录 
检查结论正常
补充说明 

2.4.5 IO 队列检查

检查项磁盘IO队列
检查记录 
检查结论正常
补充说明 

2.4.6 表 IO

检查项大表IO情况
检查记录
库名表名行数表大小磁盘读页数缓存读页数磁盘写页数缓存写页数读命中率写命中率
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          

 

检查结论正常
补充说明 

2.5 库与表检查

2.5.1 数据库日志模式

检查项数据库日志模式
检查记录 
检查结论正常
补充说明生产环境数据库日志模式使用unbuffered

2.5.2 表空间使用情况

检查项大表空间使用情况
检查记录
库名表名extents行数总数据页总大小已用页数已用大小上次使用大小变化趋势
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          

 

检查结论正常
补充说明 

2.5.3 表锁等待及死锁

检查项数据库锁使用情况
检查记录
库名表名/索引名锁请求个数锁等待次数死锁次数
     
     
     
     
     
     

 

检查结论正常
补充说明 

2.5.4 表顺序扫描

检查项数据库顺序扫描
检查记录
库名表名行数总大小已用大小扫描次数
      
      
      
      
      
      

 

检查结论正常
补充说明无大表频繁顺序扫描

2.5.5 表锁粒度

检查项数据库顺序扫描
检查记录
库名表名创建时间行数锁粒度
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

 

检查结论正常
补充说明 

2.5.6 表统计更新

检查项数据库统计更新
检查记录 
检查结论正常
补充说明 

附 GBase8schk.sh 脚本文件

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
#!/bin/bash
###################################################################################
# filename: GBase8schk.sh
# Last modified by: L3 2023-12-26
# support OS: Linux
# support database version: GBase 8s V8.x
# useage: sh GBase8schk.sh
###################################################################################
echo ""
echo "Begin to collect data for GBASEDBTSERVER:"${GBASEDBTSERVER}
echo ""
mytime=`date '+%Y%m%d%H%M%S'`
outpath="GBase8schk_${GBASEDBTSERVER}_${mytime}"
if [ ! -d ${outpath} ]; then
mkdir ${outpath}
fi
###################################################################################
## Machine
###################################################################################
echo "collect machine info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/machine.unl delimiter '|'
select
os_name,os_release,os_nodename,os_version,os_machine,os_num_procs,os_num_olprocs,
os_pagesize,os_mem_total,os_mem_free,os_open_file_lim,os_shmmax
from sysmachineinfo;
EOF
###################################################################################
## Instance
###################################################################################
echo "collect instance info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/instance.unl delimiter '|'
select
dbinfo('UTC_TO_DATETIME',sh_boottime)||' T' start_time,
(current year to second - dbinfo('UTC_TO_DATETIME',sh_boottime))||' T' run_time,
sh_maxchunks as maxchunks,
sh_maxdbspaces maxdbspaces,
sh_maxuserthreads maxuserthreads,
sh_maxtrans maxtrans,
sh_maxlocks locks,
sh_longtx longtxs,
dbinfo('UTC_TO_DATETIME',sh_pfclrtime)||' T' onstat_z_running_time
from sysshmvals;
EOF
###################################################################################
## CPUVP
###################################################################################
echo "collect cpuvp info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/cpuvp.unl delimiter '|'
select vpid,classname class,pid,round(usecs_user,2) user_cpu,round(usecs_sys,2) sys_cpu,num_ready,
total_semops,total_busy_wts,total_yields,total_spins,vp_cache_size,vp_cache_allocs
from sysvplst ;
EOF
###################################################################################
## Memory
###################################################################################
echo "collect instance memory info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/memory.unl delimiter '|'
select
indx,bufsize pagesize,
nbuffs buffers,
round(nbuffs*bufsize/1024/1024/1024,2)||'GB' buffsize,
nlrus,mindirty,maxdirty,
(bufwaits / (bufwrites + pagreads)) * 100.00 buff_wait_rate,
100 * (bufreads-dskreads)/ bufreads buff_read_rate,
100 * (bufwrites-dskwrites)/ bufwrites buff_write_rate,
fgwrites,lruwrites ,chunkwrites
from sysbufpool;
EOF
###################################################################################
## Network
###################################################################################
echo "collect sqlhosts info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/sqlhosts.unl delimiter '|'
select dbsvrnm,nettype,hostname,svcname,options,
svrsecurity,netbuf_size,svrgroup
from syssqlhosts;
EOF
###################################################################################
## Session time
###################################################################################
echo "collect session runtime info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/sessiontime.unl delimiter '|'
SELECT first 500 s.sid, s.username, s.hostname, q.odb_dbname database,
dbinfo('UTC_TO_DATETIME',s.connected) conection_time,
dbinfo('UTC_TO_DATETIME',t.last_run_time) last_run_time,
current - dbinfo('UTC_TO_DATETIME',s.connected) connected_since,
current - dbinfo('UTC_TO_DATETIME',t.last_run_time) idle_time
FROM syssessions s, systcblst t, sysrstcb r, sysopendb q
WHERE t.tid = r.tid AND s.sid = r.sid AND s.sid = q.odb_sessionid
ORDER BY 8 DESC;
EOF
###################################################################################
## Session wait
###################################################################################
echo "collect session waits info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/sessionwait.unl delimiter '|'
select first 20 sid,pid, username, hostname,
is_wlatch, -- blocked waiting on a latch
is_wlock, -- blocked waiting on a locked record or table
is_wbuff, -- blocked waiting on a buffer
is_wckpt, -- blocked waiting on a checkpoint
is_incrit -- session is in a critical section of transaction-- (e.g writting to disk)
from syssessions
order by is_wlatch+is_wlock+is_wbuff+is_wckpt+is_incrit desc;
EOF
###################################################################################
## Session IO
###################################################################################
echo "collect session IO info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/sessionio.unl delimiter '|'
select first 100 syssesprof.sid,isreads,iswrites,isrewrites,
isdeletes,bufreads,bufwrites,seqscans ,
pagreads ,pagwrites,total_sorts ,dsksorts ,
max_sortdiskspace,logspused
from syssesprof, syssessions
where syssesprof.sid = syssessions.sid
order by bufreads+bufwrites desc
;
EOF
###################################################################################
## Checkpoint
###################################################################################
echo "collect checkpoint info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/checkpoint.unl delimiter '|'
select
intvl,type,caller,dbinfo('UTC_TO_DATETIME',clock_time)||' T' clock_time,
round(crit_time,4),round(flush_time,4),round(cp_time,4),n_dirty_buffs,
plogs_per_sec,llogs_per_sec,dskflush_per_sec,ckpt_logid,ckpt_logpos,physused,logused,
n_crit_waits,tot_crit_wait,longest_crit_wait,block_time
from syscheckpoint order by intvl;
EOF
###################################################################################
## Database
###################################################################################
echo "collect database info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/database.unl delimiter '|'
SELECT trim(name) dbname,trim(owner) owner, created||' T' created_time,
TRIM(DBINFO('dbspace',partnum)) AS dbspace,
CASE WHEN is_logging+is_buff_log=1 THEN "Unbuffered logging"
WHEN is_logging+is_buff_log=2 THEN "Buffered logging"
WHEN is_logging+is_buff_log=0 THEN "No logging"
ELSE "" END Logging_mode
FROM sysdatabases
where trim(name) not like 'sys%';
EOF
###################################################################################
## DBspace
###################################################################################
echo "collect dbspaces info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/dbspace.unl delimiter '|'
SELECT A.dbsnum as No, trim(B.name) as name,
CASE WHEN (bitval(B.flags,'0x10')>0 AND bitval(B.flags,'0x2')>0)
THEN 'MirroredBlobspace'
WHEN bitval(B.flags,'0x10')>0 THEN 'Blobspace'
WHEN bitval(B.flags,'0x2000')>0 AND bitval(B.flags,'0x8000')>0
THEN 'TempSbspace'
WHEN bitval(B.flags,'0x2000')>0 THEN 'TempDbspace'
WHEN (bitval(B.flags,'0x8000')>0 AND bitval(B.flags,'0x2')>0)
THEN 'MirroredSbspace'
WHEN bitval(B.flags,'0x8000')>0 THEN 'SmartBlobspace'
WHEN bitval(B.flags,'0x2')>0 THEN 'MirroredDbspace'
ELSE 'Dbspace'
END as dbstype,
round(sum(chksize)*2/1024/1024,2)||'GB' as DBS_SIZE ,
round(sum(decode(mdsize,-1,nfree,udfree))*2/1024/1024,2)||'GB' as free_size,
case when sum(decode(mdsize,-1,nfree,udfree))*100/sum(decode(mdsize,-1,chksize,udsize))
>sum(decode(mdsize,-1,nfree,nfree))*100/sum(decode(mdsize,-1,chksize,mdsize))
then TRUNC(100-sum(decode(mdsize,-1,nfree,nfree))*100/sum(decode(mdsize,-1,chksize,mdsize)),2)||"%"
else TRUNC(100-sum(decode(mdsize,-1,nfree,udfree))*100/sum(decode(mdsize,-1,chksize,udsize)),2)||"%"
end as used,
TRUNC(MAX(A.pagesize/1024))||"KB" as pgsize,
MAX(B.nchunks) as nchunks
FROM syschktab A, sysdbstab B
WHERE A.dbsnum = B.dbsnum
GROUP BY A.dbsnum,name, 3
ORDER BY A.dbsnum;
EOF
###################################################################################
## Chunks
###################################################################################
echo "collect chunk info using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/chunks.unl delimiter '|'
SELECT A.chknum as num, B.name as spacename,
TRUNC((A.pagesize/1024)) as pgsize,
A.offset offset,
round( A.chksize*2/1024/1024,2)||'GB' as size,
round(decode(A.mdsize,-1,A.nfree,A.udfree)*2/1024/1024,2)||'GB' as free,
TRUNC(100 - decode(A.mdsize,-1,A.nfree,A.udfree)*100/A.chksize,2 ) as used,
A.fname
FROM syschktab A, sysdbstab B
WHERE A.dbsnum = B.dbsnum
order by B.dbsnum;
EOF
###################################################################################
## Chunk IO
###################################################################################
echo "collect chunk IO using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/chunk_io.unl delimiter '|'
select d.name dbspace, fname[1,125] chunk_name,reads read_count,writes write_count,
reads+writes total_count,pagesread,pageswritten,
pagesread+pageswritten total_pg
from sysmaster:syschkio c, sysmaster:syschunks k, sysmaster:sysdbspaces d
where d.dbsnum = k.dbsnum and k.chknum = c.chunknum
order by 8 desc;
EOF
###################################################################################
## Logical Log
###################################################################################
echo "collect logical log using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/logicallog.unl delimiter '|'
SELECT A.number as num, A.uniqid as uid, round(A.size*2/1024,2)||'MB' as size,
TRIM( TRUNC(A.used*100/A.size,0)||'%') as used,
d.name as spacename,
TRIM( A.chunk||'_'||A.offset ) as location,
decode(A.filltime,0,'NotFull',
dbinfo('UTC_TO_DATETIME', A.filltime)::varchar(50))||' T' as filltime,
CASE WHEN bitval(A.flags,'0x1') > 0 AND bitval(A.flags,'0x4')>0
THEN 'UsedBackedUp'
WHEN bitval(A.flags,'0x1') > 0 AND bitval(A.flags,'0x2')>0
THEN 'UsedCurrent'
WHEN bitval(A.flags,'0x1') > 0 THEN 'Used'
ELSE hex(A.flags)::varchar(50)
END as flags,
CASE WHEN A.filltime-B.filltime > 0 THEN
round(CAST(TRUNC(A.size/(A.filltime-B.filltime),4)
as varchar(20))*2/1024,2)||'MB/S'
ELSE ' N/A ' END as pps
FROM syslogfil A, syslogfil B,syschktab c, sysdbstab d
WHERE A.uniqid-1 = B.uniqid
and c.dbsnum = d.dbsnum
and a.chunk=c.chknum
UNION
SELECT A.number as num, A.uniqid as uid, round(A.size*2/1024,2)||'MB' as size,
TRIM( TRUNC(A.used*100/A.size,0)||'%') as used,
d.name as spacename,
TRIM( A.chunk||'_'||A.offset ) as location,
decode(A.filltime,0,'NotFull',
dbinfo('UTC_TO_DATETIME', A.filltime)::varchar(50))||' T' as filltime,
CASE WHEN bitval(A.flags,'0x1') > 0 AND bitval(A.flags,'0x4')>0
THEN 'UsedBackedUp'
WHEN bitval(A.flags,'0x1') > 0 AND bitval(A.flags,'0x2')>0
THEN 'UsedCurrent'
WHEN bitval(A.flags,'0x1') > 0 THEN 'Used'
WHEN bitval(A.flags,'0x8') > 0 THEN 'NewAdd'
ELSE hex(A.flags)::varchar(50) END as flags,
'N/A' as pps
FROM syslogfil A ,syschktab c, sysdbstab d
WHERE ( A.uniqid = (SELECT min(uniqid) FROM syslogfil WHERE uniqid > 0)
OR A.uniqid = 0 )
and c.dbsnum = d.dbsnum
and a.chunk=c.chknum
ORDER BY A.uniqid ;
EOF
###################################################################################
## Locks on Table
###################################################################################
echo "collect table locks using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/tab_actlock.unl delimiter '|'
select dbsname,tabname,
sum(pf_rqlock) as locks,
sum(pf_wtlock) as lockwaits,
sum(pf_deadlk) as deadlocks
from sysactptnhdr,systabnames
where systabnames.partnum = sysactptnhdr.partnum
group by dbsname,tabname
order by lockwaits,locks desc;
EOF
dbaccess sysmaster - << EOF
unload to ./${outpath}/tab_lock.unl delimiter '|'
select dbsname,tabname,
sum(lockreqs) as lockreqs,
sum(lockwts) as lockwaits,
sum(deadlks) as deadlocks
from sysptprof
group by dbsname,tabname
order by deadlocks,lockwaits,lockreqs desc;
EOF
###################################################################################
## Databaes Used Space
###################################################################################
echo "collect database used space using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/database_space.unl delimiter '|'
select t1.dbsname,
round(sum(ti_nptotal)*max(ti_pagesize)/1024/1024/1024,2)||'GB' allocated_size,
round(sum(ti_npused)*max(ti_pagesize)/1024/1024/1024,2)||'GB' used_size
from systabnames t1, systabinfo t2,sysdatabases t3
where t1.partnum = t2.ti_partnum
and trim(t3.name)=trim(t1.dbsname)
group by dbsname
order by sum(ti_nptotal) desc;
EOF
###################################################################################
## Tables Space
###################################################################################
echo "collect table and index used space using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/tab_space.unl delimiter '|'
SELECT st.dbsname databasename, st.tabname,
MAX(dbinfo('UTC_TO_DATETIME',sin.ti_created)) createdtime,
SUM( sin.ti_nextns ) extents,
SUM( sin.ti_nrows ) nrows,
MAX( sin.ti_nkeys ) nkeys,
MAX( sin.ti_pagesize ) pagesize,
SUM( sin.ti_nptotal ) nptotal,
round(SUM( sin.ti_nptotal*sd.pagesize )/1024/1024,2)||'MB' total_size,
SUM( sin.ti_npused ) npused,
round(SUM( sin.ti_npused*sd.pagesize )/1024/1024,2)||'MB' used_size,
SUM( sin.ti_npdata ) npdata,
round(SUM( sin.ti_npdata*sd.pagesize )/1024/1024,2)||'MB' data_size
FROM
sysmaster:systabnames st,
sysmaster:sysdbspaces sd,
sysmaster:systabinfo sin
WHERE
sd.dbsnum = trunc(st.partnum / 1048576)
AND st.partnum = sin.ti_partnum
AND st.dbsname NOT IN ('sysmaster','sysuser','sysadmin','sysutils','sysha','syscdr','syscdcv1')
AND st.tabname[1,3] NOT IN ('sys','TBL')
GROUP BY 1, 2
ORDER BY 9 DESC;
EOF
###################################################################################
## Tables Space By Partition
###################################################################################
echo "collect table and index partition used space using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/tab_space_frag.unl delimiter '|'
SELECT st.dbsname databasename, st.tabname,st.partnum partnum,
dbinfo('UTC_TO_DATETIME',sin.ti_created) createdtime,
sin.ti_nextns extents,
sin.ti_nrows nrows,
sin.ti_nkeys nkeys,
sin.ti_pagesize pagesize,
sin.ti_nptotal nptotal,
round(( sin.ti_nptotal*sd.pagesize )/1024/1024,2)||'MB' total_size,
( sin.ti_npused ) npused,
round(( sin.ti_npused*sd.pagesize )/1024/1024,2)||'MB' used_size,
( sin.ti_npdata ) npdata,
round(( sin.ti_npdata*sd.pagesize )/1024/1024,2)||'MB' data_size
FROM
sysmaster:systabnames st,
sysmaster:sysdbspaces sd,
sysmaster:systabinfo sin
WHERE
sd.dbsnum = trunc(st.partnum / 1048576)
AND st.partnum = sin.ti_partnum
AND st.dbsname NOT IN ('sysmaster','sysuser','sysadmin','sysutils','sysha','syscdr','syscdcv1')
AND st.tabname[1,3] NOT IN ('sys','TBL')
ORDER BY 9 DESC;
EOF
###################################################################################
## Tables and index IO and seqscans
###################################################################################
echo "collect table and index io and seqscans using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/tab_io.unl delimiter '|'
SELECT
st.dbsname,p.tabname,SUM( sin.ti_nrows ) nrows,
round(SUM( sin.ti_nptotal*sd.pagesize )/1024/1024,2)||'MB' total_size,
round(SUM( sin.ti_npused*sd.pagesize )/1024/1024,2)||'MB' used_size,
SUM( seqscans ) AS seqscans,
SUM( pagreads ) diskreads,
SUM( bufreads ) bufreads,
SUM( bufwrites ) bufwrites,
SUM( pagwrites ) diskwrites,
SUM( pagreads )+ SUM( pagwrites ) disk_rsws,
trunc(decode(SUM( bufreads ),0,0,(100 -((SUM( pagreads )* 100)/ SUM( bufreads + pagreads )))),2) AS rbufhits,
trunc(decode(SUM( bufwrites ),0,0,(100 -((SUM( pagwrites )* 100)/ SUM( bufwrites + pagwrites )))),2) AS wbufhits
FROM
sysmaster:sysptprof p,
sysmaster:systabinfo sin,
sysmaster:sysdbspaces sd,
sysmaster:systabnames st
WHERE
sd.dbsnum = trunc(st.partnum / 1048576)
AND p.partnum = st.partnum
AND st.partnum = sin.ti_partnum
AND st.dbsname NOT IN ('sysmaster','sysuser','sysadmin','sysutils','sysha','syscdr','syscdcv1')
AND st.tabname[1,3] NOT IN ('sys','TBL')
GROUP BY 1, 2
ORDER BY 11 DESC;
EOF
###################################################################################
## Current slowest sql
###################################################################################
echo "collect current slowest sql using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/slowsql.unl delimiter '|'
Select first 100 sqx_estcost,sqx_estrows,sqx_sqlstatement
FROM sysmaster:syssqexplain
order by sqx_estcost desc;
EOF
###################################################################################
## Table statistics,lockmode,index keys
###################################################################################
echo "collect tables statistics,lockmode,index keys using sql ......"
dbaccess sysmaster - << EOF
unload to ./${outpath}/tabstat.sql delimiter ";"
select
"unload to ./${outpath}/"||trim(name)||"_stat.unl Select t.tabname,t.created as tabcreated,t.nrows,tmpt.nrows as realrows,t.locklevel,t.ustlowts,i.idxname,"||
"trim(case when i.part1>0 then (select colname from "||trim(name)||":syscolumns where colno=i.part1 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part2>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part2 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part3>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part3 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part4>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part4 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part5>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part5 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part6>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part6 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part7>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part7 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part8>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part8 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part9>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part9 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part10>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part10 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part11>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part11 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part12>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part12 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part13>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part13 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part14>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part14 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part15>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part15 and tabid=i.tabid) else '' end)||"||
"trim(case when i.part16>0 then (select ','||colname from "||trim(name)||":syscolumns where colno=i.part16 and tabid=i.tabid) else '' end ) index_cols"||
",i.nunique "||
"from "||trim(name)||":systables t left join "||trim(name)||":sysindexes i on t.tabid=i.tabid "||
"join (select tabname,sum(ti_nrows) as nrows from systabnames tn join systabinfo ti on ti.ti_partnum=tn.partnum where dbsname='"||trim(name)||"' "||
"group by tabname) as tmpt "||
"on t.tabname=tmpt.tabname "||
"where t.tabid>99 "||
"and t.tabtype='T' "||
"order by 4 desc,1"
from sysdatabases
where name NOT IN ('sysmaster','sysuser','sysadmin','sysutils','sysha','syscdr','syscdcv1')
and is_logging=1;
EOF
dbaccess sysmaster ${outpath}/tabstat.sql
###################################################################################
## onstat cmd
###################################################################################
echo "collect instance running status using onstat commands ......"
onstat -b > ./${outpath}/onstat_b.unl
onstat -C all > ./${outpath}/onstat_C_all.unl
onstat -C > ./${outpath}/onstat_bigc.unl
onstat -c > ./${outpath}/onstat_c.unl
onstat -D > ./${outpath}/onstat_bigd.unl
onstat -d > ./${outpath}/onstat_d.unl
onstat -F > ./${outpath}/onstat_F.unl
onstat -g act > ./${outpath}/onstat_g_act.unl
onstat -g arc > ./${outpath}/onstat_g_arc.unl
onstat -g ath > ./${outpath}/onstat_g_ath.unl
onstat -g buf > ./${outpath}/onstat_g_buf.unl
onstat -g cluster > ./${outpath}/onstat_g_cluster.unl
onstat -g cmsm > ./${outpath}/onstat_g_cmsm.unl
onstat -g cfg > ./${outpath}/onstat_g_cfg.unl
onstat -g cfg diff > ./${outpath}/onstat_g_cfg_diff.unl
onstat -g ckp > ./${outpath}/onstat_g_ckp.unl
onstat -g con > ./${outpath}/onstat_g_con.unl
onstat -g cpu > ./${outpath}/onstat_g_cpu.unl
onstat -g dic > ./${outpath}/onstat_g_dic.unl
onstat -g dis > ./${outpath}/onstat_g_dis.unl
onstat -g dsc > ./${outpath}/onstat_g_dsc.unl
onstat -g env > ./${outpath}/onstat_g_env.unl
onstat -g glo > ./${outpath}/onstat_g_glo.unl
onstat -g iof > ./${outpath}/onstat_g_iof.unl
onstat -g iog > ./${outpath}/onstat_g_iog.unl
onstat -g ioq > ./${outpath}/onstat_g_ioq.unl
onstat -g iov > ./${outpath}/onstat_g_iov.unl
onstat -g lmx > ./${outpath}/onstat_g_lmx.unl
#onstat -g mem > ./${outpath}/onstat_g_mem.unl
onstat -g mgm > ./${outpath}/onstat_g_mgm.unl
onstat -g ntd > ./${outpath}/onstat_g_ntd.unl
onstat -g ntt > ./${outpath}/onstat_g_ntt.unl
onstat -g ntu > ./${outpath}/onstat_g_ntu.unl
onstat -g osi > ./${outpath}/onstat_g_osi.unl
onstat -g rea > ./${outpath}/onstat_g_rea.unl
onstat -g seg > ./${outpath}/onstat_g_seg.unl
onstat -g ses 0 > ./${outpath}/onstat_g_ses_0.unl
onstat -g ses > ./${outpath}/onstat_g_ses.unl
onstat -g smb s > ./${outpath}/onstat_g_smb_s.unl
#onstat -g spi | sort -n -k 2 | tail -200 > ./${outpath}/onstat_g_spi.unl
onstat -g sql > ./${outpath}/onstat_g_sql.unl
onstat -g sql 0 > ./${outpath}/onstat_g_sql_0.unl
#onstat -g ssc > ./${outpath}/onstat_g_ssc.unl
#onstat -g stk >onstat_g_stk.unl
#onstat -g sts >onstat_g_sts.unl
onstat -g wai > ./${outpath}/onstat_g_wai.unl
onstat -L > ./${outpath}/onstat_bigl.unl
onstat -l > ./${outpath}/onstat_l.unl
onstat -p > ./${outpath}/onstat_p.unl
onstat -R > ./${outpath}/onstat_R.unl
onstat -u > ./${outpath}/onstat_u.unl
onstat -V > ./${outpath}/onstat_V.unl
onstat -x > ./${outpath}/onstat_x.unl
onstat -X > ./${outpath}/onstat_bigx.unl
###################################################################################
## system cmd
###################################################################################
echo ""
echo "collect instance running status using system command ......"
echo ""
echo "collect cm memory ......"
ps -aux |grep cmsm > ./${outpath}/cm_mem.unl
echo ""
echo "collect online.log last 50000 rows......"
onlinefile=`onstat -m |grep 'Message Log File' | awk '{print $4}'`
tail -50000 ${onlinefile} > ./${outpath}/online.log
echo ""
echo "collect current user env ......"
env > ./${outpath}/env.unl
echo ""
echo "collect system cpu and memory using vmstat ......"
vmstat 1 5 > ./${outpath}/vmstat.unl
echo ""
echo "##################################################################"
echo "GBase 8s Database Health Check Finshed"
echo "tar all of the output files in path: ${outpath}"
echo "tar -cvf ${outpath}.tar ${outpath} "
echo "##################################################################"
###################################################################################
## end of all
###################################################################################

执行方式:

1
2
chmod +x GBase8schk.sh
sh GBase8schk.sh

生成的巡检文件为一个 tar 包。