5.2. SHADOW
A shadow is an exact, page-by-page copy of a database. Once a shadow is created, all changes made in the database are immediately reflected in the shadow. If the primary database file becomes unavailable for some reason, the DBMS will switch to the shadow.
This section describes how to create and delete shadow files.
5.2.1. CREATE SHADOW
Creates a shadow file for the current database
Available inDSQL, ESQL
Syntax
CREATE SHADOW [IF NOT EXISTS] <sh_num>
[{AUTO | MANUAL}] [CONDITIONAL]
'filepath'
CREATE SHADOW Statement Parameters| Parameter | Description |
|---|---|
sh_num | Shadow number — a positive number identifying the shadow set |
filepath | The name of the shadow file and the path to it, in accord with the rules of the operating system |
The CREATE SHADOW statement creates a new shadow.
When IF NOT EXISTS is specified, the statement will not raise an error if the shadow already exists.
The shadow starts duplicating the database right at the moment it is created. It is not possible for a user to connect to a shadow.
The page size for shadow files is set to be equal to the database page size and cannot be changed.
If a calamity occurs involving the original database, the system converts the shadow to a copy of the database and switches to it.
The shadow is then unavailable.
What happens next depends on the MODE option.
5.2.1.1. AUTO | MANUAL Modes
When a shadow is converted to a database, it becomes unavailable. A shadow might alternatively become unavailable because someone accidentally deletes its file, or the disk space where the shadow files are stored is exhausted or is itself damaged.
If the AUTO mode is selected (the default value), shadowing ceases automatically, all references to it are deleted from the database header, and the database continues functioning normally.
If the
CONDITIONALoption is set, the system will attempt to create a new shadow to replace the lost one. It does not always succeed, however, and a new one may need to be created manually.If the MANUAL mode attribute is set when the shadow becomes unavailable, all attempts to connect to the database and to query it will produce error messages. The database will remain inaccessible until either the shadow again becomes available, or the database administrator deletes it using the
DROP SHADOWstatement.MANUALshould be selected if continuous shadowing is more important than uninterrupted operation of the database.
You can verify the location of the shadow file(s) by connecting to the database using isql and running the command SHOW DATABASE;
5.2.1.2. Who Can Create a Shadow
The CREATE SHADOW statement can be executed by:
Users with the
ALTER DATABASEprivilege
5.2.1.3. Examples Using CREATE SHADOW
Creating a shadow for the current database as
shadow number 1
:CREATE SHADOW 1 'g:\data\test.shd';
See alsoSection 5.1.1, “CREATE DATABASE”, Section 5.2.2, “DROP SHADOW”
5.2.2. DROP SHADOW
Drops (deletes) a shadow file from the current database
Available inDSQL, ESQL
Syntax
DROP SHADOW [IF EXISTS] sh_num
[{DELETE | PRESERVE} FILE]
DROP SHADOW Statement Parameter| Parameter | Description |
|---|---|
sh_num | Shadow number — a positive number identifying the shadow set |
The DROP SHADOW statement deletes the specified shadow for the current database.
When IF EXISTS is specified, the statement will not raise an error if the shadow does not exist.
When a shadow is dropped, all files related to it are deleted and shadowing to the specified sh_num ceases.
The optional DELETE FILE clause makes this behaviour explicit.
On the contrary, the PRESERVE FILE clause will remove the shadow from the database, but the file itself will not be deleted.
5.2.2.1. Who Can Drop a Shadow
The DROP SHADOW statement can be executed by:
Users with the
ALTER DATABASEprivilege
5.2.2.2. Example of DROP SHADOW
Deleting shadow number 1
.
DROP SHADOW 1;
See alsoSection 5.2.1, “CREATE SHADOW”