1. 程式人生 > >db2相關語句

db2相關語句

lint procedure arc insert 提交 repl exe varchar name

--創建過程並執行
CREATE or replace PROCEDURE test_hzjkqsyss (
in v_start smallint default 0,
in v_end smallint default 0
)
LANGUAGE SQL
p1:begin

DECLARE idx smallint;
DECLARE sql varchar(1000);
set idx = v_start;

fetch_loop:
loop
if idx >= v_end then
leave fetch_loop;
end if;

set sql = ‘insert into hzjkqsyss
(fdate, findate, fzqdm, fszsh, fgddm, fjyxwh, fbje, fsje, fbsl, fssl, fbyj, fsyj, fbjsf, fsjsf, fbyhs, fsyhs, fbzgf, fszgf, fbghf, fsghf, fbgzlx, fsgzlx, fhggain, fbfxj, fsfxj, fbsfje, fsssje, ffxj, fzqbz, fywbz, fqsbz, fsetcode, ftzbz, fbfy1, fsfy1, fbfy2, fsfy2, fbfy3, fsfy3, fxgr, fxgr1, zqdm, datasource, fsqbh, fcfbz, ffromset)
select fdate, findate, fzqdm, fszsh, fgddm, fjyxwh, fbje, fsje, fbsl, fssl, fbyj, fsyj, fbjsf, fsjsf, fbyhs, fsyhs, fbzgf, fszgf, fbghf, fsghf, fbgzlx, fsgzlx, fhggain, fbfxj, fsfxj, fbsfje, fsssje, ffxj, fzqbz, fywbz, fqsbz, ‘ || char(idx) || ‘, ftzbz, fbfy1, fsfy1, fbfy2, fsfy2, fbfy3, fsfy3, fxgr, fxgr1, zqdm, datasource, fsqbh, fcfbz, ffromset
from hzjkqsyss
where fdate = date‘‘2018-11-28‘‘ and fsetcode=-1‘;
prepare ps from sql;
execute ps;

set idx = idx + 1;
end loop;
end p1;

call test_hzjkqsyss(1001,1100);

--sqlstate=57016錯誤原因:修改表字段權限,此時該表處於不可用狀態
CALL SYSPROC.ADMIN_CMD(‘REORG TABLE lsetlist‘);

--當前數據庫表及數據統計
select tabname,card from syscat.tables
where tabschema = ‘DB2INST1‘ and tabname like ‘%LACCOUNT‘
order by card desc;


--查詢所有鎖表信息:
SELECT * FROM TABLE (SNAP_GET_LOCK (‘‘, -1)) AS T WHERE lock_object_type = ‘TABLE_LOCK‘

--根據agent_id進行解鎖操作:
FORCE application (162);


/*
單個事務10240*4KB=40MB 40MB*20=800 800MB*12%=96MB,直接影響事務提交數據量,批處理控制在此範圍內,否則無法執行,數據庫會強制斷開該鏈接
修改日誌文件大小(4KB):update db cfg for zsyhjj using LOGFILSIZ 10240
修改主日誌文件個數:update db cfg for zsyhjj using LOGPRIMARY 20
修改輔助日誌文件個數:update db cfg for zsyhjj using LOGSECOND 0
事務使用的最大主日誌空間的百分比: update db cfg for zsyhjj using MAX_LOG 12


單個應用表鎖升級:做大儲存量*百分比 40MB*30%=12MB
單個進程操作單標超過12MB時,表行鎖升級為表鎖,待進程執行完後表鎖狀態打開後下個進程才可對該表進行操作,直接影響,業務高峰期導致程序慢,嚴重是表死鎖頁面報錯,或數據庫鏈接超時頁面超時報錯
鎖定列表的最大存儲量 (4KB): update db cfg for zsyhjj using LOCKLIST 10240
每個應用程序的鎖定百分比列表:update db cfg for zsyhjj using MAXLOCKS 30
*/

db2相關語句