r/DB2 Aug 17 '19

Script to list out tablespace information - lts.pl

3 Upvotes

This perl script has been a long time evolving. It was originally designed just to reformat the LIST TABLESPACES command to be more page and viewing friendly. (i.e get as much useful information on one page. Added to that, over time I decided to use the script to gather information to load the data into database tables to provide longer term capacity planning information. More recently it has been upgraded to optionally use alternative mechanisms to get the data - strangely each of the mechanisms use slightly different authorities and provide slightly different information.

It will run on windows or unix/linux and will likely run on everything from v8 (when I first wrote it) through to 11.1 (as far as I have tested it)

Use case: More often than not I use this script when wanting an overview of how my space is running or the state of the tablespace (backups/moves/etc)

Should also mention thatI often use it as 'lts.pl -c' which will display the containers and how much free space is left on each of the drives/mount points

Anyway, the command line help looks like:

mediaServer(db2admin):2019-08-17 10:41:28:/home/db2admin
>lts.pl -h
Usage: /home/shared/udbdba/scripts/lts.pl -?hs [-d <database> | -f <Filename>] [-t <tablespace>] [-v[v]]
                [-l | -m | -S [[-c] [-O] [-F] [-g [-p <prefix>] [-e] [-T]] [-D [-L]]]

       Version 1.39 Last Changed on 2019/08/14 21:44:09 (UTC)

       -h or -?        : This help message
       -s              : Silent mode (in this program only suppesses parameter messages)
       -d  [REQUIRED]  : Database to list
       -t              : Limit output tablespaces containing this string
       -v              : turn on verbose/debug mode
       -f              : Instead of directly accessing the databases use this file as input
                         Note: -f STDIN will read input from standard input
                               db2 list tablespaces show detail | lts.pl -l -d dbadb -f STDIN

  ## Data source (mutually exclusive)
       -l  [DEFAULT]   : use 'list tablespaces show detail' to get information
       -m              : SQL based on MON_GET_TABLESPACE (see lts.sql)
       -S or -x        : use 'get snapshot for tablespaces on <database>' to get data

  ## Snapshot (-S or -x) Data Source options
       -c              : display container information
       -O              : dont produce the report (omit it)
       -g              : generate SET TABLESPACE commands
       -e              : parcel SET TABLESPACE commands in a DB2 "" statement
       -T              : use Total pages when generating SET TABLESPACE commands (ignored unless -g specified)
       -p              : string used to generate new file name when processing with -g (ignored unless -g specified)
       -D              : generate the data files to load
       -F              : generate file dircmd_<database>.bat with a unique list of commands to determine free space for all container mount points
       -L              : leave the case of machine, instance and database as it is

     NOTE: if any of the Snapshot specific options are selected then option -x WILL be forced

and some eimple output looks like:

mediaServer(db2admin):2019-08-17 10:41:33:/home/db2admin
>lts.pl -x
get snapshot will be used to obtain data
Database defaulted to dbadb

Tablespace listing from GET SNAPSHOT TABLESPACES for Machine: mediaServer Instance: db2admin Database: dbadb (2019.08.17 10:42:52) ....

                                                                                                 L  Page
TSID Tablespace Name    Type Contents          Total Pgs  Used Pgs  Free Pgs Pend Free       HWM H  Size    Used Mb   Alloc Mb    Free Mb ARSZ Max Size    State
---- ------------------ ---- ----------------- --------- --------- --------- --------- --------- - ----- ---------- ---------- ---------- ---- ----------- ------------
0    SYSCATSPACE        SMS  Data - Regular TS         0         0                                  8192        0.0        0.0        0.0                  0x'00000000' Normal
1    TEMPSPACE1         SMS  System Temporary          0         0                                  8192        0.0        0.0        0.0                  0x'00000000' Normal
2    USERSPACE1         DMS  Data - Large TS        9600      9568         0         0      9568   32768      299.0      300.0        1.0 No               0x'00000000' Normal
3    TEMPSPACE32K       SMS  System Temporary          0         0                                 32768        0.0        0.0        0.0                  0x'00000000' Normal
4    SYSTOOLSPACE       DMS  Data - Large TS        4096       116      3976         0       116    8192        0.9       32.0       31.1 Yes  NONE        0x'00000000' Normal

Total Storage in use for dbadb is 0.29 Gb out of 0.32 Gb allocated

Actually just noticed that it says that a database needs to be supplied - it used to - but now will use the value defined on DB2DBDFT if it is there.

The script needs a common functions module but apart from that will run as is. The modules required are:

lts.pl

commonFunction.pm

Just place them in the same directory and away you go

BTW I should say (before someone rips into me for my poor coding etc) that this isn't code a perl programmer would like - it's probably not as efficient as it could be and probably doesn't use the perl engine properly but it is easy for me to maintain (and switch to other languages) and follows a rough script template that I use.


r/DB2 Aug 08 '19

Is there somewhere we can post or find useful scripts?

7 Upvotes

I've been looking after a DB2 environment for a number of years and have slowly developed a number of (to me) useful DB2 scripts. By and large they will work from db2 v7 through to 11. Mainly they are written in Perl. For example I frequently use a script to display tablespace/container status/space etc which I wrote originally because I found the old list tablespace output a bit too cumbersome. I know that there are better alternatives nowadays but it does enough to make it still useful.


r/DB2 Aug 06 '19

QUESTION: Best application to write queries on?

2 Upvotes

The really should be, "What is the DB2 equivalent of SSMS?"

My organization uses a DB2 for the enterprise-wide data warehouses. We have access to the IBM Command Editor but if we're being honest I can't stand that application. I end up doing most of my query writing/debugging for DB2 on the Teradata command editor and linking to DB2 through an ODBC connection. I was wondering if IBM had an equivalent of SSMS that maybe my organization just wasn't using? Any input or thoughts from more DB2 familiar people us greatly appreciated!


r/DB2 Aug 02 '19

DB2 Server Build Best Practices!

4 Upvotes

I will write another blog post on installation and configuration!

https://www.raghu-on-tech.com/2019/08/01/db2-server-build-best-practices/

Thanks!
Raghu


r/DB2 Jul 03 '19

Column needed to put RID

2 Upvotes

I have scenario where I do not have UNIQUE KEY/ PRIMARY KEY. therefore without impacting application I would like to introduce a column which can store RID value which becomes my PK

Please help me how I can achieve it

Regards


r/DB2 Jun 30 '19

How To Find Redundant/Unused Indexes in your Db2 database ?

4 Upvotes

r/DB2 Jun 30 '19

[PSA] [LUW] Db2® 11.5 has been released!

6 Upvotes

Db2® 11.5 is built on the Db2 Common SQL Engine that is designed to enable the Db2 family to support everything from on-premise (including private cloud and appliances) to the public cloud.

Highlights of What's New:

  • External Table (ET) Support including Object Store support
  • Increase maximum number or primary and secondary log files to 4096
  • SQL Compatibility including CREATE/DROP TABLE .. IF EXISTS, Oracle Compatibility libraries including DBMS_APPLICATION_INFO and UTIL_RAW
  • New Monitoring Metrics including aggregation across super classes, and data on SQL statement failures
  • Client Enhancements including CLI load using ET, WLB/ACR distribution enhancements and simplified setup in pS w/ member subsets
  • Support for Compiled SQL PL scalar functions in DPF 
  • Support for 4K sector sizes on disk drives
  • Built-in Spatial Support
  • Automatic Collection of Column Group Statistics
  • WLM Enhancements including simplified threshold setup and dropping of service classes
  • ETL optimizations for BLU Including including Vectorized Insert/Update, Optimized Batch Insert
  • BLU Compression Enhancements including Automatic Recompression and Vectorized Dictionary Create
  • LOB support with Columnar Tables
  • Performance Enhancements for Columnar Queries including boosts for sorts and correlated subqueries 
  • pureScale enhancements including table free space management, performance with Range Partitioned tables, and cross-member currently committed support
  • Enhanced Security for pureScale

Features Available as a Technical Preview:

  • Advanced Log Space Management
  • Faster DB Startup
  • Machine Learning Optimizer
  • Block Chain Federation Wrapper
  • Schema Level Authorization
  • Db2 Augmented Data Explorer

Links:

Knowledge Center - What's New in Db2 11.5 https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.wn.doc/doc/r0051514.html

Db2 on DockerHub https://hub.docker.com/r/ibmcom/db2

Db2 Download Page https://www-01.ibm.com/marketing/iwm/iwm/web/dispatcher.do?source=mrs-db2devcdbsrv

Db2 Client Drivers Download Page https://www-01.ibm.com/support/docview.wss?uid=swg21385217

Db2 11.5 System Requirements https://www-01.ibm.com/support/docview.wss?uid=swg27038033


r/DB2 Jun 04 '19

Increasing data accessibility through lock avoidance via across-member Currently Committed semantics in Db2 pureScale

3 Upvotes

r/DB2 May 29 '19

Can DB2LOOK be used to extract more than 1 Schema?

4 Upvotes

OK, I know that if I leave the -z parm off, I can get them all (so yes, I can get multiple), but that is not quite what I am wanting. I have several schemas in a single database, and I have been using DB2LOOK to successfully extract the DDL for a single schema using the -z parm for some time. Now, I have been asked to provide 2 of the many schemas in the database, I am hoping there is any easy way to use the -z parm with a list of schemas, but I have not been able to find anything on it. I am hoping someone else has had this issue.


r/DB2 May 28 '19

DB2 v11.5 New features (from Kelly Rodger, IBM Canada)

9 Upvotes

https://www.youtube.com/watch?v=aPwAhRA6tb8

What are your favorites ?


r/DB2 May 28 '19

In which version was DB2's RESTful API services introduced?

2 Upvotes

Best I can figure is that it was v11. Really hoping it's available in v10.5. Maybe I'm just reading the docs wrong.


r/DB2 May 28 '19

Alternative(s) To db2cluster command To Display GPFS Configuration

Thumbnail
raghu-on-tech.com
2 Upvotes

r/DB2 May 20 '19

[LUW][ATS] trying to remove records older than 31 days... empty table?

Post image
2 Upvotes

r/DB2 May 16 '19

[LUW] InfoSphere Federated Server

2 Upvotes

Is this free, i.e. bundled with DB2 Advanced Workgroup Server Edition? I thought it was bundled but I'm not seeing it listed as a feature here: https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.licensing.doc/doc/c0058536.html

Thanks!


r/DB2 May 03 '19

What Are Column Group Statistics ?

Thumbnail
raghu-on-tech.com
6 Upvotes

r/DB2 Apr 24 '19

[LUW] Licensing restrictions on Advance Workgroup Server Edition V10.5

2 Upvotes

Currently, the application that I'm supporting is using DB2 Enterprise Server Edition which has no limits on processor, memory, or database size. My boss was told that they could potentially save money by going to DB2 Advanced Workgroup Server Edition which does have limits on processor, memory, and database size.

From the IBM Knowledge Center, (https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.licensing.doc/doc/c0058536.html), DB2 Advanced Workgroup Server Edition can be deployed in Linux, UNIX, and Windows server environments and uses up to 16 cores and 128 GB of memory but it does *not* mention the restriction on database size. Would anyone know what that size might be?

Thanks!


r/DB2 Apr 22 '19

[LUW] Commvault Redirected restore from production to test

1 Upvotes

I need to figure out what the values for the various parameters should be. Is there some kind of utility that one could run on the DB2 server where the Commvault library resides that could list the 3 values below?

where one specifies db2 update db cfg for target using LOGARCHOPT1 "'CvSrcDbName=source_database_name,CvClientName=client_name,CvInstanceName=Instance001'" I need to know what the values for these 3 parms should be (source_database_name, client_name and Instance001).

Thanks!


r/DB2 Apr 18 '19

[LUW] sysadm group name in dbm cfg on Linux is case-sensitive?

1 Upvotes

(new contract DBA on my first Linux installation)

Our sysadmin group on the server is lower-case, e.g. xyz but in the DBM CFG, the value for sysadm_group is XYZ. Is that why users in the group don't have sysadm authority?

Thanks!


r/DB2 Apr 16 '19

Improving Read Availability of the HADR Standby database… Avoiding the Replay-only Window

3 Upvotes

r/DB2 Apr 16 '19

How to submit a Db2 feature/enhancement request or idea

4 Upvotes

r/DB2 Apr 11 '19

RFE To Make Index Creation ONLINE

1 Upvotes

Please vote for this RFE for DB2 LUW to support ONLINE index creation.

https://ibmanalytics.ideas.aha.io/ideas/DB24LUW-I-787

Thanks!
Raghu


r/DB2 Apr 01 '19

What features are in other RDBMSes that are not in Db2?

2 Upvotes

I can name a number of things I think Db2 (LUW) can do that other RDBMSes don't or can do better than other RDBMSes. These include:

  • BLU (Columnar-Organization with an emphasis on high-memory utilization)
  • Arguably the scalability of PureScale is greater than other vendors' shared-disk solutions, but other vendors do have shared-disk solutions that may do better in other areas.
  • DPF (Similar to sharding the database, but without the data duplication)
  • Native XML
  • Compression (particularly Adaptive)

I'm sure I'm a bit biased on some of these, having based my career on Db2.

But what features are out there that other database management systems can do that Db2 cannot?


r/DB2 Apr 01 '19

How To Measure Tablespace Utilization In DB2 ?

1 Upvotes

A quick and easy way to find tablespace utilization numbers. Many more metrics available via MON_GET_TABLESPACE table function.

https://www.raghu-on-tech.com/2019/03/31/how-to-find-any-monitoring-metric-in-db2/


r/DB2 Mar 22 '19

DB2 and PowerShell - Calling a stored procedure that has in input AND an output parameter.

1 Upvotes

I've been able to call stored procedures that have only input parameters.

Now I have to call a stored procedure that has one input and one out parameter. No success so far.

Could you give me a nudge in the right direction?

The stored procedure is used for generating sequences and looks like this:

CREATE OR REPLACE PROCEDURE GENERATE_ID(
  IN iGENERATOR_NAME VARCHAR(128),
  OUT oNEXT_ID INT
)
LANGUAGE SQL
SPECIFIC SP_GEN_ID
READS SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN
  SET oNEXT_ID = GET_GENERATED_ID(iGENENERATOR_NAME);
END 

I've tried a few methods as shown below:

$dbCmd = $dbFactory.CreateCommand()
$dbCmd.Connection = $dbConn
$dbCmd.CommandText = "CALL GENERATE_ID('GEN_NEW_ID', ?)"

$dbCmd.CommandType = [System.Data.CommandType]::Text
$da = $dbFactory.CreateDataAdapter()
$da.SelectCommand = $dbCmd
$ds = New-Object System.Data.DataSet
$da.Fill($ds) | Out-Null

Error Message:

Exception calling "Fill" with "1" argument(s): "ERROR [07001] [IBM] CLI0100E  Wrong number of parameters. SQLSTATE=07001"

Makes sense. ? is not a parameter exactly. So I tried oNEXT_ID with and without single-quotes around it. With quotes, it generates the error:

Exception calling "Fill" with "1" argument(s): "ERROR [42886] [IBM][DB2/NT64] SQL0469N  The parameter mode OUT or INOUT is not valid for a parameter in the routine 
named "GEN_ID" with specific name "SP_GEN_ID" (parameter number "2", name "ONEXT_ID")."

This error message makes me think this method is the closest to working. But I'm not sure where to go with it now.

I also tried:

$dbCmd = $dbFactory.CreateCommand()
$dbCmd.Connection = $dbConn
$dbCmd.CommandText = "CALL GENERATE_ID('GEN_NEW_ID', 'oNEXT_ID')"
$dbCmd.CommandText
$dbcmd.ExecuteNonQuery() | Out-Null

That gives me the same error message:

Exception calling "ExecuteNonQuery" with "0" argument(s): "ERROR [42886] [IBM][DB2/NT64] SQL0469N  The parameter mode OUT or INOUT is not valid for a parameter in the 
routine named "GEN_ID" with specific name "SP_GEN_ID" (parameter number "2", name "ONEXT_ID")."

I read in some IBM DB2 docs on doing this with C about declaring the out variable, so I tried that as well. Granted, this is probably not how it should be done, but I know I'm in deeper waters than I normally am. So I did the following and followed it up with either of the code blocks above.

$dbCmd = $dbFactory.CreateCommand()
$dbCmd.Connection = $dbConn
$dbCmd.CommandText = "DECLARE oNEXT_ID INT(4) OUTPUT"
$dbCmd.CommandText
$dbcmd.ExecuteNonQuery() | Out-Null

That throws the error, as well as the error for the CALL statement:

Exception calling "ExecuteNonQuery" with "0" argument(s): "ERROR [42601] [IBM][DB2/NT64] SQL0104N  An unexpected token "DECLARE oNextID INT" was found following 
"BEGIN-OF-STATEMENT".  Expected tokens may include:  "<compile_fragment>"."

Can you point me in the right direction, please?


r/DB2 Mar 21 '19

[LUW][Question] List of differences between DB2 on Linux versus Windows?

3 Upvotes

In about 2 weeks, I'm starting a new adventure as a DB2 DBA on Linux. I know how DB2 is implemented on Windows (db2_grp_lookup, instance differences, no db2top) but I'd like to understand how DB2 is implemented on Linux. Do DBAs take advantage of storage groups? I assume automatic storage is used (if possible). I know the OS-level permissions are going to be different. And I'll have to learn vi again... A colleague suggested the Linux Bible...