DB2表空間管理(1)—基礎篇

轉載:http://www.xifenfei.com/2012/04/db2%e8%a1%a8%e7%a9%ba%e9%97%b4%e7%ae%a1%e7%90%861.html

1.創建數據庫
[db2inst2@xifenfei ~]$ db2 “create database xifenfei automatic storage yes
on /home/db2inst2/dbauto dbpath on /home/db2inst2/xifenfei
using codeset utf-8 territory cn collate using system”

DB20000I The CREATE DATABASE command completed successfully.

DBPATH ON表示數據庫目錄
USING CONDESET codeset TERRITORY territory指定數據庫編碼集(Codeset)和區域(Territory)
automatic storage yes on /home/db2inst2/dbauto 表示啓用自動存儲管理,on指定路徑

2.查看數據庫
[db2inst2@xifenfei ~]$ db2 list db directory

System Database Directory

Number of entries in the directory = 1

Database 1 entry:

Database alias = XIFENFEI
Database name = XIFENFEI
Local database directory = /home/db2inst2/xifenfei
Database release level = c.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =

3.連接數據庫
[db2inst2@xifenfei ~]$ db2 connect to xifenfei

Database Connection Information

Database server = DB2/LINUX 9.5.0
SQL authorization ID = DB2INST2
Local database alias = XIFENFEI

4.創建緩衝池
[db2inst2@xifenfei ~]$ db2 “create bufferpool bp32k size 100 pagesize 32k”
DB20000I The SQL command completed successfully.

DB2默認創建庫指創建4k的bufferpool,因爲下面需要創建32k的表空間,所以需要先創建32k的bufferpool

5.創建數據庫管理(DMS)的數據表空間
[db2inst2@xifenfei ~]$ db2 “create large tablespace tbs_data pagesize 32k managed by database
using (file ‘/home/db2inst2/dms/tbs_data01.dbf’ 100M) extentsize 32 prefetchsize automatic
bufferpool bp32k no file system caching”

DB20000I The SQL command completed successfully.

no file system caching關閉文件系統緩存,默認選項

6.創建系統管理(SMS)的臨時表空間
[db2inst2@xifenfei ~]$ db2 “create temporary tablespace tbs_temp pagesize 32k
managed by system using (‘/home/db2inst2/xifenfei/temp’) bufferpool bp32k”

DB20000I The SQL command completed successfully.

7.創建系統管理(SMS)的用戶臨時表空間
[db2inst2@xifenfei ~]$ db2 “create user temporary tablespace tbs_user_temp pagesize 32k
managed by system using (‘/home/db2inst2/xifenfei/user_temp’) bufferpool bp32k”

DB20000I The SQL command completed successfully.

8.自動存儲管理(Automatic Storage)的表空間
[db2inst2@xifenfei ~]db2createtablespacetbsindexpagesize32kbufferpoolbp32kDB20000ITheSQLcommandcompletedsuccessfully.[db2inst2@xifenfei ] db2 “create tablespace tbs_data2 initialsize 10M increasesize 10M maxsize 10G”
DB20000I The SQL command completed successfully.

數據表空間選擇DMS,臨時表空間選擇SMS

9.查看錶空間狀態
[db2inst2@xifenfei ~]$ db2 list tablespaces show detail

       Tablespaces for Current Database

Tablespace ID = 0
Name = SYSCATSPACE
Type = Database managed space
Contents = All permanent data. Regular table space.
State = 0x0000
Detailed explanation:
Normal
Total pages = 16384
Useable pages = 16380
Used pages = 10500
Free pages = 5880
High water mark (pages) = 10500
Page size (bytes) = 4096
Extent size (pages) = 4
Prefetch size (pages) = 4
Number of containers = 1

Tablespace ID = 1
Name = TEMPSPACE1
Type = System managed space
Contents = System Temporary data
State = 0x0000
Detailed explanation:
Normal
Total pages = 1
Useable pages = 1
Used pages = 1
Free pages = Not applicable
High water mark (pages) = Not applicable
Page size (bytes) = 4096
Extent size (pages) = 32
Prefetch size (pages) = 32
Number of containers = 1

Tablespace ID = 2
Name = USERSPACE1
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Total pages = 8192
Useable pages = 8160
Used pages = 96
Free pages = 8064
High water mark (pages) = 96
Page size (bytes) = 4096
Extent size (pages) = 32
Prefetch size (pages) = 32
Number of containers = 1

Tablespace ID = 3
Name = TBS_DATA
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Total pages = 3200
Useable pages = 3168
Used pages = 96
Free pages = 3072
High water mark (pages) = 96
Page size (bytes) = 32768
Extent size (pages) = 32
Prefetch size (pages) = 32
Number of containers = 1

Tablespace ID = 4
Name = TBS_TEMP
Type = System managed space
Contents = System Temporary data
State = 0x0000
Detailed explanation:
Normal
Total pages = 1
Useable pages = 1
Used pages = 1
Free pages = Not applicable
High water mark (pages) = Not applicable
Page size (bytes) = 32768
Extent size (pages) = 32
Prefetch size (pages) = 32
Number of containers = 1

Tablespace ID = 5
Name = TBS_USER_TEMP
Type = System managed space
Contents = User Temporary data
State = 0x0000
Detailed explanation:
Normal
Total pages = 1
Useable pages = 1
Used pages = 1
Free pages = Not applicable
High water mark (pages) = Not applicable
Page size (bytes) = 32768
Extent size (pages) = 32
Prefetch size (pages) = 32
Number of containers = 1

Tablespace ID = 6
Name = TBS_INDEX
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Total pages = 1024
Useable pages = 992
Used pages = 96
Free pages = 896
High water mark (pages) = 96
Page size (bytes) = 32768
Extent size (pages) = 32
Prefetch size (pages) = 32
Number of containers = 1

Tablespace ID = 7
Name = TBS_DATA2
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Total pages = 2560
Useable pages = 2528
Used pages = 96
Free pages = 2432
High water mark (pages) = 96
Page size (bytes) = 4096
Extent size (pages) = 32
Prefetch size (pages) = 32
Number of containers = 1

10.查看錶空間和容器相關信息
[db2inst2@xifenfei ~]$ db2 list tablespace containers for 6 show detail

        Tablespace Containers for Tablespace 6

Container ID = 0
Name = /home/db2inst2/dbauto/db2inst2/NODE0000/XIFENFEI/T0000006/C0000000.LRG
Type = File
Total pages = 1024
Useable pages = 992
Accessible = Yes

11.顯示錶空間配置信息/使用信息/容器信息
[db2inst2@xifenfei ~]$ db2pd -d xifenfei -tablespaces

Database Partition 0 – Database XIFENFEI – Active – Up 0 days 01:07:23

Tablespace Configuration:
Address Id Type Content PageSz ExtentSz Auto Prefetch BufID BufIDDisk FSC NumCntrs MaxStripe LastConsecPg Name
0x9F43E060 0 DMS Regular 4096 4 Yes 4 1 1 Off 1 0 3 SYSCATSPACE
0x9F43E6B0 1 SMS SysTmp 4096 32 Yes 32 1 1 On 1 0 31 TEMPSPACE1
0x9F442EB0 2 DMS Large 4096 32 Yes 32 1 1 Off 1 0 31 USERSPACE1
0x9F73B2E0 3 DMS Large 32768 32 Yes 32 2 2 Off 1 0 31 TBS_DATA
0x9FAFE320 4 SMS SysTmp 32768 32 Yes 32 2 2 On 1 0 31 TBS_TEMP
0x9FB029B0 5 SMS UsrTmp 32768 32 Yes 32 2 2 On 1 0 31 TBS_USER_TEMP
0x9FB05420 6 DMS Large 32768 32 Yes 32 2 2 Off 1 0 31 TBS_INDEX
0x9FB0BB20 7 DMS Large 4096 32 Yes 32 1 1 Off 1 0 31 TBS_DATA2

Tablespace Statistics:
Address Id TotalPgs UsablePgs UsedPgs PndFreePgs FreePgs HWM State MinRecTime NQuiescers
0x9F43E060 0 16384 16380 10500 0 5880 10500 0x00000000 0 0
0x9F43E6B0 1 1 1 1 0 0 0 0x00000000 0 0
0x9F442EB0 2 8192 8160 96 0 8064 96 0x00000000 0 0
0x9F73B2E0 3 3200 3168 96 0 3072 96 0x00000000 0 0
0x9FAFE320 4 1 1 1 0 0 0 0x00000000 0 0
0x9FB029B0 5 1 1 1 0 0 0 0x00000000 0 0
0x9FB05420 6 1024 992 96 0 896 96 0x00000000 0 0
0x9FB0BB20 7 2560 2528 96 0 2432 96 0x00000000 0 0

Tablespace Autoresize Statistics:
Address Id AS AR InitSize IncSize IIP MaxSize LastResize LRF
0x9F43E060 0 Yes Yes 33554432 -1 No None None No
0x9F43E6B0 1 Yes No 0 0 No 0 None No
0x9F442EB0 2 Yes Yes 33554432 -1 No None None No
0x9F73B2E0 3 No No 0 0 No 0 None No
0x9FAFE320 4 No No 0 0 No 0 None No
0x9FB029B0 5 No No 0 0 No 0 None No
0x9FB05420 6 Yes Yes 33554432 -1 No None None No
0x9FB0BB20 7 Yes Yes 10485760 10485760 No -2147483648 None No

Containers:
Address TspId ContainNum Type TotalPgs UseablePgs StripeSet Container
0x989BDE10 0 0 File 16384 16380 0 /home/db2inst2/dbauto/db2inst2/NODE0000/XIFENFEI/T0000000/C0000000.CAT
0x9F43ED00 1 0 Path 1 1 0 /home/db2inst2/dbauto/db2inst2/NODE0000/XIFENFEI/T0000001/C0000000.TMP
0x9F443500 2 0 File 8192 8160 0 /home/db2inst2/dbauto/db2inst2/NODE0000/XIFENFEI/T0000002/C0000000.LRG
0x9F73B930 3 0 File 3200 3168 0 /home/db2inst2/dms/tbs_data01.dbf
0x9F73DE90 4 0 Path 1 1 0 /home/db2inst2/xifenfei/temp
0x9FB05020 5 0 Path 1 1 0 /home/db2inst2/xifenfei/user_temp
0x9FB0B4A0 6 0 File 1024 992 0 /home/db2inst2/dbauto/db2inst2/NODE0000/XIFENFEI/T0000006/C0000000.LRG
0x9FB0C170 7 0 File 2560 2528 0 /home/db2inst2/dbauto/db2inst2/NODE0000/XIFENFEI/T0000007/C0000000.L

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章