Monday, July 25, 2016

What is checktable in teradata

"Checktable" is diagnostic tool provided by Teradata to identify inconsistencies and corruption in internal data structure of database objects in the system, it checks inconsistencies at table header, row identifier, secondary index and fallback table validity.

check table has 3 levels of checking

level 1: compares row count of subtable of primary data with subtable of fall back table for each cluster and reports the difference and also does row count comparison for base table and secondary index subtable.

level 2:  compares row identifier in various sub tables and report any inconsistency, It checks fallback & secondary index subtables for duplicate row id's , out of order rowids and incorrectly distributed rows,

level 3: compares the actual rows bytes by byte at secondary index, table header, rowid and fallback level. it is most resource consuming level and should be run in idle time.


check table can be run from superviser window in primary not of system using cnsterm 6 console.

command: start checktable will start the utility.

example check table command:
check all tables at level one with no error limit;

What is Crashdump database in Teradata



Crashdump database is used to store the memory/swap dump of Teradata system when Teradata Database crashes (database restarts) or there is critical/Fatal error has occurred in Teradata which it cannot recover from.

This is Teradata support consultant team use crash dump to analyze the reason of database crash or any fatal error.

Crash dump types:
there are two type of dumps that is generated from Teradata TPA namely 1. Crash dump 2. snapshot dump.



Enabling System level resource logging in Teradata



This can be done from cnsterm terminal, follow the steps below.

CVS_1-8:~ # cnsterm 6
Attempting to connect to CNS...Completed.
Hello

Input Supervisor Command:
start qrysessn

Started 'qrysessn' in window 1
 at Sat May 11 06:53:04 2013


Input Supervisor Command:
start qrysessn

Started 'qrysessn' in window 2
 at Sat May 11 06:53:04 2013


Input Supervisor Command:
start showlocks

Started 'showlocks' in window 1
 at Sat May 11 06:53:08 2013

Input Supervisor Command:
> get logtable all
get logtable all

spma table's logging is disabled
ipma table's logging is enabled
svpr table's logging is enabled
ivpr table's logging is disabled
scpu table's logging is enabled
sldv table's logging is enabled
spdsk table's logging is enabled
svdsk table's logging is enabled
sawt table's logging is enabled
sps table's logging is enabled
shst table's logging is enabled

Input Supervisor Command:
> set logtable spma on
set logtable spma on


Input Supervisor Command:
> get logtable all
get logtable all

spma table's logging is enabled
ipma table's logging is enabled
svpr table's logging is enabled
ivpr table's logging is disabled
scpu table's logging is enabled
sldv table's logging is enabled
spdsk table's logging is enabled
svdsk table's logging is enabled
sawt table's logging is enabled
sps table's logging is enabled
shst table's logging is enabled

Input Supervisor Command:
> set logtable ivpr on
set logtable ivpr on


Input Supervisor Command:
> get logtable all
get logtable all

spma table's logging is enabled
ipma table's logging is enabled
svpr table's logging is enabled
ivpr table's logging is enabled
scpu table's logging is enabled
sldv table's logging is enabled
spdsk table's logging is enabled
svdsk table's logging is enabled
sawt table's logging is enabled
sps table's logging is enabled
shst table's logging is enabled

Input Supervisor Command:


What is impact CPU in teradata?

Impact cpu in Teradata is the cpu consumed on hottest AMP multiplied by number of AMP in the system. so, in other word we can say it as actual "impact" on system cpu during skewed processing.

formula to calculate impact cpu:
MaxAMPCPUTime * (HASHAMP()+1) AS impactCPU

Monday, April 18, 2016

Teradata HUT lock vs Transaction lock


If we consider these locks only from blocking perspective then behavior of HUT lock and Transaction Lock are same.
  1. For example, 

  2. 1) A read lock prevents another job from claiming a write lock or exclusive lock. 
  3. 2)A write lock prevents a read lock, write lock, or exclusive lock. 
  4. 3) An exclusive lock prevents any other type of lock. 

  5. Conflicting HUT and transaction locks on an object block each other, just as if both were transaction locks or both were HUT locks. 
The two differences between transaction locks and HUT locks are: 

Permanence:
           A transaction lock exists only for the duration of a transaction; after the transaction completes or is                    aborted, the lock is released. A HUT lock is more permanent. It is only removed if an explicit                            RELEASE LOCK command is issued, or if the locking operation completes successfully 

Scope:
           Transaction lock has session scope
           i.e. it applies to any command submitted by the session running the locking transaction. Another session            running against the same object(s) must claim its own locks, even if it is running under the same user 

           HUT lock has users scope
           i.e. it applies to any Teradata ARC operation that the user is performing on the object. A user must have            only one HUT lock against an object at a time. The HUT lock allows any Teradata ARC operation from            that user to access the locked object(s), but blocks other users from acquiring a conflicting HUT lock on            the object(s). 

Wednesday, April 13, 2016

The difference between copy and restore in teradata

The difference between copy and restore is as below

• A restore operation moves data from archived files back to the same Teradata Database from which it was archived or to a different Teradata Database so long as the database DBC is already restored.

• A copy operation moves data from an archived file back to a Teradata Database, not necessarily to the same system, and creates a new table if one does not already exist on the target database. When a selected partition is copied, the table must exist and be a table that was previously copied as a full-table copy.

Wednesday, February 3, 2016

How to find PPI tables in Teradata.

List all PPI tables in Teradata:

The index and parition information in teradata can be found in below two tables.

dbc.indices
==========

all index information in Teradata is stored in dbc.indices and as table is being partitioned on primay index
the table is partition information can be found with indextype='Q'.

sel * from dbc.indices where  indextype='Q' and databasename=<yourdatabasename>

dbc.indexconstraints
===============

Teradata consider PPI as constraints and also store the partition expression in dbc.indexconstraints

sel constrainttext from dbc.indexconstraints where dbc.indexconstraints='Q'  

Friday, December 25, 2015

Number of load jobs running on the system

To get a count of load jobs that are currently executing, you can use the following SQL.

SELECT COUNT(DISTINCT LogonSequenceNo) AS Utility_Cnt
FROM DBC.SessionInfo
WHERE Partition IN ('Fastload', 'Export', 'MLoad');

DBS Control parameters (MaxLoadTasks and MaxLoadAWT) can be used to control the number of concurrent load utilities running in a system.

Note: If TASM utility throttles are used, then the utility throttles override the MaxLoadTasks and MaxLoadAWT values and uses 60% (of AWTs) as the setting for the AWTs.

RELEASE MLOAD Statement

Once MLOAD job or TPT Update operator execution has begun, table headers are updated in the target tables indicating that a MLOAD is in progress. if the MLOAD fails, target tables are still considered under the control of the MLOAD and access to them will be restricted accordingly.

The RELEASE MLOAD statement provides a way to return tables to general availability where there is no desire to restart the MLOAD. If the specified table is in the Preliminary, DDL or the early part of the Acquisition phase, the RELEASE MLOAD statement makes the table completely accessible and prevents any attempt to restart the MLOAD.

 If the MLOAD had proceeded into the Application phase, the RELEASE MLOAD statement is rejected and the job must be restarted or until the transaction with the lock completes or if the point of no return has occurred(i.e. DELETE statement is sent to the DBC)

To successfully complete a RELEASE MLOAD, the following procedure must be followed:
1. Make sure MLOAD is not running; abort it if it is. (Note: MLOAD is still in a re-startable state if aborted. If it is past the point of no return, go to step 4.)
2. Enter RELEASE MLOAD (try IN APPLY if in application phase with caustion)
3. If successful, drop the work and error tables.
  4. If not successful, determine if past point of no return. If so, either restart MLOAD and let it complete, or drop target, work, and error tables.

Example:


release MLOAD Inventory;
release MLOAD Order IN APPLY;

Monday, October 5, 2015

Types of spools in Teradata

Teradata Database draws spool space dynamically from unused system perm space, there are mainly three types of spool usage in the system.

Volatile Spool:
Volatile spool is used for volatile table creation and  is retained until the Transaction completes (unless the table was created with ON COMMIT PRESERVE ROW)
or Table is dropped manually during the session
or Session ends
or Teradata Database resets

Intermediate Spool:
Intermediate spool is used during query processing, the spool are retained until they are no longer needed by the query for which they were created. You can determine when intermediate spool is flushed by examining the output of an EXPLAIN.
Note: The first step performed after intermediate spool has been flushed is designated “Last Use.”
or Teradata Database resets

Output Spool:
Output spool is used mainly for returning the result rows while responding, these are either Response rows returned in the answer set for a query or during Rows updated within, inserted into, or deleted from a base table

Monday, September 28, 2015

Find table skew in teradata

To find skew factor for table in Teradata, we can use below query.


 SELECT 
TABLENAME,
SUM(CURRENTPERM) /(1024*1024) AS CURRENTPERM, 
(100 - (AVG(CURRENTPERM)/MAX(CURRENTPERM)*100)) AS SKEWFACTOR 
FROM 
DBC.TABLESIZE 
WHERE DATABASENAME= 'Mydatabase_name'
AND TABLENAME ='myTable_name'
GROUP BY 1;

Simply replace the "Mydatabse_name" and "myTable_name" and run the query.

Thursday, August 13, 2015

Find "Bad character in format or data" using OTranslate function


Bad character in format or data
======================

This error is reported when you try to translate a (Varchar or char) column with special characters in it to (Decimal or integer).When a query fails with such errors, the primary challenge is to find our where the problems lies and which column might have special character. the answer is where there is explicit or implicit conversion happening from character columns to integer.

More cumbersome job is to find what is that value in column which is causing the issue, here is a technique using which one can identify the value quickly.

example:

  sel roll from perf_app.$ab_temp   WHERE CHAR_LENGTH(roll) <> CHAR_LENGTH(oTranslate(roll, '/_#.'',-*)(:"', ''))


here the sys_fnlib.oTranslate function can identify the special character and provide the lenth of the value after replacing with ''(blank).

Monday, November 10, 2014

Dynamic Hash Join

Dynamic hash join provides the ability to do an equality join directly between a small table and a large table on non‑primary index columns without placing the large table into a spool file. important criteria for dynamic hash join to be used, the left table must be small enough to fit in a single hash join partition.
It process as follows:
1) Duplicate the smaller table.
2) Place the smaller table in a hash array
3) Read a row from the right table
4) Compute the row hash code
5) Match each right row with all rows in the hash array having the same row hash.
6) Join the matching rows.
Dynamic hash join is faster than redistributing the small table, putting it into the hash array, reading the large table, building the row hash code, writing the data out to spool, and then reading the table in again to do the hash join.
The dynamic hash join can be decided by optimizer in case of left, right, and full outer joins as well as inner joins, and can also take advantage of equality conditions for dynamic partition elimination. 

Thursday, February 20, 2014

Create procedure in Teradata


A stored procedure is a database object containing combination of SQL statements and control and condition handling Statements stored in database in compiled form.

Basic Syntax:

    CREATE PROCEDURE ProcedureName (IN/OUT/INOUT fields datatypes)
    BEGIN
    SQL statements;
    END;

Tuesday, February 11, 2014

disable user in Teradata

To disable a user in Teradata we can revoke logon rights from user as below.

Revoke logon on all from myusername;

Sunday, February 2, 2014

Tara process clean up

Follow below steps to check for leftover arcmain processes when we abort a job (best to do this when all jobs have finished running so you don't kill a job that you want to run) And the procedure to restart services properly.

Example below is for Tidwprod 2 node linux bar system Primary: RRI1TDBPL1P and Secondry: RRI1TDBPL2P
Proper steps for restarting services:
a.   Stop the TARA Server services. Once the TARA Server services have stopped, the TARA Client services should stop automatically.
TARA Server
Stop:   /etc/init.d/tdtaraserver stop
Stop:    /etc/init.d/tdtaraclient stop

b.   Verify the TARA Client services have stopped. If not, stop the TARA Client services for each configured machine.
TARA Client
Stop:    /etc/init.d/tdtaraclient stop

c.   Run the netstat command and make sure no connections are still set for the port 54323 (default). If there are still listings with status: ESTABLISHED, CLOSE_WAIT, TIMED_WAIT, etc. wait 5 to 10 minutes to make sure these entries go away.
RRI1TDBPL2P:~ # netstat -pant | grep 54323

d.   Once the tcp connections have been cleared for TARA, start the TARA Server services. The TARA Client services may start automatically (within 5 minutes). Otherwise, start the TARA Client services.
TARA Server
Start:   /etc/init.d/tdtaraserver start
Start:   /etc/init.d/tdtaraclient start

TARA Client
Start:   /etc/init.d/tdtaraclient start

e.   Verify the connections are established between the TARA Server and the TARA Clients by running the netstat command.
TARA SERVER
RRI1TDBPL1P:~ # netstat -pant | grep 54323
tcp 0 0 0.0.0.0:54323 0.0.0.0:* LISTEN 29146/taraserver
tcp 0 0 10.18.33.43:54323 10.18.33.43:40926 ESTABLISHED 29146/taraserver
tcp 0 0 10.18.33.43:54323 10.18.33.45:38522 ESTABLISHED 29146/taraserver
tcp 0 0 10.18.33.43:40926 10.18.33.43:54323 ESTABLISHED 29252/TaraD
tcp 0 0 10.18.33.43:54323 10.18.32.101:4874 ESTABLISHED 29146/taraserver
tcp 0 0 10.18.33.43:54323 10.18.32.101:4960 ESTABLISHED 29146/taraserver

RRI1TDBPL1P:

Wednesday, December 11, 2013

move space in teradata

In teradata permanent space can be moved from one database to another, below is commands in sequence to perform this task.

1. CREATE DATABASE TDAdmin20131211041448 FROM "DBC" AS perm = 322122547200
2. GIVE TDAdmin20131211041448 TO "dba_dat"
3. DROP DATABASE TDAdmin20131211041448

Monday, December 9, 2013

Starting teradata database service in linux(vm)

For Teradata database express edition  installed on Suse linux, we can check the database service status by
command "pdestate".

# pdestate -a
PDE state is START/TVSASTART.  --which indicates database service is up and running.
or
PDE state is DOWN/HARDSTOP.   --- indicates database service is down.

we can start or stop the database service from /etc/init.d as

s10-1310:/etc/init.d # service tpa start/stop.

Note: once we start the database service (tpa), this may take few minute to start and enable logons etc.

Troubleshooting

If you are running into problems getting Teradata started, the first place to check for clues is in the log file:

#tail /var/log/messages
And finally, to check your storage, use the verify_pdisks command:



# verify_pdisks
All pdisks on this node verified.


You may see some warning messages with this, but what we're looking for is the final 'verified' message.

Wednesday, November 20, 2013

Release Hut-Lock in Teradata database


Hut-Lock is placed on table or database by Teradata where there is archive/restore operation is being performed on table/database, ideally the archive/resotre/copy script should include “release lock” command at the end of script to release lock once the operation is complete. But in case if backup script did not mention “release lock” clause or backup job failed with abnormal termination the lock is not release automatically.
In this case we need to release lock manually; we can release Hut- lock in two ways 1. By using arcmain  or by using SQL Assistant/bteq.

Using arcmain to release lock.

Using command prompt or Linux prompt, enter below command.

      > arcmain
         Logon serverip/arcuser1,arcuserpassword;
         Release lock (databasename.tablename);       à to release table level lock.

  Or

         Release lock (databasename);         à to release database level lock.
         Logoff;

Note: In both the cases Teradata expect to use same user (arcuser1) which has put Hut-Lock, if not you can use super                    user with “override” option.
             
              i.e. Release lock (databasename.tablename), override;

Using Sql Assistant/bteq to release lock.

        1. Logon to SQL Assistant using same arcuser1, which accuire lock.
        2.   release lock(databasename.tablename);


Hut-Lock

Host Utility (HUT) Lock is a lock that Teradata ARC utility places when ARC command like ARCHIVE/RESTORE etc. are executed on database or objects with below condition apply.

     1. HUT locks are associated with the currently logged-on user who entered the statement,
         not with a job or transaction.
     2. HUT locks are placed only on the AMPs that are participating in a Teradata ARC
         operation.
     3. A HUT lock that is placed for a user on an object at one level never conflicts with another
         level of lock on the same object for the same user.


We can check the Hut-lock in Teradata database using the ShowLocks Console utility.