一、安裝docker
https://www.ibm.com/docs/en/db2/11.5?topic=system-linux
二、導(dǎo)入數(shù)據(jù)
層級(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)。導(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