Preserving DDL and Structure

Modified on Mon, 30 Nov at 12:52 PM

An image copy is only as useful as the knowledge needed to read it. DSN1COPY copies pages exactly as they were written, and every page carries the internal identifiers that Db2 assigned to its database, tablespace and table at the time. To put that data anywhere else, into a test subsystem, into a database created for an investigation, or back into a table that was dropped and created again, those identifiers must be translated, and the target must have exactly the structure the data was written with. Db2 keeps neither once the structure changes: the catalog shows only what exists now. TUC preserves both, the internal identifiers and the DDL, with every structure change, so any image copy can be put to use long after the objects it came from have changed or disappeared.

Key Benefits

Every Change Recorded — Internal identifiers, physical attributes and DDL are preserved for every object, and a new version is kept each time the structure changes.

Copies Between Subsystems — Translation for DSN1COPY is prepared automatically, with source and target compared before a page is copied.

Data From the Past — For investigation, objects are created with the structure of the chosen version, current or past, and the source copies are recovered into them without touching production.

Versions Compared — The DDL of any two versions of a table can be compared, to see exactly what changed and when.

UNDROP — A dropped table is recreated from its preserved DDL and its data is restored from its last image copy, with the old identifiers translated to the new ones.

Fast and Incremental — Each refresh processes only the objects altered since the last one, so the history is always current and there is nothing to prepare on the day it is needed.

Why Image Copies Lose Their Meaning

Every Db2 object has internal identifiers: a database identifier, a tablespace identifier and an identifier for each table and index. They are written into every page and recorded in the image copies. When the same table exists in another subsystem, or is dropped and created again, it gets new identifiers, and DSN1COPY must be told how to translate the old ones into the new ones.

The catalog cannot help with the past. It records the identifiers and the definition of each object as it is now. After an ALTER that changes the structure, the definition the older copies were written with is gone. After a DROP, the identifiers and the DDL are gone altogether, while the image copies of the table may still be on disk. MODIFY RECOVERY makes it worse: once old copies are removed from SYSCOPY, Db2 no longer knows they exist, even though the datasets are still cataloged. Without that knowledge, the copies cannot be safely restored anywhere, and the data in them is lost in practice even though it still exists.


Preserving the Structure With Every Change

TUC keeps its own record of every object, separate from the catalog:

  • Internal identifiers and attributes. For every tablespace, partition, table and index, TUC records the internal identifiers and the physical attributes that DSN1COPY depends on: the type, the page size, the dataset size, the number of partitions, the segment size, the page numbering, the compression, the row format and more.
  • A new version with each change. When an object is altered, the new definition is recorded as the current version, and the previous one is kept as history, with the time it was valid. Each image copy can therefore be related to the version of the structure that was current when it was taken.
  • Dropped objects remembered. When an object disappears from the catalog, its record is kept and marked as dropped, with the date it was found missing.
  • DDL preserved. For every table whose structure changed, the full DDL is generated and preserved with the version, through Db2's own DDL generation service, so the object can be built again exactly as it was.
  • Image copies kept as long as they exist. TUC keeps its own record of the image copies and the flat files that utilities created for each table. A copy stays recorded for as long as its dataset is cataloged, even after MODIFY RECOVERY has removed it from SYSCOPY and even after the table was dropped, so old copies that Db2 no longer knows about can still be found and used.

Fast and Incremental

The preservation is designed to run fast enough to be part of every day. Each refresh looks only at the objects whose alteration time in the catalog is later than the last refresh, and generates DDL only for the tables whose structure really changed. On a subsystem with tens of thousands of objects, the work is driven by the few that changed since the last refresh, not by the size of the subsystem, so the recording can run as often as needed without a heavy cost. It can also be taken at a recorded point of consistency after a copy or a quiesce, and internal identifiers can be extracted from a remote subsystem, so the source of a copy does not have to be local.


Structure Versions in the Dialog

The history is not hidden in tables. For any table, the dialog lists its structure versions, newest first, with the period each one was current and whether it is current, historical or dropped. From the list, the preserved DDL of a version can be displayed, two versions can be compared line by line to show exactly what an ALTER changed, the image copies taken while a version was current can be listed, and a recovery into that version can be generated.


Moving Data From Source to Target

The most frequent use is refreshing test and development environments with production data. TUC matches each source dataset, a pageset or an image copy, to its target object, and prepares the translation of every source identifier into the matching target identifier for DSN1COPY. Before anything is copied, the recorded attributes of source and target are compared, so an object whose structure differs is reported instead of being copied into an incompatible target, and its data can be moved by unload and load instead.

Because the source identifiers are taken from the recording and not only from the live catalog, the copy can come from an image copy taken earlier, from another subsystem, or from a database that has since changed.


When the Target Does Not Exist Yet

Data that is moved by unload and load does not need a target prepared in advance. When the target table is missing, TUC creates it, together with its auxiliary objects, and when it exists but lacks columns, the missing columns are added. Unloaded or discarded rows, or the data of an object that could not be copied page by page, can be loaded into a new table, an archive table or a table that has fallen behind the source.


Restoring Data for Investigation

When the question is what the data looked like last Tuesday, or before an application change, restoring the production table is out of the question. TUC restores the past into a separate place instead, with Db2's redirected recovery: the source image copies are recovered into other target objects, and the source objects are not touched.

Redirected recovery works only when the target objects have the structure the source had when the copies were taken. That is exactly what the preserved versions provide. The structure versions of the table, with the image copies taken while each was current, show which version a given copy needs.

From the chosen version, TUC generates a single job. It first creates the objects with that structure under another database and owner, with the names in the DDL adjusted automatically. It then runs the redirected recovery from the source objects into the new ones. For recent data the current version is used, and the objects are created with the current structure. For data from before an ALTER, the older version is used, and the objects are created as they were then.

The recovery can be taken to a recorded point of consistency, to the last copy or to current. When it runs to current, objects whose source has a non-recoverable event, such as a load without logging, are left out automatically, because their data cannot be rebuilt from the log. The investigation runs against a faithful copy of the table as it was, while production keeps running.


UNDROP

Dropping the wrong table is one of the most expensive mistakes in Db2. The catalog forgets the table at once, its definition and its identifiers disappear, and a normal RECOVER is no longer possible. TUC makes the drop reversible.

Dropped tables are listed with their indexes and the date they were found missing. For each one, the preserved DDL and the recorded image copies and flat files can be displayed, and an UNDROP job can be generated. The job recreates the table, its tablespace and its indexes from the preserved DDL; when the database was dropped too, it is recreated with the same buffer pools and storage group. It then restores the data with DSN1COPY from the last image copy, or from any copy chosen from the list, translating the identifiers of the dropped object into the identifiers of the new one, and rebuilds the indexes that are not copied.

The recovery of a dropped table becomes a generated job, not a weekend of reconstruction.


Without and With TUC

Task Without TUC With TUC
Internal identifiers for DSN1COPYLooked up in each catalog and coded into the job.Recorded and translated automatically.
Target for a loadCreated or altered first, to match the data.Missing tables and columns created automatically.
Structure of an old image copyUnknown once the table was altered.Kept as a version, with its period and its DDL.
Copies removed from SYSCOPYForgotten, although the datasets still exist.Still recorded while the dataset is cataloged.
Investigating past dataRestore production, or rebuild the structure by guesswork.Objects created with the version's structure; redirected recovery into them.
Comparing structuresRead DDL side by side.Versions listed in the dialog; any two compared.
Keeping the history currentA full DDL extract, too slow to run often.Incremental refresh of the objects altered since the last one.
A dropped tableDDL and identifiers lost; data effectively gone.UNDROP job: recreated, restored and indexes rebuilt.

In short — TUC preserves the internal identifiers, the physical attributes and the DDL of every object with every structure change, and keeps them after the object is dropped. With that history, any image copy remains usable: to refresh a test environment, to recover past data into separate objects built with the structure of that time, current or older, for investigation, or to bring back a table that was dropped by mistake.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article