0% found this document useful (0 votes)
65 views30 pages

Tsm Sql Interface: Tivoli 技术专家沙龙活动

The document introduces the TSM SQL interface, including that it only supports SELECT queries. It provides examples of common SQL statements and how to view the TSM system catalog. It also explains clauses, operators, and functions that can be used to manipulate and analyze query results.

Uploaded by

LeeWang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views30 pages

Tsm Sql Interface: Tivoli 技术专家沙龙活动

The document introduces the TSM SQL interface, including that it only supports SELECT queries. It provides examples of common SQL statements and how to view the TSM system catalog. It also explains clauses, operators, and functions that can be used to manipulate and analyze query results.

Uploaded by

LeeWang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 30

Tivoli 技术专家沙龙活动

Tsm Sql Interface

周硕基
[email protected]
IBM Software Group | Tivoli software

Overview

•Tsm sql interface 介绍


•Tsm sql 在问题诊断中的案例分析
•Tsm sql 在做信息统计时常用的一些语句举例
•Tsm sql 其他

2
IBM Software Group | Tivoli software

Tsm Sql Interface 介绍


 Supports the SQL SELECT query only

 Requires a “minimum” of 4MB of free space in the database(Some


conditions, such as the ORDER BY clause, the GROUP BY clause, and
the DISTINCT operator, may require additional temporary table storage.)

 Complicated queries may take a long time to complete and can interfere
with server operations(such as select * from backups)

 You cannot issue SELECT queries from the server console (admin
command line only )

3
IBM Software Group | Tivoli software

Tsm Sql Interface 介绍


 “Mostly” conforms to standard SQL
 Subset of the SQL92 and SQL93 ANSI standards

 Does NOT support:


 UNION ( 合集)
 INTERSECT (交集 , 左右两边的两个查询都返回的所有非重复值 )
 EXCEPT (从左查询中返回右查询没有找到的所有非重复值)
 Correlated subqueries ( 相关子查询 )
 Semicolon cannot be used as a command terminator

4
IBM Software Group | Tivoli software

SELECT 语法
 SELECT column|expression [,n..]
FROM tablename {,n…}
 column refers to a column in a table
 * is allowed as a wildcard to select all columns in a table
 expression refers to functions that allow you manipulate the data being
returned
 [,n…] indicates that you may specify one or more columns or
expressions
 FROM clause indicates which table to search
 You can specify one or more tablenames

5
IBM Software Group | Tivoli software

Tsm Database Catalog


 Tsm has three system catalog tables so that you can view the tables,
columns and enumerated data types available
 SYSCAT.TABLES

 SYSCAT.COLUMNS( 可以查询到表的 index 列 , 在检索时使用 index 列 , 可


以加快检索速度 )
select colname,index_keyseq from columns where
tabname='VOLUMES'

 SYSCAT.ENUMTYPES

6
IBM Software Group | Tivoli software

Viewing the Tsm System Catalog


 To view available table names:
SELECT * FROM SYSCAT.TABLES

 To view all column names within tables


SELECT tabname,colname FROM SYSCAT.COLUMNS
 To view the valid values and order for enumerated types
SELECT * FROM SYSCAT.ENUMTYPES

7
IBM Software Group | Tivoli software

Manipulating the Results


 You may not want all of the data in all of the columns all of the time so:

 SQL provides clauses, operators, and functions

 These allow you to sort, order, filter, and compute the data on a select
command

8
IBM Software Group | Tivoli software

Clauses, Operators, and Functions


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

*Supported by TSM SELECT

9
IBM Software Group | Tivoli software

WHERE Clause
 The WHERE clause allows you to filter out rows from the results

 I want this, this and this, but only where this condition is true

 I want to see all the volumes on which the client called test1 has data:

SELECT NODE_NAME,VOLUME_NAME FROM VOLUMEUSAGE


WHERE NODE_NAME=‘TEST1’

10
IBM Software Group | Tivoli software

Operators (use with WHERE)


 Comparison Operators
is 、 is not 、 = 、 <> 、 < 、 > 、 <= 、 >=
 Logical Operators
Logical operators separate two or more conditions in the WHERE
clause
LIKE is used with the wildcard % to match all occurrences
SELECT * FROM NODES WHERE NODE_NAME LIKE ‘%T%’

AND means that the expressions on both sides must be true to return
TRUE
SELECT * FROM NODES WHERE NODE_NAME=‘TEST1’ AND
PLATFORM_NAME=‘WinNT’

11
IBM Software Group | Tivoli software

More Logical Operators


 You can use OR to sum up a series of conditions. If any of the
comparisons is true, OR returns TRUE
SELECT * FROM NODES WHERE NODE_NAME=‘TEST1’ OR
‘TEST2’
 Use IN to replace multiple OR’s
SELECT * FROM NODES WHERE
NODE_NAMEIN(‘CARROL’,’DODSON’,’LEWIS’,’CHARLES’)

 Use BETWEEN to get a range


SELECT NODE_NAME FROM OCCUPANCY WHERE LOGICAL_MB
BETWEEN 5000 AND 10000

12
IBM Software Group | Tivoli software

ORDER BY Clause
 The ORDER BY clause is used to sort the rows priorto displaying them:
SELECT NODE_NAME, PLATFORM_NAME FROM NODES
ORDER BY PLATFORM_NAME

 You can specify that the results be sorted in ascending or descending


order:
SELECT NODE_NAME, TYPE, FILESPACE_NAME,LOGICAL_MB
FROM OCCUPANCY ORDER BY LOGICAL_MB DESC

13
IBM Software Group | Tivoli software

Functions
 Functions allow you to aggregate data and operate on strings, numeric
and date and time values

 Aggregate functions perform operations on values from selected rows to


produce a singlevalue.
They include COUNT(*), SUM, AVG, MAX, and MIN.

COUNT(*) is useful for finding the number of rows that match a query.

select count(*) from libvolumes

14
IBM Software Group | Tivoli software

Timestamp and CAST Functions


 Example of date/time and cast function –displays nodes that have not
accessed the server in a specified ($1) number of days
 CAST’s the timestamp as decimal forprocessing
SELECT NODE_NAME,LASTACC_TIME FROM NODES WHERE
CAST((CURRENT_TIMESTAMP-LASTACC_TIME)DAYS as decimal)
>= 0
(This sql’s sample output will be:
NODE_NAME LASTACC_TIME
------------------ ------------------
TEST1 2007-08-19
22:06:27.000000
)

15
IBM Software Group | Tivoli software

GROUP BY Clause
 The GROUP BY clause allows you to combine the rows being selected
into logical groups
 Normally used with aggregate functions
SELECT NODE_NAME, SUM(NUM_FILES) AS #_OF_FILES,
SUM(LOGICAL_MB) AS TOTAL_MB FROM OCCUPANCY GROUP
BY NODE_NAME

(this sql’s sample output will be:


NODE_NAME #_OF_FILES TOTAL_MB
------------------ ----------- ---------------------------------
TEST1 15 4.32
)
 When using aggregate functions, you need to
name the columns (i.e. AS #_OF_FILES)

16
IBM Software Group | Tivoli software

HAVING Clause
 HAVING always follows the GROUP BY clause

 Use the HAVING clause to filter the results of the GROUP BY clause
SELECT NODE_NAME, SUM(NUM_FILES) AS #_OF_FILES,
SUM(LOGICAL_MB) AS TOTAL_MB FROM OCCUPANCY GROUP BY
NODE_NAME HAVING SUM(LOGICAL_MB)>1

17
IBM Software Group | Tivoli software

Joining Tables
 Helps you see how data relates between tables

 There are different types of joins, depending on the data you are trying
to relate

 Use an alias to specify which column you want to display when joining
tables with columns of the same name

 The keyword DISTINCT specifies only unique rows will be retrieved and
prevent duplicates

18
IBM Software Group | Tivoli software

JOIN Example
 To see which schedules a node is associated with join ASSOCIATIONS
with CLIENT_SCHEDULES
 DOMAIN_NAME and SCHEDULE_NAME are common columns

 We’ll use the alias C.SCHEDULE_NAME, to indicate which


SCHEDULE_NAME to return

select tabname,colname from columns where tabname in


('ASSOCIATIONS','CLIENT_SCHEDULES') and colname in('DOM
AIN_NAME','SCHEDULE_NAME')
the output will be:
TABNAME COLNAME
------------------ ------------------
ASSOCIATIONS DOMAIN_NAME
ASSOCIATIONS SCHEDULE_NAME
CLIENT_SCHEDULES DOMAIN_NAME
CLIENT_SCHEDULES SCHEDULE_NAME

19
IBM Software Group | Tivoli software

Join Example continued


 SELECT DISTINCT NODE_NAME,C.SCHEDULE_NAME FROM
ASSOCIATIONS A, CLIENT_SCHEDULES C WHERE
A.SCHEDULE_NAME=C.SCHEDULE_NAME

 This is an example of an inner join or equi-join

 The goal is to match the values of a column in one table to the


corresponding values in the second table (schedule_name)

20
IBM Software Group | Tivoli software

Tsm sql 案例一


 用户在用客户端恢复文件的时候,报告此客户端上 2006 年 12 月 31 日归
档的 /tmp/test1 文件恢复失败
 查询 actlog 表查看具体报错信息 (or q act begind=xxx sear=err/fail)
 定位 /tmp/test1 文件
有几个归档:
select node_name,filespace_name,filespace_id,archive_date, class_name
from archives where ll_name='test1‘
此归档文件存放在哪些卷:
select volume_name,node_name,type,filespace_name from contents where
type='Arch' and file_name like '%test1'

21
IBM Software Group | Tivoli software

Tsm sql 案例一 continued


 通过刚才的两个 sql 查询,我们可以定位需要恢复的文件一共做过几次归
档,各个归档存放在哪一个卷上
 思考一:我们如何通过一个查询连接这两个表进行恢复文件定位?
( substr(contents.file_name) 和 archives.ll_name)
 下一步如何处理?
 寻找其他时间点的归档进行恢复
 对 volume 状态重置 (q vol xx f=d or select * from volumes where access like
xx)
 做 audit libr xxx or audit vol xxx
…

 思考 : 恢复不了的文件是做的备份而不是归档还要注意哪些地方?

select state,backup_date , class_name from backups where xxx

注意活动非活动版本
注意不同的管理类

22
IBM Software Group | Tivoli software

Tsm sql 案例二


 用户在做 backup db 做到一半,由于某种原因中断,怎么样让此 db 备份
磁带变回 scratch 状态?
select volume_name as "DBB Full Tapes", date_time as "Time
Created", current_timestamp as "Current D&T" from volhistory where
cast ((current_timestamp-date_time)days as decimal) >=0 and
type='BACKUPFULL' order by date_time

DBB Full Tapes Time Created Current D&T


------------------ ------------------ ------------------
abc123 2007-08-20 2007-08-20
19:49:49.000000 19:51:28.000000
abc321 2007-08-20 2007-08-20
19:49:49.000000 19:51:28.000000

next?
 Del volh t=dbb

23
IBM Software Group | Tivoli software

Tsm sql 案例三


 用户反映在一个单节点归档 , 两驱动器的带库备份系统中 , 每天备份量大
小基本相同 , 虽然归档时间设置成 30 天 , 但存储池中磁带空间不见循环
使用 ?
一般判断 , 应该是存储部分的故障
select date_time,msgno,message from actlog where severity=‘E‘ or
severity=’W’ 检查 act log 相应的错误信息
select drive_name,online from drives
select destination_name,destination_type,library_name,device,online
from paths
常见故障分析 :one drive offline,one path offline,path 定义错误…

24
IBM Software Group | Tivoli software

Tsm Sql 常用统计语句


 在我们抓取用户信息做服务方案 , 做带库扩容方案 , 做时间估算…
 有多少磁带逻辑状态不正常 ?
select VOLUME_NAME,ACCESS from volumes where access
='UNAVAILABLE'
 带库里目前有多少 scratch 磁带 ?
select count(*) as Scratch_count from libvolumes where status='Scratch'
 在改变存储池回收回收阀值时有多少个磁带会做回收处理?
select count(*) from volumes where stgpool_name='poolname'and
upper(status)='FULL' and pct_utilized <%%
 各存储池卷分配情况
select stgpool_name,devclass_name,count(*) as "VOLUMES" from
volumes group by stgpool_name,devclass_name

25
IBM Software Group | Tivoli software

Tsm Sql 常用统计语句二


 按照节点统计文件和文件大小
select node_name, sum(logical_mb) as Data_In_MB, sum(num_files) as
Num_of_files from occupancy group by node_name order by
node_name
 过去 24 小时 tsm 数据备份总量
SELECT entity AS "Node name",CAST(sum(bytes/1024/1024) AS
char(29)),1,10) AS "start date", SUBSTR (CAST(min (start_time) AS
char(29)),12,8) AS "start time", SUBSTR (CAST(max (end_time) AS
char(29)),1,10) AS "end date", SUBSTR (CAST(max (end_time) AS
char(29)),12,8) AS "end time" FROM summary WHERE
activity='BACKUP' AND start_time>=current_timestamp - 24 hours
GROUP BY entity

(activity 可取值 :'TAPE MOUNT',


'FULL_DBBACKUP','INCR_DBBACKUP',
'EXPIRATION', 'RECLAMATION', 'MIGRATION', 'MOVE DATA',
'STGPOOL BACKUP', 'BACKUP', 'RESTORE', 'ARCHIVE' and
'RETRIEVE'. )

26
IBM Software Group | Tivoli software

Tsm Sql 常用统计语句三

 列出使用自动调度的客户端节点
SELECT node_name FROM nodes WHERE node_name IN (SELECT
node_name FROM associations) ( 子查询非相关子查询)

other:
events?
策略相关 ?

27
IBM Software Group | Tivoli software

Tsm sql other


 Odbc?
 scripts(scripts.smp)

28
IBM Software Group | Tivoli software

Tsm Sql 参考
 Help select

 http://www.redbooks.ibm.com/abstracts/tips0010.html?Open

 http://thobias.org/tsm/sql/index.html

 http://www.lascon.co.uk/d005104.htm

29
IBM Software Group | Tivoli software

Questions????

30

You might also like