db2 使用指北

一、安裝docker

https://www.ibm.com/docs/en/db2/11.5?topic=system-linux

二、導(dǎo)入數(shù)據(jù)

  1. 層級(jí)概念: database > schema > table
    db2 docker啟動(dòng)時(shí)創(chuàng)建了一個(gè)默認(rèn)的database名字叫testdb,導(dǎo)入數(shù)據(jù)時(shí)盡量都導(dǎo)入這個(gè)database,因?yàn)閐b2 的database是一個(gè)很大的概念,與Oracle類似,有點(diǎn)像一個(gè)可拔插磁盤(pán)的感覺(jué),創(chuàng)建一個(gè)新的數(shù)據(jù)庫(kù)開(kāi)銷比較大,盡量不要?jiǎng)?chuàng)建新的。在database下面有叫做schema的命名空間,不同的schema里面可以有相同的table名字,這樣可以把不同的數(shù)據(jù)集分隔開(kāi)來(lái)。

  2. 導(dǎo)入命令

# 1. connect to database testdb 
db2 connect to testdb

# 2. create a new schema namespace s1
db2 "create schema s1;"
db2 "set current schema s1;"

# 3. create tables
# first method 
db2 "create table s1_table1 ( a int, b int );"
# second method
db2 "create table s1.s1_table1 ( a int , b int) ;"
# third method: +c quite output, -t semi-comma separated, -f read sql queries from file
db2 +c -tf schema.sql 

# 4. load data
# COLDEL| means '|' is the delimiter character
for f in *.csv; do
  barename=$(basename $f)
  barebarename=$(basename $f .csv)
  db2 +c "IMPORT FROM '$barename' OF DEL MODIFIED BY COLDEL| INSERT INTO $barebarename" 
done

三、啟動(dòng)與關(guān)閉

# show all the connected applications
db2 list applications 
# force all the applications stop
db2 force applications all
# stop db2
db2stop
# start db2
db2start 

四、修改配置文件

db2每insert一條record就會(huì)寫(xiě)一條日志,如果有constraint甚至?xí)?xiě)多條日志,這樣導(dǎo)致日志文件增長(zhǎng)得很快。并且db2配置選項(xiàng)如log file size一開(kāi)始設(shè)置得很小,總共64MB,這樣log file就容易滿,出現(xiàn)報(bào)錯(cuò)的情況。

# check configurations
db2 GET DATABASE CONFIGURATION FOR testdb | grep 'LOGARCHMETH1'
db2 GET DATABASE CONFIGURATION FOR testdb | grep 'OVERFLOWLOGPATH'
db2 GET DATABASE CONFIGURATION FOR testdb | grep 'Path to log files'
db2 GET DATABASE CONFIGURATION FOR testdb | grep 'LOGBUFSZ'
db2 GET DATABASE CONFIGURATION FOR testdb | grep 'LOGFILSIZ'
db2 GET DATABASE CONFIGURATION FOR testdb | grep 'LOGPRIMARY'
db2 GET DATABASE CONFIGURATION FOR testdb | grep 'LOGSECOND'

# update configurations  
# 262144 * 4K = 1GB
# 16384 * 4K = 64MB
db2 update database configuration for testdb using logfilsiz 262144
db2 update database configuration for testdb using logbufsz 262144

# delete log files
db2 prune logfile prior to S0001375.LOG

五、查看一些表的結(jié)構(gòu)信息之類的

# check tables for one schema
db2 list tables for schema dsb

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容