[HOWTO] How to Pretend You are a TSM Superstar with TSM SQL Queries

Status
Not open for further replies.

Elomis

ADSM.ORG Senior Member
Joined
Jul 14, 2007
Messages
85
Reaction score
5
Points
0
Location
Sydney, Australia
There are heaps upon heaps of questions posted in these forums that either start with, or are entirely, "I need a select statement that shows me...". In the spirit of teaching people to fish rather than giving them a fish, I thought I'd pen some notes on how to figure out essentially anything in TSM using SQL.

I am no TSM superguru, I know some really clever tricks and understand a substantial amount of the inner workings, I'm even certified - but I can pull any piece of information out of TSM that anyone needs me to. You can too, like this;

If you are unfamiliar with what parts of TSM you can query, the first things you should do is enter select tabname from syscat.tables at the admin console prompt, this will dump out a list of each area of TSM you can query using SQL. Copy and paste this into notepad or something and save it to a thumb drive because you are going to be referring to it a lot. In fact if you go to a command prompt and type dsmadmc -ID=yourusername -pass=yourpassword select tabname from syscat.tables > TSMTablesToQuery.txt to create a text file list in TSMTablesToQuery.txt

If you are unfamiliar with SQL you need the three line primer on what it is. SQL queries the TSM database by selecting stuff where a paramater is valid from a table and ordering it by the paramater. So:

select * from drives where online = "YES" order by LAST_UPDATE

Selects everything from the drives table, that matches the online paramater being yes, and orders the list by the last time the drive was updated.

Now the juicy bit. Your boss comes along and says to you, "I want a list of every tape that is not full yet", how do you resolve this query and make yourself look like the purveyor of all information? Have a look at the table names, tapes are media, there's a table name called media.

Type select * from media and you'll get an output similar to the following;

VOLUME_NAME: A12345
STATE: MOUNTABLEINLIB
UPD_DATE: 2008-01-01 12:13:19.000000
LOCATION:
STGPOOL_NAME: TAPESTORAGEPOOL
LIB_NAME: GIANTTAPELIBRARY
STATUS: FULL
ACCESS: READWRITE
LRD: 2008-01-01 09:13:19.000000

... for a few pages, where TSM has gone through and found all of the items in the table "media" that matches your criteria. In this instance you haven't specified criteria so it's going to try and return all of them.

But what our boss asked for was a list of them that are not full, so we need to specify our parameter;

select * from media where status = 'FILLING'

Will do it, presenting an output of all the details of each tape that is filling.

We still haven't quite given the boss exactly what he/she wants, they asked for a list of the tapes, and our output so far is all the details of all the tapes, so instead of select * (return all the details), we just want the names of the tapes. Easy-peasey;

select volume_name from media where status = 'FILLING'

Is exactly what the boss asked for. I recommend importing it into Microsoft Excel and colour coding it to make youself look even more useful to management, because we all know that to management the only acceptable format for anything is Excel and nothing is of any value unless it's colour coded *saracstic giggle*

So to recap;
To get any piece of information out of TSM.
  1. Look at syscat.tables to identify where that type of information is likely to reside, drives for drives, media for tapes, nodes for nodes etc.
  2. Do a quick select * from tablename to ID what criteria you are going to filter your query by.
  3. Change the * to what criteria you actually want to list.
The more cluey among us know tips like "as" to name columns in results and count(*) to return a count instead of the actual results, I'll update this later if people are interested.
 
  • Like
Reactions: dkk
Thanks Elomis, you'll be surprised on the number of select statements we all can come up with over the course of this forum. Some basic, some advanced. But.....
There is always room to learn more here - dont we know it.
The SQL wizards here will guide along the way - eh guys and gals :)
 
I actually think it would be very very handy to have a read only forum full of scripts and sqls, perhaps one that someone could look over before posting them as a lot of very similar questions are asked and it is quicker to repost and answer than to find the original, this must be the case for the person asking the question as well I guess. I am not sure how many mod/admins there actually are on the forum and that may be more work than those people have the time to provide and i know TSMWiki tries something similar.

I think however if a script/sql read forum was created possibly a lot of loose ends could be cleaned up and with the right headings on the posts then people could very easily find what they are looking for...

How that would be split is difficult to know, doing by table works except of course for cross table commands.

I think it would be a very very good change to the site personally.

In regards to the information you have posted Elomis I think you are right and pointing people in the right direction. Generally i tell people to start with select * from tables and select * from columns and familiarise themselves with what is there to start with.

I also get them to perform a "help select" at in particular to familiarise themselves with each of the following as it is hard to get someone to "go and learn sql", they are only come back and ask why the hell they learnt it when heaps of the functions are missing, but if they performed even a google search on

SQL [function]

on each of the options below, they could do a lot worse

Code:
      ALL                    CURRENT_USER            MAX
      ANY                    DISTINCT                MIN
      AVG                    EXISTS                  NULL
      AS                     EXTRACT                 ORDER BY
      BETWEEN                FROM                    POSITION
      CASE                   GROUP BY                SOME
      CAST                   HAVING                  SUBSTRING
      COUNT                  IN                      SUM
      CURRENT_DATE           JOIN                    TRIM
      CURRENT_TIME           LIKE                    WHERE
      CURRENT_TIMESTAMP

Also looking through the crappy page of selects IBM provides with its documentation still gives people and idea of how to "structure" a statement.

Generally with selects a basic user should grab "everything" from something.
Then as you show they should grab something from a table
Then grab everything from a table meeting a criteria within the table.
then grab multiple items from a table
Next would be to order the output and then group output.

After that there is summing/counting the data, changing the heading, selecting starting and end points in the output of the data you bring back.

Probably the next step is to look at the mathematical functions within some of those selects, the way conversions of data type are performed and why, generally not just pulling out the data but manipulating it.
It is not really important for most to insert their own text or to use the concatenate functions or anything like that, but it is worth knowing that theses can be done.

Generally I have always thought that it would be great for someone to do a "Guide to using SQL in TSM" with a guide not just of sql's but how to create your sql's what you should and should not try and do etc etc. Probably the best two guides out there are on Chad's tsmexperts site. The is a beginner and an expert guide there for those starting out with their SQLs.

If someone was to do something similar and in fact expand on, I personally think that would be a fantastic addition for the site, perhaps made a "sticky" or something.

Very nice start btw.
 
Last edited:
I am not sure how many mod/admins there actually are on the forum

Right now, 1 admin and no mods (and no, I'm not the admin but I have talked to him).

Any suggestions like this should be sent to him. I think he'd be very open to the idea of a read-only forum with this kind of data in it.

-Aaron
 
Beleive it or not... Exactly yester I had a thought about how would it be on composing all the TSM queries together as ahandy reference... What a coincidence! I would be happy to contribute to this effort...! It should go like when to use what...
 
Count me in to help! I love doing select statements, they can be very challenging. I also think the only way to learn to to get your hands dirty. That's the way I learned, and it's the best way to learn the in's and out's of the TSM DB. Maybe we could just add to Thobias's SQL list at http://thobias.org/tsm/sql/index.html? We could ask him.
 
Last edited:
I would think it best to incorporate those sql into here as appropriate (nice link there btw Chad), because I think it would be best to be able to navigate your way through this site as i think it is one of the first links you give someone. I would say if I am showing TSM there are 3/4 pages i will give people as reference pages and this would always be one of them. This i think would be consistent across most of us across this site, so having the information here has some big benefits.

It would be great if someone did raise this with the admin here as it would be a pity if this was just an idea in a post and the admin never heard about it.

Seems there are people happy to put there hand up and do the work as well and there are plenty of SQL gurus on the site so i would think there is a good chance this would work.

It is just really important (IMO) that all of the SQL's/scripts are tested by people other than the person submitting them.
 
Last edited:
Hey, that is really good to know. I have always been limited by the standard TSM q statements.
Now I am faced with upgrading TSM sever 5.3 to 5.5 on windows server 2003 sp2 sever. Is there anything I should be concerned with? Has anyone done this yet in windows?

I appreciate all your help.

Kofibrit
 
Hey, that is really good to know. I have always been limited by the standard TSM q statements.
Now I am faced with upgrading TSM sever 5.3 to 5.5 on windows server 2003 sp2 sever. Is there anything I should be concerned with? Has anyone done this yet in windows?

I appreciate all your help.

Kofibrit
you should delete your post and start in another thread mate. Not only does it not hijack this one, but it also allows others to use your thread as a reference point when going through a new upgrade
 
Status
Not open for further replies.
Back
Top