Sunday 1 January 2012

How to use ARCMAIN to archive and restore partitions for PPI table?



For ARCHIVE:

     ARCHIVE DATA TABLES
     (db_old.tablename) 
     ( PARTITIONS WHERE (! x IN(x_106) !)),
      RELEASE LOCK, 
     FILE=ARCHIVEFILE;
     LOGOFF;


Archive command is used to archive Teradata tables. With PPI tables we have option of archiving only a particular partition.
IN above syntax we need to specify the table name to be archived. Notice the round brackets.
For PPI tables we need to specify the partition to be archived.
The command RELEASE LOCK is necessary because the ARC utility places a HUT(host utility Lock) of the table to be archived which needs to be released.
FILE indicates the file in which the archive needs to be stored.
Notice Semicolon ending the command.


For COPY:

     COPY DATA TABLES
     ( db_new.tablename_XXX  ) (from ( db_old.tablename )),
       RELEASE LOCK,
       FILE=ARCHIVE;
     LOGOFF;

db_new.tablename_XXX is the name of the name of the new table being created. This may be needed if we are restoring the data on same database system as the original table. In that case we need to provide the new table name.
FROM is used to specify which table from the archive file. A single archive may contain multiple tables being archived.
RELEASE LOCK is used to release the HUT lock.
FILE is used to indicate the file which contains the archived tables.
If it into same tablename and there no other tables in archive job not required to give 'from' in COPY syntax.
     COPY DATA TABLES
     ( db_new.tablename ),
     RELEASE LOCK,
     FILE=ARCHIVE;
     LOGOFF;


Additional Examples:

for Archive:
     .logon TDPID/username,passwd;
     ARCHIVE DATA TABLES
     (Students.orders_PPI_M)
     (PARTITIONS WHERE (! o_orderdate = DATE '2000-01-25' !)),
     RELEASE LOCK,
     FILE=ARCHIVE;
     .logoff;
For Copy:
     .logon TDPID/username,passwd;
     COPY DATA TABLES
     (Students.orders_rst )   (from(Students.orders_PPI_M )),
     RELEASE LOCK,
     FILE=ARCHIVE;
     .LOGOFF;

4 comments:

  1. Very Nice Article.
    One Thing:

    Say you have Archived a single partition, then the Restore Operation will only recognise that Single Partition? Say you archived the January month data and only restore command is executed for January and February month. I guess it not possible and give Error.

    ReplyDelete
  2. Hi, Is there a way to make the partition value a variable? Say "current date"?

    ReplyDelete