0

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.

See link: http://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.admin.dbobj.doc/doc/c0055392.html

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
  • There's no place where you can "right-click and choose 'shrink database'", so you will have to read a bit more of the manual to figure out how to do what you want to do. How do you determine there is unused space? Not sure what you mean by "returning it to the database" -- isn't it already in the database? Do you use automatic storage? What kinds of tablespaces does your database use (list tablespaces show detail)? – mustaccio Aug 22 '16 at 17:49
  • As a reference point, the "right click and choose 'shrink database'" option is how you accomplish this in SQLServer – pojo-guy Aug 22 '16 at 19:47
  • @mustaccio Thanks for poining out my typo - I want to give space back to the operating system - corrected the original question and added info about the TS in question. I know there's roughly 300 GB freed because I dropped and recreated a particular table. It helps that the tablespace shows roughly 45,000,000 unused pages – pojo-guy Aug 22 '16 at 19:50
  • Not sure where you got those 300 GB -- the entire tablespace you show is just over 20 GB in size. You didn't say if you use automatic storage or not; the commands you show would only be applicable for automatic storage. What's the output of db2pd -d <your database> -tablespaces? Both HWM reduction and container resize are background operations, so you won't see an immediate effect when the commands complete. – mustaccio Aug 22 '16 at 20:32
  • 83,000,000 * 4096 = 339,968,000,000 bytes. Which is pretty close to what the OS reports. Added output from db2pd. Since this took several weeks to add to the database, it may take some time to remove. Knowing it runs asynchronously helps. – pojo-guy Aug 22 '16 at 21:02
1

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>).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.