.LOGTABLE dbname.fastexp_log;
.LOGON TDPID/username,password;
DATABASE dbname;
.BEGIN EXPORT SESSIONS 10;
.EXPORT OUTFILE D:\path\Teradata_fastExp_query_log.txt
MODE RECORD FORMAT TEXT;
select cast(‘IDWWM’||’~~’||
rtrim(cast(tb1.Username as char(128)))||’~~’||
rtrim(cast(tb1.AppID as char(30)))||’~~’||
rtrim(cast(tb1.ClientID as char(30)))||’~~’||
rtrim(cast(tb1.StartTime as char(21)))||’~~’||
rtrim(cast(tb1.ampcputime as char(10)))||’~~’||
rtrim(cast(tb1.TotalIOCount as char(20)))||’~~’||
rtrim(cast(tb1.ParserCPUTime as char(10)))||’~~’||
rtrim(cast(tb1.firstresptime as char(21)))||’~~’||
rtrim(cast(tb1.firststeptime as char(21)))||’~~’||
rtrim(cast(tb1.ProcID as char(6)))||’~~’||
rtrim(cast(tb1.QueryID as char(20)))||’~~’||
rtrim(cast(tb1.MaxAMPCPUTime as char(10)))||’~~’||
rtrim(cast(tb1.MaxAMPIO as char(20)))||’~~’||
rtrim(cast(tb4.ampcputime as char(10)))||’~~’||
rtrim(cast(tb4.TotalIOCount as char(20)))||’~~’||
rtrim(cast(((CAST((CAST(tb1.firstresptime AS DATE)- CAST(tb1.firststeptime AS DATE)) AS DECIMAL(18,6)) * 60*60*24)
+ ((EXTRACT( HOUR FROM tb1.firstresptime) – EXTRACT( HOUR FROM tb1.firststeptime)) * 60*60)
+ ((EXTRACT(MINUTE FROM tb1.firstresptime) – EXTRACT(MINUTE FROM tb1.firststeptime)) * 60)
+ (EXTRACT(SECOND FROM tb1.firstresptime) – EXTRACT(SECOND FROM tb1.firststeptime)) ) as char(20)))||’~~’||
rtrim(cast(coalesce(TB3.OBJECTDATABASENAME,’Not Present’) as char(500)))||’~~’||
rtrim(cast(tb2.sqlrowno as char(2)))||’~~’||
rtrim(cast(tb1.statementtype as char(100)))||’~~’||
rtrim(cast(tb1.logonsource as char(100)))||’~~’||
rtrim(cast(coalesce(tb1.queryband,’Not Present’) as char(6160)))||’~~’||
rtrim(cast(tb2.SQLTEXTINFO as char(20000)))
as char(27000))
)
from
pdcrinfo.dbqlogtbl tb1 inner join pdcrinfo.dbqlsqltbl tb2
on tb1.queryid = tb2.queryid
and tb1.procid = tb2.procid
and tb1.logdate = tb2.logdate
left outer join
(
select queryid,procid,logdate,tdstats.udfconcat(trim(objectdatabasename)) as objectdatabasename
from pdcrinfo.dbqlobjtbl
where objecttype=’db’ and logdate between ‘2017/01/01’ AND ‘2017/05/29’
group by queryid,procid,logdate
)
tb3
on tb1.queryid = tb3.queryid
and tb1.procid = tb3.procid
and tb1.logdate = tb3.logdate
inner join
(
select logdate,sum(ampcputime) ampcputime,sum(totaliocount) as totaliocount
from pdcrinfo.dbqlogtbl
where
logdate between ‘2023/01/01’ AND ‘2023/05/29’
group by logdate
)tb4 on tb4.logdate = tb1.logdate
where
tb1.logdate between ‘2023/01/01’ AND ‘2023/05/29’
and tb1.errorcode=0
order by tb1.procid,tb1.queryid,tb2.sqlrowno;
.END EXPORT;
.LOGOFF;