DB2 9.7 - how to release unused space back to the OS?
-
03-10-2020 - |
سؤال
I am looking for a clear set of instructions on how to release unused space back to the operating system from a DB2 9.7 instance running on a Windows box. IBM's docs might be great if you already knew and just needed a reminder but to someone who's primary role is not DB2 support they might as well be greek.
If I read through it all correctly, in theory this is supposed to do the trick:
alter tablespace userspace1 lower high water mark;
alter tablespace userspace1 reduce max;
In practice, I would have accomplished more and been a little happier if I had simply stepped out for coffee.
This is an FAQ in DB2 land, whose answers have tended to the cryptic - probably because most DB2 DBA's are primarily or solely DB2 DBA's.
I am hoping (probably in vain) that there's some place I missed that I can right-click and choose "shrink database", in which case I'm a little embarrassed and someone gets some easy rep.
Tablespace specifics:
Tablespace ID = 2
Name = USERSPACE1
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Total pages = 83320832
Useable pages = 83320800
Used pages = 16096
Free pages = 83304704
High water mark (pages) = 45397248
Page size (bytes) = 4096
Extent size (pages) = 32
Prefetch size (pages) = 32
Number of containers = 1
Minimum recovery time = 2016-08-22-15.32.02.000000
db2pd output:
Tablespace Configuration:
Address Id Type Content PageSz ExtentSz Auto Prefetch BufID BufIDDisk FSC NumCntrs MaxStripe LastConsecPg Name
0x000000003B4B1F60 0 DMS Regular 4096 4 Yes 4 1 1 Off 1 0 3 SYSCATSPACE
0x000000003B4B36E0 1 SMS SysTmp 4096 32 Yes 32 1 1 On 1 0 31 TEMPSPACE1
0x000000003B4B6E20 2 DMS Large 4096 32 Yes 32 1 1 Off 1 0 31 USERSPACE1
0x000000003B4B85A0 3 DMS Large 4096 4 Yes 4 1 1 Off 1 0 3 SYSTOOLSPACE
0x000000003B4B9D20 4 DMS Large 32768 16 No 32 2 2 Off 1 0 15 XXXXXXXXEBIG
0x000000003B4BB4A0 5 SMS SysTmp 32768 16 No 16 2 2 On 1 0 15 XXXXXXXXETEMP
Tablespace Statistics:
Address Id TotalPgs UsablePgs UsedPgs PndFreePgs FreePgs HWM Max HWM State MinRecTime NQuiescers PathsDropped
0x000000003B4B1F60 0 32768 32764 26628 0 6136 26628 26628 0x00000000 0 0 No
0x000000003B4B36E0 1 1 1 1 0 0 0 0 0x00000000 0 0 No
0x000000003B4B6E20 2 45397280 45397248 15680 416 45381152 45397248 83319520 0x00000000 1471879922 0 No
0x000000003B4B85A0 3 8192 8188 160 0 8028 160 160 0x00000000 1462319023 0 No
0x000000003B4B9D20 4 304 288 272 0 16 288 304 0x00000000 1471348087 0 No
0x000000003B4BB4A0 5 1 1 1 0 0 0 0 0x00000000 1462325615 0 No
Tablespace Autoresize Statistics:
Address Id AS AR InitSize IncSize IIP MaxSize LastResize LRF
0x000000003B4B1F60 0 Yes Yes 33554432 -1 No None None No
0x000000003B4B36E0 1 Yes No 0 0 No 0 None No
0x000000003B4B6E20 2 Yes Yes 33554432 -1 No None None No
0x000000003B4B85A0 3 Yes Yes 33554432 -1 No None None No
0x000000003B4B9D20 4 Yes Yes 33554432 -1 No None None No
0x000000003B4BB4A0 5 Yes No 0 0 No 0 None No
Containers:
Address TspId ContainNum Type TotalPgs UseablePgs PathID StripeSet Container
0x000000003B4B34A0 0 0 File 32768 32764 0 0 E:\DB2\NODE0000\XXXXXXXX\T0000000\C0000000.CAT
0x000000003B4B4BC0 1 0 Path 1 1 0 0 E:\DB2\NODE0000\XXXXXXXX\T0000001\C0000000.TMP
0x0000000044D1D8A0 2 0 File 45397280 45397248 0 0 E:\DB2\NODE0000\XXXXXXXX\T0000002\C0000000.LRG
0x000000003B4B9AE0 3 0 File 8192 8188 0 0 E:\DB2\NODE0000\XXXXXXXX\T0000003\C0000000.LRG
0x0000000044D35E40 4 0 File 304 288 0 0 E:\DB2\NODE0000\XXXXXXXX\T0000004\C0000000.LRG
0x000000003B4BC980 5 0 Path 1 1 0 0 E:\DB2\NODE0000\XXXXXXXX\T0000005\C0000000.TMP
المحلول
Both high water mark (HWM) reduction and container resize are background operations, so you won't see an immediate effect when the commands complete. To achieve greates effect you will need to lower HWM first, wait until it finishes (use db2pd -tablespaces
to verify), then try reducing container size. Note that you will need a slightly different syntax for non-automatic storage tablespaces: ALTER TABLESPACE USERSPACE1 REDUCE (ALL CONTAINERS <whatever size is free>)
.