





















































In today’s tutorial we will assist you to overcome the errors that arise while loading, deleting or updating large volumes of data using Teradata Utilities.
[box type="note" align="" class="" width=""]This article is an excerpt from Teradata Cookbook co-authored by Abhinav Khandelwal and Rajsekhar Bhamidipati. This book provides recipes to simplify the daily tasks performed by database administrators (DBA) along with providing efficient data warehousing solutions in Teradata database system.[/box]
When data is being loaded via FastLoad, a table lock is placed on the target table. This means that the table is unavailable for any other operation. A lock on a table is only released when FastLoad encounters the END LOADING command, which terminates phase 2, the so-called application phase. FastLoad may get terminated in phase 1 due to any of the following reasons:
If so, it keeps a lock on the table, which needs to be released manually. In this recipe, we will see the steps to release FastLoad locks.
Identify the table on which FastLoad is been ended prematurely and tables are in locked state. You need to have valid credentials for the Teradata Database.
Execute the dummy FastLoad script from the same user or the user which has write access to the lock table.
A user requires the following privileges/rights in order to execute the FastLoad:
PUBLIC on the restart log table (SYSADMIN.FASTLOG). There will be a row in the FASTLOG table for each FastLoad job that has not completed in the system.
.LOGON 127.0.0.1/dbc, dbc; /* Vaild system name and credentials to
your system */
.DATABASE Database_Name; /* database under which locked table is */
erorfiles errortable_name, uv_tablename /* same error table name as
in script */
begin loading locked_table; /* table which is getting 2652 error */
.END LOADING; /* to end pahse 2 and release the lock */
.LOGOFF;
As FastLoad is designed to work only on empty tables, it becomes necessary that the loading of the table finishes in one go. If the load script is errored out prematurely in phase
2, without encountering the END loading command, it leaves a lock on loading the table. Fastload locks can't be released via the HUT utility, as there are no technical lock on the table.
To execute FastLoad, the following are some requirements:
If this does not fix the issue, you need to drop the target table and error tables associated with it. Before proceeding with dropping tables, check with the administrator to abort any FastLoad sessions associated with this table.
MLOAD works in five phases, unlike FastLoad, which only works in two phases. MLOAD can fail in either phase three or four. Figure shows 5 stages of MLOAD.
Identify the table which is getting affected by error 2571. Make sure no host utility is running on this table and the load job is in a failed state for this table.
RELEASE MLOAD <databasename.tablename>;
>
/* Release lock in application phase */
RELEASE MLOAD <databasename.tablename> in apply;
The Mload utility places a lock in table headers to alert other utilities that a MultiLoad is in session for this table. They include:
If the release lock statement still gives an error and does not release the lock on the table, you need to use SELECT with the ACCESS lock to copy the content of the locked table to a new one and drop the locked tables.
If you start receiving the error 7446 Mload table %ID cannot be released because NUSI exists, you need to drop all the NUSI on the table and use ALTER Table to nonfallback to accomplish the task.
This error is associated with the UPDATE statement, which could be SQL based or could be in MLOAD.
Various times, while updating the set of rows in a table, the update fails on Failure 7547 Target row updated by multiple source rows.
This error will happen when you update the target with multiple rows from the source. This means there are duplicated values present in the source tables.
Let's create sample volatile tables and insert values into them. After that, we will execute the UPDATE command, which will fail to result in 7547:
** TARGET TABLE**
create volatile table accounts
(
CUST_ID,
CUST_NAME,
Sal
)with data
primary index(cust_id)
insert values (1,'will',2000);
insert values (2,'bekky',2800);
insert values (3,'himesh',4000);
** SOURCE TABLE**
create volatile table Hr_payhike
(
CUST_ID,
CUST_NAME,
Sal_hike
) with data
primary index(cust_id)
insert values (1,'will',2030);
insert values (1,'bekky',3800);
insert values (3,'himesh',7000);
/* Snippet from MLOAD update */
UPDATE ACC
FROM ACCOUNTS ACC , Hr_payhike SUPD
SET Sal= TUPD.Sal_hike
WHERE
Acc.CUST_ID = SUPD.CUST_ID;
Failure: Target row updated by multiple source rows
/*Check for duplicate values in source table*/
SELECT cust_id,count(*)
from Hr_payhike
group by 1 order by 2 desc
/* Update part of MLOAD */
UPDATE ACC
FROM ACCOUNTS ACC ,
( SELECT
CUST_ID,
CUST_NAME,
SAL_HIKE
FROM
Hr_payhike
QUALIFY ROW_NUMBER() OVER (PARTITION BY CUST_ID ORDER BY
CUST_NAME,SAL_HIKE DESC)=1) SUPD
SET Sal= SUPD.Sal_hike
WHERE
Acc.CUST_ID = SUPD.CUST_ID;
Failure will happen when you update the target with multiple rows from the source. If you defined a primary index column for your target, and if those columns are in an update query condition, this error will occur.
To further resolve this, you can delete the duplicate from the source table itself and execute the original update without any modification. But if the source data can't be changed, then you need to change the update statement.
To summarize, we have successfully learned how to overcome or prevent errors while using utilities for loading data into database. You could also check out the Teradata Cookbook for more than 100 recipes on enterprise data warehousing solutions.
2018 is the year of graph databases. Here’s why.
6 reasons to choose MySQL 8 for designing database solutions
Amazon Neptune, AWS’ cloud graph database, is now generally available