一、安装docker
https://www.ibm.com/docs/en/db2/11.5?topic=system-linux
二、导入数据
层级概念: database > schema > table
db2 docker启动时创建了一个默认的database名字叫testdb,导入数据时尽量都导入这个database,因为db2 的database是一个很大的概念,与Oracle类似,有点像一个可拔插磁盘的感觉,创建一个新的数据库开销比较大,尽量不要创建新的。在database下面有叫做schema的命名空间,不同的schema里面可以有相同的table名字,这样可以把不同的数据集分隔开来。导入命令
# 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
三、启动与关闭
# 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就会写一条日志,如果有constraint甚至会写多条日志,这样导致日志文件增长得很快。并且db2配置选项如log file size一开始设置得很小,总共64MB,这样log file就容易满,出现报错的情况。
# 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
五、查看一些表的结构信息之类的
# check tables for one schema
db2 list tables for schema dsb