-
Notifications
You must be signed in to change notification settings - Fork 0
/
db2alias
executable file
·652 lines (568 loc) · 19.5 KB
/
db2alias
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
#!/bin/bash
#############################################################################
#
#author : 黄柱星 [email protected]
#create time : 2017-09-28 17:45
#version : 0.1
#############################################################################
#
# NAME: db2alias
#
# FUNCTION: db2alias - print all command
#
#############################################################################
OSTYPE=`uname`; #OS类型
HOSTNAME=`hostname`; #主机名
WHOAMI=`whoami`; #当前用户
INSTANCE=`whoami`; #当前实例用户
[[ -f ~/sqllib/db2profile ]] && . ~/sqllib/db2profile ;
BASE_PATH=/etc ; #$(cd `dirname ${0}`; pwd)
CACHE_FILE=/tmp/db2alias.`hostname`.`whoami`.cache ;
CACHE_FILE_TMP=${CACHE_FILE}.tmp ;
[[ -f ${CACHE_FILE} ]] && cat ${CACHE_FILE} |awk -F'|' '{print $1}' > ${CACHE_FILE_TMP} && . ${CACHE_FILE_TMP} && rm -f ${CACHE_FILE_TMP} ;
DFT_DB2HOME_LIST=( #DB2的安装位置(当找不到db2ls时到此列表中路径find)
'/usr/local/bin/'
);
#################定义颜色的变量#################
RED_COLOR='\E[1;31m'; #红
GREEN_COLOR='\E[1;32m'; #绿
YELOW_COLOR='\E[1;33m'; #黄
BLUE_COLOR='\E[1;34m'; #蓝
PINK='\E[1;35m'; #粉红
RES='\E[0m'; #重置
#################定义颜色的变量#################
function ColorFont(){
#30:黑色字
#31:红色字
#32:绿色字
#33:黄色字
#34:蓝色字
#35:紫色字
#36:天蓝字
#37:白色字
text=${1} ;
color=${2-${RED_COLOR}} ;
echo -n "${color}${text}${RES}" ;
}
function PrintTitle(){
total_len=80;
title_len=${#1};
belife_len=$(( (total_len - 2 - title_len)/2 ))
#printf "%.s#" {1..${total_len}} && echo;
for (( i=1;i<=${total_len};i++ )) do echo -n '#' ; done && echo;
echo -n '#' && for (( i=1;i<=${belife_len};i++ )) do echo -n ' ' ; done && echo -n ${1} && for (( i=1;i<=${belife_len};i++ )) do echo -n ' ' ; done ;
(( belife_len * 2 + 2 + title_len < total_len )) && echo ' #' || echo '#' ;
for (( i=1;i<=${total_len};i++ )) do echo -n '#' ; done && echo;
}
#ServerList=("Centos7Bases")
#function Server(){
#
#}
function __init__(){
ARGS=`getopt -o u::l::v::h:: --long upgrade::,load::,version::,help:: -n 'db2alias' -- "$@"`;
[ $? != 0 ] && return ;
eval set -- "${ARGS}" ;
while true
do
[[ $1 != "" ]] && echo $1 && shift || break ;
done ;
}
#__init__ $@ ;
if which db2ls 1>&2 &> /dev/null ; then
echo -e `ColorFont 'db2alias ready!' ${GREEN_COLOR}` ;
else
for db2home in ${DFT_DB2HOME_LIST[@]}; do
echo ${db2home} ;
done;
echo "db2ls env not found!";
fi;
function DB2Alias(){
cat /etc/db2alias|grep '^function '|grep -v grep | while read line
do
echo $line | awk -F'(' '{print $1}' | awk -F' ' '{print $NF}';
done ;
cat /etc/db2alias|grep '^alias '|grep -v grep | while read line
do
echo $line | awk -F'=' '{print $1}' | awk -F' ' '{print $NF}';
done ;
}
alias db2alias="DB2Alias|sort" ;
function ReloadDB2Alias() {
echo 'Loading..';
>${CACHE_FILE} ;
SelectDefaultDB;
[[ -f ${BASE_PATH}/db2alias ]] && . ${BASE_PATH}/db2alias;
}
function GetCurrTimestamp(){
fmt=${1-"%Y-%m-%d %H:%M:%S"} ;
date "+${fmt}" ;
}
function SetVal(){
#cache format : keyname=values|create_or_update timstamp(date "+%Y-%m-%d %H:%M:%S")
[[ ${1} == "" || ${2} == "" ]] && return ;
[[ ! -f ${CACHE_FILE} ]] && touch ${CACHE_FILE} ;
key=${1} ;
values=${2} ;
interval_sec=${3-1}; #default > 1 sec,update
data="${key}=${values}" ;
cur_time=`GetCurrTimestamp` ;
text="${data}|${cur_time}" ;
line=`grep "^${key}=" ${CACHE_FILE}` ;
if [[ ${line} != "" ]]; then
cutime=`echo ${line}|awk -F"|" '{print $2}'` ;
first_stamp=`date -d "${cutime}" +%s` ;
cur_stamp=`date -d "${cur_time}" +%s` ;
if (( $(( ${cur_stamp} - ${first_stamp} )) > ${interval_sec} )) ; then
sed -i "s/${line}/${text}/g" ${CACHE_FILE};
fi;
else
echo ${text} >> ${CACHE_FILE} ;
fi;
}
function GetVal(){
[[ ${1} == "" ]] && return ;
[[ ! -f ${CACHE_FILE} ]] && return ;
key=${1} ;
line=`grep "^${key}=" ${CACHE_FILE}` ;
if [[ ${line} != "" ]]; then
echo ${line}|awk -F"|" '{print $1}' |awk -F"=" '{print $2}';
fi;
}
function SysConfirm(){
PS3=${1-"Are you sure to continue(Y/N)?"}
YANDN=("Y" "N");
select var in ${YANDN[@]}
do
[[ ${var} == "" ]] && continue ;
if [[ $var == "N" ]] ; then
false || return;
fi;
[[ $var == "Y" ]] && true && return;
done ;
}
function TestPortActive(){
SERVER=localhost ;
PORT=${1-50001} ;
</dev/tcp/$SERVER/$PORT ;
if [ "$?" -ne 0 ] ; then
false;
return 1;
else
true;
return 0;
fi;
}
function DB2S(){
ARGS=`getopt -o pi:h:: --long prompt,instance:,help:: -n 'db2s' -- "$@"` ;
[ $? != 0 ] && return ;
eval set -- "${ARGS}" ;
> ${CACHE_FILE_TMP}.3;
inst_arr=();
inst_index=0;
db2ls |awk 'NR>3' > ${CACHE_FILE_TMP}.1 ;
while read line
do
db2_install_path=$(echo ${line}|awk '{print $1}') ;
db2_install_path_ver=$(echo ${line}|awk '{print $2}') ;
echo -e `ColorFont "install path(version):${db2_install_path}(${db2_install_path_ver})" ${YELOW_COLOR}` >> ${CACHE_FILE_TMP}.3;
${db2_install_path}/instance/db2ilist > ${CACHE_FILE_TMP}.2 ;
while read inst
do
service_port=`GetVal SERVICE_PORT` ;
if [[ ${service_port} == "" ]] ; then
service_port=`grep DB2c${inst} /etc/services|tail -1 |awk '{print $2}'` ;
SetVal SERVICE_PORT ${service_port%/*} ;
fi;
TestPortActive ${service_port%/*} 1>&2 &> /dev/null ;
status=`[[ $? == "0" ]] && echo "Listen" || echo "Stop"` ;
if [[ ${status} == "Listen" ]]; then
conn_num=`netstat -na|egrep ':${service_port%/*}.*ESTABLISHED' |wc -l` ;
echo -e "INSTANCE:`ColorFont ${inst} ${GREEN_COLOR}` PORT:`ColorFont ${service_port} ${GREEN_COLOR}` STATUS:`ColorFont \"${status}(${conn_num})\" ${GREEN_COLOR}`" >> ${CACHE_FILE_TMP}.3;
else
echo -e "INSTANCE:`ColorFont ${inst}` PORT:`ColorFont ${service_port}` STATUS:`ColorFont ${status}`" >> ${CACHE_FILE_TMP}.3;
fi;
inst_index=$[ inst_index + 1 ];
inst_arr[${inst_index}]=${inst};
done <${CACHE_FILE_TMP}.2 ;
done<${CACHE_FILE_TMP}.1 ;
[[ -f ${CACHE_FILE_TMP}.1 ]] && rm -f ${CACHE_FILE_TMP}.1 ;
[[ -f ${CACHE_FILE_TMP}.2 ]] && rm -f ${CACHE_FILE_TMP}.2 ;
if [[ `whoami` != "root" ]] ; then
cat ${CACHE_FILE_TMP}.3 | while read line
do
echo -e ${line};
done ;
echo
return ;
fi;
while true
do
case "$1" in
-p|--prompt)
PS3="Please select an instance:";
select var in ${inst_arr[@]}
do
[[ ${var} == "" ]] && continue ;
id ${var} 1>&2 &> /dev/null && su - ${var} || echo "instance ${var} not found!" ;
return;
done ;
break;
;;
-i|--instance)
id $2 1>&2 &> /dev/null && su - $2 || echo "instance $2 not found!" ;
return;
;;
-h|--help)
#USAGE;
echo "db2s [-p|--prompt] [-i|--instance <instname>] [-h|--help]";
return;
;;
--)
shift ;
break ;
;;
*)
echo "Internal error!"
return;
;;
esac;
done;
cat ${CACHE_FILE_TMP}.3 | while read line
do
echo -e ${line};
done ;
echo
[[ -f ${CACHE_FILE_TMP}.3 ]] && rm -f ${CACHE_FILE_TMP}.3 ;
}
alias db2s="DB2S";
if ! which db2 1>&2 &> /dev/null ; then
return;
fi
function SelectDefaultDB(){
DBNAME_LIST=(`db2 list db directory |egrep "Database name.*=" |sort|uniq|awk -F'=' '{gsub(/^[ \t]+/,"",$2); print $2}'` );
if (( ${#DBNAME_LIST[@]} > 1 )); then
DBNANE_LIST_SRT="";
for db in ${DBNAME_LIST[@]}
do
DBNAME_LIST_STR="${DBNAME_LIST_STR},${db}";
done;
SetVal DBNAME_LIST ${DBNAME_LIST_STR:1} ;
PS3="Please select an default database:";
select var in ${DBNAME_LIST[@]}
do
[[ ${var} == "" ]] && continue ;
DFT_DBNAME=${var};
break;
done ;
else
DFT_DBNAME=${DBNAME_LIST};
fi ;
[[ ${DFT_DBNAME} != "" ]] && SetVal DFT_DBNAME ${DFT_DBNAME} ;
}
if [[ ! ${DFT_DBNAME} || ${DFT_DBNAME} == "" ]] ; then
SelectDefaultDB;
fi;
#############################################################################
#list info
function ListDB(){
db2 list database directory;
}
alias listdb="ListDB";
function ConnDB(){
echo "connect to ${DFT_DBNAME} $@";
}
alias conndb=" db2 \"`ConnDB $@`\"";
alias condb=" db2 \"`ConnDB $@`\"";
function DB2TopX(){
db2top -d ${DFT_DBNAME} $@;
}
alias db2topx="DB2TopX" ;
function DB2LookX(){
db2look -d ${DFT_DBNAME} $@;
}
alias db2lookx="DB2LookX";
function DB2PdX(){
db2pd -d ${DFT_DBNAME} $@;
}
alias db2pdx="DB2PdX";
function ListApp(){
echo "list applications $@";
}
alias listapps="db2 \"` ListApp $@ `\"" ;
function ListUtil(){
db2 list utilities $@;
}
alias listutil="ListUtil";
function ListUtilX(){
ListUtil show detail;
}
alias listutilx="ListUtilX";
function ListTables(){
echo "list tables $@";
}
alias listtabs="db2 \"`ListTables $@ `\"" ;
function ListColumns(){
echo "select varchar(
trim(char(colno)) concat '.' concat trim(varchar(tabschema,64)) concat '.' concat trim(varchar(tabname,128)) concat '.' concat trim(varchar(colname,128)),80 ) as colinfo,
varchar(varchar(typename,25) concat '(' concat trim(char(length)) concat ',' concat trim(char(scale)) concat ')',25) as datatype,
varchar(case when nulls = 'Y' and numnulls > -1 then 'Y(' concat trim(char(numnulls)) concat ')' else 'N' end,10) as nullinfo ,
varchar(trim(char(colcard)) concat '\' concat trim(char(avgcollen)) ,18) as colcard_avgcollen
from syscat.columns where 1=1
order by tabschema,tabname,colno
";
}
alias listcols="db2 \"`ListColumns $@ `\"" ;
function ListPkg(){
echo "list packages $@";
}
alias listpkg="db2 \"`ListPkg $@ `\"";
function ListPkgAndRoute(){
echo "with t(bschema,bname,rouname) as (
select varchar(bschema,16),varchar(bname,20),varchar(procname,64) from SYSCAT.PROCEDURES a join sysibm.sysdependencies b on a.SPECIFICNAME=b.DNAME where BTYPE ='K'
union
select varchar(bschema,16),varchar(bname,20),varchar(funcname,64) from SYSCAT.FUNCTIONS a join sysibm.sysdependencies b on a.SPECIFICNAME=b.DNAME where BTYPE ='K'
order by 1
) select * from t ${@} " #> ${CACHE_FILE_TMP} ;
#cat ${CACHE_FILE_TMP} && [[ -f ${CACHE_FILE_TMP} ]] && rm -f ${CACHE_FILE_TMP} ;
}
alias listpkgandroute="db2 \"`ListPkgAndRoute $@ `\"" ;
function DBCfg(){
db2 get db cfg for ${DFT_DBNAME} ;
}
function DBMCfg(){
db2 get dbm cfg ;
}
function HadrStatus(){
db2pdx -hadr ;
DBCfg |grep -i hadr ;
egrep "hadr.*${INSTANCE}" /etc/services ;
}
function OnLineBackup(){
db2 -v backup database ${DFT_DBNAME} online compress include logs
}
function OffLineBackup(){
db2 backup database ${DFT_DBNAME} compress ;
}
function SetHadrCfg(){
[[ ${1} == "" || ${2} == "" ]] && echo "arg error!pls input : SetHadrCfg [primary|standby] <remote_hostname|remote_ip>" && return;
if [[ $1 == 'primary' ]] ; then
inst_port=`GetVal SERVICE_PORT`
hadr_local_svc=$(( ${inst_port} + 1000 ));
hadr_remote_svc=$(( ${inst_port} + 2000 ));
fi;
if [[ $1 == 'standby' ]]; then
inst_port=`GetVal SERVICE_PORT`
hadr_local_svc=$(( ${inst_port} + 2000 ));
hadr_remote_svc=$(( ${inst_port} + 1000 ));
fi;
echo "echo hadr_l_${INSTANCE} ${hadr_local_svc}/tcp >> /etc/services" ;
echo "echo hadr_r_${INSTANCE} ${hadr_remote_svc}/tcp >> /etc/services" ;
echo "db2 update db cfg for ${DFT_DBNAME} using HADR_LOCAL_HOST ${HOSTNAME} HADR_LOCAL_SVC hadr_l_${INSTANCE} HADR_REMOTE_HOST $2 HADR_REMOTE_SVC hadr_r_${INSTANCE} HADR_REMOTE_INST ${INSTANCE} LOGINDEXBUILD ON ";
}
function GetDBMCfg(){
echo "get dbm cfg $@ ";
}
alias getdbmcfg="db2 \"`GetDBMCfg $@`\"";
function GetDBCfg(){
echo "get db cfg for ${DFT_DBNAME} $@ ";
}
alias getdbcfg="db2 \"`GetDBCfg $@ `\"";
function GetActiveLogs(){
db2 "select varchar(a.DB_NAME,20) db_name,a.LOG_UTILIZATION_PERCENT, a.TOTAL_LOG_USED_KB, a.TOTAL_LOG_AVAILABLE_KB, a.TOTAL_LOG_USED_TOP_KB,a.DBPARTITIONNUM as parnum,a.MEMBER from sysibmadm.LOG_UTILIZATION a with ur " ;
db2pdx -logs ;
}
function GetWaitSql(){
echo "SELECT MEMBER,
NUM_EXECUTIONS,
STMT_EXEC_TIME,
decimal((TOTAL_ACT_WAIT_TIME / double(STMT_EXEC_TIME)) * 100, 5, 2) as pct_wait,
decimal((POOL_READ_TIME / double(STMT_EXEC_TIME)) * 100, 5, 2) as pct_read,
decimal((LOCK_WAIT_TIME/double(STMT_EXEC_TIME)) * 100, 5, 2) as pct_lock,
decimal((LOG_DISK_WAIT_TIME / double(STMT_EXEC_TIME)) * 100, 5, 2) as pct_log,
decimal((TOTAL_SECTION_SORT_TIME / double(STMT_EXEC_TIME)) * 100, 5, 2) as pct_sort,
CAST(FLOAT(STMT_EXEC_TIME)/FLOAT(NUM_EXECUTIONS) as decimal(10,3)) as AVG_EXEC_TIME,
substr(STMT_TEXT,1,500) AS STMT_TEXT
FROM TABLE(MON_GET_PKG_CACHE_STMT(NULL,NULL,NULL,-2))
WHERE NUM_EXECUTIONS >1 and STMT_EXEC_TIME>0 with ur " ;
}
alias getwaitsql="db2 \"`GetWaitSql`\""
function UpdateDBMCfg(){
db2 -v update dbm cfg using $@ ;
}
function UpdateDBCfg(){
db2 -v update db cfg for ${DFT_DBNAME} using $@ ;
}
function DeactivateDB(){
db2 deactivate database ${DFT_DBNAME} ;
}
function ActivateDB(){
db2 activate database ${DFT_DBNAME} ;
}
function HadrPrimary(){
db2 start hadr on database ${DFT_DBNAME} as primary ;
}
function HadrStandby(){
db2 start hadr on database ${DFT_DBNAME} as standby ;
}
function HadrTakeOver(){
db2 takeover hadr on database ${DFT_DBNAME} $@ ;
}
function HadrTakeOverByForce(){
HadrTakeOver by force PEER WINDOW ONLY;
}
function HadrStatus(){
PrintTitle "db2set cfg"
db2set -all |grep -i hadr ;
echo && PrintTitle "etc services cfg"
egrep "hadr.*${INSTANCE}" /etc/services ;
echo && PrintTitle "db cfg"
db2 get db cfg for ${DFT_DBNAME} | grep -i hadr ;
echo && PrintTitle "db2pd status"
db2pdx -hadr ;
}
function HadrStop(){
db2 stop hadr on database ${DFT_DBNAME} ;
}
#############################################################################
#set current
function SetSchema(){
[[ $1 == "" ]] && echo 'schema name is null!' && return ;
db2 -v set current schema $1 ;
}
#############################################################################
#tools
alias db2explnx="db2expln -database ${DFT_DBNAME} -g -i -t " ;
function DB2ExplnS(){
> ${CACHE_FILE_TMP};
ARGS=`getopt -o s:q: --long schema:,statement: -n '$0' -- "$@"`;
[ $? != 0 ] && return ;
eval set -- "${ARGS}" ;
schema="";
while true
do
case "$1" in
-s|--schema)
schema=$2;
echo "schema:"$schema;
shift ;
;;
-q|--statement)
statement=$2;
echo "statement:"$statement;
shift ;
;;
--)
shift ;
break ;
;;
*)
shift;
;;
esac;
done;
[[ ${schema} != "" ]] && echo "set schema ${schema}" > ${CACHE_FILE_TMP} ;
echo ${statement} >> ${CACHE_FILE_TMP};
db2explnx -stmtfile ${CACHE_FILE_TMP};
[[ -f ${CACHE_FILE_TMP} ]] && rm -f ${CACHE_FILE_TMP} ;
}
alias myexplnq="DB2ExplnS";
function DB2ExfmtS(){
db2 explain plan with snapshot for "$1" && db2exfmt -d ${DFT_DBNAME} -1 -t ;
}
alias myexpfmtq="DB2ExfmtS";
function DB2ExplnR(){
ARGS=`getopt -o s:p:n:r: --long schema:,package:,section:,routine: -n '$0' -- "$@"`;
[ $? != 0 ] && return ;
eval set -- "${ARGS}" ;
while true
do
case "$1" in
-s|--schema)
schema=$2;
shift ;
;;
-p|--package)
package=$2;
shift ;
;;
-r|--routine)
routine=$2;
shift ;
;;
-n|--section)
section=$2;
shift ;
;;
--)
shift ;
break ;
;;
*)
shift;
;;
esac;
done;
if [[ ${routine} != "" ]] ; then
listpkgandroute > ${CACHE_FILE_TMP} ;
grep "SQL1024N" ${CACHE_FILE_TMP} && return ;
package=`grep -i ${routine} ${CACHE_FILE_TMP} |awk '{print $2}'|tail -1` ; # > ${CACHE_FILE_TMP} ;
schema=`grep -i ${routine} ${CACHE_FILE_TMP} |awk '{print $1}'|tail -1` ;
[[ -f ${CACHE_FILE_TMP} ]] && rm -f ${CACHE_FILE_TMP};
echo "routine:"$routine;
echo "package:"$package;
fi;
if [[ ${schema} == "" ]] ; then
db2 values current schema |head -n 4|tail -1 > ${CACHE_FILE_TMP} ;
schema=`cat ${CACHE_FILE_TMP}`;
fi;
if [[ ${section} != "" ]] ; then
db2explnx -package ${package} -c ${schema} -section ${section} ;
echo "db2explnx -package ${package} -c ${schema} -section ${section} ";
else
db2explnx -package ${package} -c ${schema} ;
echo "db2explnx -package ${package} -c ${schema} ";
fi;
}
alias myexplnp="DB2ExplnR";
#############################################################################
function CreateDB2Instance(){
[[ `whoami` != 'root' ]] && echo 'only root user!' && return ;
}
function DB2SetStandard() {
if ! which db2set 1>&2 &> /dev/null ; then
echo "not instance user!";
return;
fi ;
echo "
db2set DB2COUNTRY=86
db2set DB2TERRITORY=86
db2set DB2CODEPAGE=1208
db2set DB2_LOAD_COPY_NO_OVERRIDE=NONRECOVERABLE
db2set DB2COMM=TCPIP
db2set DB2_LOGGER_NON_BUFFERED_IO=ON
db2set DB2_MDC_ROLLOUT=DEFER
db2set DB2_TRUST_MDC_BLOCK_FULL_HINT=YES
db2set DB2SORCVBUF=1048576
db2set DB2SOSNDBUF=1048576
db2set DB2_MAX_GLOBAL_SNAPSHOT_SIZE=20971520
db2set DB2RSHCMD=SSH
db2set DB2_RESTRICT_DDF=TRUE
";
SysConfirm "Are you sure to apply the following standard configuration to the current instance(Y/N)?";
[[ $? == "1" ]] && return ;
db2set DB2COUNTRY=86 ;
db2set DB2TERRITORY=86 ;
db2set DB2CODEPAGE=1208 ;
db2set DB2_LOAD_COPY_NO_OVERRIDE=NONRECOVERABLE;
db2set DB2COMM=TCPIP ;
db2set DB2_LOGGER_NON_BUFFERED_IO=ON ;
db2set DB2_MDC_ROLLOUT=DEFER ;
db2set DB2_TRUST_MDC_BLOCK_FULL_HINT=YES ;
db2set DB2SORCVBUF=1048576 ;
db2set DB2SOSNDBUF=1048576 ;
db2set DB2_MAX_GLOBAL_SNAPSHOT_SIZE=20971520 ;
db2set DB2RSHCMD=SSH ;
db2set DB2_RESTRICT_DDF=TRUE ;
db2set -all;
echo "Done!";
}