Lesson 1: Creating a database mirroring system

 Set up a database mirroring system
  1. Create the following directories: c:\server1, c:\server2, and c:\arbiter.

  2. Run the following command to create a database named mirror_demo.db that contains data from the sample database:

    newdemo c:\server1\mirror_demo.db
  3. Run the following command to start the first database server:

    dbsrv12 -n mirror_server1 -x "tcpip(PORT=6871;DOBROAD=no)" -su sql "c:\server1\mirror_demo.db" -xp on
    • -n   Names the database server mirror_server1.

    • -x   Specifies the port on which the database server runs.

    • -su   Specifies the password for the utility database. It is recommended that you include the -su option to specify the password for the utility database. Then, you can connect to the utility database to shut down the database server, or force the mirror server to become the primary server, if necessary. See Stopping a database server in a mirroring system and Forcing a database server to become the primary server.

    • -xp on   Indicates that the database server is available to participate in a database mirroring system.

  4. Connect to the database from Interactive SQL:

    dbisql -c "UID=DBA;PWD=sql;SERVER=mirror_server1"
  5. Execute the following statements to define the primary and mirror servers:

    CREATE MIRROR SERVER mirror_demo_primary
    AS PRIMARY
    connection_string='SERVER=mirror_demo_primary;HOST=localhost:6871,localhost:6872';
    
    CREATE MIRROR SERVER mirror_demo_mirror
    AS MIRROR
    connection_string='SERVER=mirror_demo_mirror;HOST=localhost:6871,localhost:6872';
  6. Execute the following statements to define mirror_server1 and mirror_server2 as partners in the mirroring system:

    CREATE MIRROR SERVER mirror_server1
    AS PARTNER
    connection_string='SERVER=mirror_server1;host=localhost:6871'
    state_file='c:\\server1\\server1.state';
    
    CREATE MIRROR SERVER mirror_server2
    AS PARTNER
    connection_string='SERVER=mirror_server2;host=localhost:6872'
    state_file='c:\\server2\\server2.state';
  7. Execute the following statement to define the arbiter server:

    CREATE MIRROR SERVER demo_arbiter
    AS ARBITER
    connection_string ='SERVER=demo_arbiter;HOST=localhost:6870';
  8. Execute the following statement to set the authentication string for the database:

    SET MIRROR OPTION authentication_string='abc';
  9. Disconnect from Interactive SQL.

  10. Make copies of the database file and transaction log in c:\server1, and add them to c:\server2 by running the following command:

    dbbackup -c "UID=DBA;PWD=sql;SERVER=mirror_server1;DBN=mirror_demo" c:\server2
  11. Run the following command to start the second database server:

    dbsrv12 -n mirror_server2 -x "tcpip(PORT=6872;DOBROAD=no)" -su sql "c:\server2\mirror_demo.db" -xp on

    This command line specifies the following dbsrv12 options:

    • -n   Names the database server mirror_server2.

    • -x   Specifies the port on which the database server runs.

    • -su   Specifies the password for the utility database. It is recommended that you include the -su option to specify the password for the utility database. Then, you can connect to the utility database to shut down the database server, or force the mirror server to become the primary server, if necessary. See Stopping a database server in a mirroring system and Forcing a database server to become the primary server.

    • -xp on   Indicates that the database server is available to participate in a database mirroring system.

  12. Run the following command to start the arbiter database server:

    dbsrv12 -n demo_arbiter -su sql -x "tcpip(PORT=6870;DOBROAD=no)" -xf "c:\arbiter\arbiter.state" -xa "AUTH=abc;DBN=mirror_demo"
    • -n   Names the database server demo_arbiter.

    • -su   Specifies the password for the utility database. It is recommended that you include the -su option to specify the password for the utility database. Then, you can connect to the utility database to shut down the database server, or force the mirror server to become the primary server, if necessary. See Stopping a database server in a mirroring system and Forcing a database server to become the primary server.

    • -x   Instructs the database server to use TCP/IP communications over port 6870. The other servers also use TCP/IP, but communicate on different ports.

    • -xf   Specifies the location of the state information file for the arbiter.

    • -xa   Specifies the names of the database(s) being mirrored and the authentication string (in this case abc) for the arbiter server. This authentication string must be used amongst all the servers (arbiter, primary, and mirror) in a database mirroring system.

  13. Start Interactive SQL and connect to the primary server using the alternative server name for the primary server by running the following command:

    dbisql -c "UID=DBA;PWD=sql;SERVER=mirror_demo_primary;HOST=localhost:6871,localhost:6872"
  14. Determine which database server you are connected to by executing the following statement:

    SELECT PROPERTY( 'ServerName' );

    The name of the server that is acting as the primary server appears.

    For example:mirror_server1

  15. Add data to the database by executing the following statements:

    CREATE TABLE test (col1 INTEGER, col2 CHAR(32));
    INSERT INTO test VALUES(1, 'Hello from server1');
    COMMIT;
  16. Proceed to Lesson 2: Initiating failover in a database mirroring system.

 See also