DB2数据库常用语句
1.快速清空大量數據表數據,但是還原不了
alter table rm_customer activate not logged initially with empty table
2.大量導出表語句
select 'db2 export from d:\exportdb\'||tabname||'.dat select * from '||tabname||';' from syscat.tables where TABSCHEMA='DB2ADMIN'
and tabname not in (select tabname from (select a.tabname, a.tbspace, a.npages*b.pagesize/1024.0/1024.0/1024.0 g , a.card --,a.*
from syscat.tables a
left join syscat.tablespaces b
on a.tbspace = b.tbspace
where a.type = 'T'
and a.tabschema = (select current schema from sysibm.sysdummy1
)) a
where a.g>0.05);
3.單表導出語句
db2 "export to FTP_ADJUST_COA.del of del select * from FTP_ADJUST_COA" 當前路徑下
4.大量導入表語句
select 'db2 import from d:\exportdb\'||tabname||'.dat of del replace into '||tabname||';' from syscat.tables where TABSCHEMA='DB2ADMIN'
and tabname not in (select tabname from (select a.tabname, a.tbspace, a.npages*b.pagesize/1024.0/1024.0/1024.0 g , a.card --,a.*
from syscat.tables a
left join syscat.tablespaces b
on a.tbspace = b.tbspace
where a.type = 'T'
and a.tabschema = (select current schema from sysibm.sysdummy1
)) a
where a.g>0.05);
5.單表導入語句
db2 import from sm_res_paractrl.del of del insert into sm_res_paractrl 當前路徑下
4229 查看表空間
db2 => list tablespaces show detail
從上述錯誤來看,是表空間NNC_INDEX01表空間被占滿了。
看下NNC_INDEX01表空間使用情況:
db2 => list tablespaces show detail
發現可用頁數已經變成了0。
查看報錯的地方,是一個綁定變量+Batch的操作。insert into IC_ATP_F,這個表有一個主鍵索引,而批量插入的時候肯定會用到索引表空間。
添加一個容器,alter tablespace nnc_index01 add (file '\db2\nnc_index01_2' 204800)
再次執行,問題解決。
4229 可能日志文件太小
連接目標數據庫,執行命令:
1.查看日志大小
db2 get db cfg|find /i "log"
2.修改日志文件大小
db2 update db cfg using LOGFILSIZ 16384
3.修改主日志文件個數
db2 update db cfg using LOGPRIMARY 24
4.修改輔助日志文件個數
db2 update db cfg using LOGSECOND 20
修改后的總大小為:16384*4K*(12+20)=2048M
5.重啟數據庫
db2stop
db2start
6.檢查日志是否修改成功
db2 get db cfg|find /i "log"
db2 -tvf createtb.sql> createtb.log
db2move HKYH import -io replace_create -u db2admin -p db2admin
DB2 SQL Error: SQLCODE=-101, SQLSTATE=54001, SQLERRMC=null, DRIVER=3.63.123
1、命令查看你的bufferpool總大小(前提,連接數據庫 connect to GXCSP)
db2 'select bpname,pagesize,npages from syscat.bufferpools'
2、在保證所有bufferpool總合不超過1G的情況下,盡量增加buffer的大小,調整bufferpool的大小。
db2 'alter bufferpool ibmdefaultbp size 51200'
這時會報錯,其實緩沖區已經修改成功。SQL20169W?The buffer pool is not started.?SQLSTATE=01654
3、重啟數據庫即可(關閉數據庫,啟動數據庫)
db2 get db cfg|find /i "locklist"
db2 update db cfg using MAXLOCKS AUTOMATIC
db2 update db cfg using LOCKLIST 524288 AUTOMATIC
db2 alter tablespace nnc_index01 add (file 'D:\DB2\NODE0000\FTP63TE\nnc_index01_2' 1G)
db2 alter tablespace nnc_index01 extend (file 'D:\DB2\NODE0000\FTP63TE\nnc_index01_2' 1G)
db2 alter tablespace nnc_index01 reduce (file 'D:\DB2\NODE0000\FTP63TE\nnc_index01_2' 1G)
?
-- 表分區------
--1 創建具有多個分區鍵列的 分區表.
drop table tab_partitions
create table tab_partitions (
acct_no varchar(20),
data_date char(10) ,
pk_run char(20) ,
busi_type varchar(3)
)
partition by range (data_date,pk_run)
(
part tab_partition_20150301_1001H610000000000KU3 STARTING ('2015-03-01','1001H610000000000KU3') INCLUSIVE ENDING ('2015-03-01','1001H610000000000KU3') INCLUSIVE,
part tab_partition_20150302_1001H610000000000KU3 STARTING ('2015-03-02','1001H610000000000KU3') INCLUSIVE ENDING ('2015-03-02','1001H610000000000KU3') INCLUSIVE,
part tab_partition_20150301_1001H610000000000KU4 STARTING ('2015-03-01','1001H610000000000KU4') INCLUSIVE ENDING ('2015-03-01','1001H610000000000KU4') INCLUSIVE,
part tab_partition_20150302_1001H610000000000KU4 STARTING ('2015-03-02','1001H610000000000KU4') INCLUSIVE ENDING ('2015-03-02','1001H610000000000KU4') INCLUSIVE
)
-- 2 查看分區表
select *
from syscat.datapartitions a
where a.tabname = upper('tab_partitions')
-- 3 添加分區
alter table tab_partitions add part tab_partition_20150303_1001H610000000000KU3 STARTING ('2015-03-03','1001H610000000000KU3') INCLUSIVE ENDING ('2015-03-03','1001H610000000000KU3') INCLUSIVE
-- 4 拆離分區 (注,分區的拆離是個異步的過程)
alter table tab_partitions detach part tab_partition_20150301_1001H610000000000KU3 into tab_partition_20150301_1001H610000000000KU3
-- 4 拆離分區 (注,分區的拆離是個異步的過程)//db2 97 以后版本,異步處理機制規避,先刪除ftp_res_acct_his_bk,然后把ftp_res_acct_his剝離分區成ftp_res_acct_his_bk,下次再刪除此表。
alter table tab_partitions detach partition tab_partition_20150301_1001H610000000000KU3 into new_table
drop table new_table
-- SELECT * FROM tab_partition_20150301_1001H610000000000KU3
-- 5 將一個獨立的表添加到分區表中
create table tab_partition_01 (
acct_no varchar(20),
data_date char(10) ,
pk_run char(20) ,
busi_type varchar(3)
)
-- 往表里插入數據
insert into tab_partition_01(acct_no,data_date,pk_run,busi_type)
values('20160621122332000001','2015-03-04','1001H610000000000KU3','3')
-- 查看插入的數據
select *
from tab_partition_01
-- 合并表到分區表
ALTER TABLE
tab_partitions ATTACH PARTITION tab_partition_20150304_1001H610000000000KU3 STARTING ('2015-03-04','1001H610000000000KU3') INCLUSIVE
ENDING ('2015-03-04','1001H610000000000KU3') INCLUSIVE
FROM
tab_partition_01
-- 查看分區表
-- 會發現新增加的分區的數據,在分區表中不可見。用最后的語句,執行完整性檢查 。
select *
from tab_partitions
-- 查看分區表字典
select b.datapartitionname,b.tabname,b.access_mode,b.status,b.lowvalue,b.highvalue
from syscat.DATAPARTITIONS b
where b.TABNAME = upper('tab_partitions')
-- 執行 設置完整性
set integrity for tab_partitions allow write access immediate checked
>db2 "set integrity for tab_partitions allow write access immediate checked"
-- 6、分區表索引
from t_student m
select *
from syscat.indexpartitions
create index idx1_tab_partitions on tab_partitions (acct_no)
轉載于:https://www.cnblogs.com/simon6623/p/8663759.html
總結
以上是生活随笔為你收集整理的DB2数据库常用语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 达克宁多少钱啊?
- 下一篇: 橱柜模压门价格多少钱一平方