Search code examples
ibm-midrange

Retrieve a physical file after truncate


I had a user truncate a physical file in a testing DB2 database using some outside client. I can use ftpfile to retrieve it from another catalog, but it won't be the exact same info. But I saw some time ago an administrator finding a file's history, I don't have a way to reach this person, any way doing it?


Solution

  • Do you mean SQL TRUNCATE? The IBM i database does not implement TRUNCATE. Possibly the user ran the SQL DELETE FROM table statement instead. Or the CLRPFM command.

    You can possibly access the contents of the file before it was cleared if the file is journaled. Or, an easier way is if the file was saved to tape or save file.

    Run the DSPOBJD command on the table to display both the last save date of the table. And the journal that the table is journaled to.

    DSPOBJD  LIBNAME/TABLENAME *FILE
    

    If the table was saved before it was cleared you can use the RSTOBJ command to restore the contents of the table.

    If the table is journaled, you can use the DSPJRN command to display the journal entries created when rows were inserted into the table. Then, using the sequence numbers of those journal entries, run the APYJRNCHG command to apply those inserted rows back into the table.

    DSPJRN JRN(STEVE/QSQJRN) FILE((ACED011P))  
    
    APYJRNCHG JRN(STEVE/QSQJRN)  
              FILE((ACED011P))      
              RCVRNG(*CURRENT)      
              FROMENTLRG(668094)    
              TOENTLRG(668094)