Using CREATE SHADOW

From InterBase

Go Up to Creating a Database Shadow


Use the CREATE SHADOW statement to create a database shadow. Because this does not require exclusive access, it can be done without affecting other users. A shadow can be created using a combination of the following options:

  • Single-file or multifile shadows
  • Auto or manual shadows
  • Conditional shadows

These options are not mutually exclusive. For example, you can create a single-file, manual, conditional shadow.

The syntax of CREATE SHADOW is:

CREATE SHADOW set_num [AUTO | MANUAL] [CONDITIONAL]
 'filespec' [LENGTH [=] int [PAGE[S]]] [<secondary_file>];

Where:

<secondary_file> = FILE 'filespec' [<fileinfo>] [<secondary_file>]
<fileinfo> = {LENGTH[=]int [PAGE[S]] | STARTING [AT [PAGE]] int } [<fileinfo>]

Creating a Single-file Shadow (Using CREATE SHADOW)

To create a single-file shadow for the database employee.ib, enter:

CREATE SHADOW 1 'employee.shd';

The shadow is associated with the currently connected database, employee.ib. The name of the shadow file is employee.shd, and it is identified by a shadow set number, 1, in this example. The shadow set number tells InterBase that all of the shadow files listed are grouped together under this identifier.

To verify that the shadow has been created, enter the isql command SHOW DATABASE:

SHOW DATABASE;
Database: employee.ib Shadow 1: '/usr/interbase/employee.shd' auto PAGE_SIZE 1024 Number of DB pages allocated = 392 Sweep interval = 20000

The page size of the shadow is the same as that of the database.

Shadow Location (Using CREATE SHADOW)

On non-NFS systems, which includes all Microsoft Windows machines, the shadow must reside on the same host as the database. You cannot specify a different host name or a mapped drive as the location of the shadow.

On UNIX systems, it is possible to place the shadow on any NFS-mounted directory, but you run the risk of losing the shadow if you experience problems with NFS, so this is not a recommended procedure.

Creating a Multifile Shadow (Using CREATE SHADOW)

You can create multifile shadows, similarly to the way you create multifile databases. To create a multifile shadow, specify the name and size of each file in the shadow set. File specifications are platform-specific.

The following examples illustrate the creation of a multifile shadow on a UNIX platform. They create the shadow files on the A, B, and C drives of the IB_bckup node.

The first example creates a shadow set consisting of three files. The primary file, employee.shd, is 10,000 database pages in length and the first secondary file is 20,000 database pages long. The final secondary file, as always, grows as needed.

CREATE SHADOW 1 'D:/shadows/employee.shd' LENGTH 10000
FILE 'D:/shadows/employee2.shd' LENGTH 5000
FILE 'D:/shadows/employee3.shd';

Instead of specifying the page length of secondary files, you can specify their starting pages. The previous example could be entered as follows:

CREATE SHADOW 1 'D:/shadows/employee.shd' LENGTH 10000
FILE 'D:/shadows/employee2.shd' STARTING AT 10000
FILE 'D:/shadows/employee3.shd' STARTING AT 30000;

In either case, you can use SHOW DATABASE to verify the file names, page lengths, and starting pages for the shadow just created:

SHOW DATABASE;
Database: employee.ib
Owner: SYSDBA
Shadow 1: "D:\SHADOWS\EMPLOYEE.SHD" auto length 10000
file D:\SHADOWS\EMPLOYEE2.SHD starting 10000
file D:\SHADOWS\EMPLOYEE3.SHD starting 30000
PAGE_SIZE 1024
Number of DB pages allocated = 462
Sweep interval = 20000
Note:
The page length allocated for secondary shadow files need not correspond to the page length of the database’s secondary files. As the database grows and its first shadow file becomes full, updates to the database automatically overflow into the next shadow file.

Auto Mode and Manual Mode (Using CREATE SHADOW)

A shadow can become unavailable for the same reasons a database becomes unavailable: disk failure, network failure, or accidental deletion. If a shadow becomes unavailable, and it was created in AUTO mode, database operations continue automatically without shadowing. If a shadow becomes unavailable, and it was created in MANUAL mode, further access to the database is denied until the database administrator intervenes. The benefits of AUTO mode and MANUAL mode are compared in the following table:

Auto vs. manual shadows
Mode Advantage Disadvantage

AUTO

Database operation is uninterrupted

Creates a temporary period when the database is not shadowed; the DBA might be unaware that the database is operating without a shadow.

MANUAL

Prevents the database from running unintentionally without a shadow

Halts database operation until the problem is fixed; needs intervention of the DBA

Auto Mode (Using CREATE SHADOW)

The AUTO keyword directs the CREATE SHADOW statement to create a shadow in AUTO mode:

CREATE SHADOW 1 AUTO 'employee.shd';

Auto mode is the default, so omitting the AUTO keyword achieves the same result.

In AUTO mode, database operation continues even if the shadow becomes inoperable. If the original shadow was created as a conditional shadow, a new shadow is automatically created. If the shadow was not conditional, you must create a new shadow manually. For more information about conditional shadows, see Conditional Shadows.

Manual mode (Using CREATE SHADOW)

The MANUAL keyword directs the CREATE SHADOW statement to create a shadow in manual mode:

CREATE SHADOW 1 MANUAL 'employee.shd';

Manual mode is useful when continuous shadowing is more important than continuous operation of the database. When a manual-mode shadow becomes unavailable, further connections to the database are prevented. To allow database connections again, the database administrator must remove the old shadow file, delete references to it, and create a new shadow.

Conditional Shadows (Using CREATE SHADOW)

A shadow can be defined so that if it replaces a database, a new shadow will be automatically created, allowing shadowing to continue uninterrupted. A shadow defined with this behavior is called a conditional shadow.

To create a conditional shadow, specify the CONDITIONAL keyword with the CREATE SHADOW statement. For example:

CREATE SHADOW 3 CONDITIONAL 'employee.shd';

Creating a conditional file directs InterBase to automatically create a new shadow. This happens in either of two cases:

  • The database or one of its shadow files becomes unavailable.
  • The shadow takes over for the database due to hardware failure.


Advance To: