Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 » SQL Anywhere Server - Database Administration » Maintaining Your Database » SQL Anywhere high availability

 

Tutorial: Using database mirroring with multiple databases sharing an arbiter server

In this configuration the primary and mirror servers each host three individual databases participating in mirroring systems. All three mirroring systems communicate with the same arbiter server. Each mirroring system uses a unique alternate server name that is specified using the -sn option. With this type of configuration, the primary, mirror, and arbiter servers can all run on separate computers.

Diagram showing the mirroring system.

If the primary server becomes unavailable, then a role switch occurs and the mirror server takes ownership of the databases. The mirror server becomes the primary server. The client must re-establish a connection to the primary server. The alternate server name is all that needs to be specified to re-establish the connection to the primary server. This configuration also has the ability to protect against failure of a single database. If a database running on the primary server becomes unavailable, then a role switch occurs and the mirror server takes ownership for the failed database. The mirror server becomes the primary server for only this database. The client must re-establish a connection to the primary server for this database using the alternate server name.

To set up a mirroring system with three databases and one arbiter server
  1. Create the following directories:

    • c:\server1
    • c:\server2
    • c:\arbiter
  2. Run the following commands from the c:\server1 directory:

    dbinit one.db
    dbinit two.db
    dbinit three.db
  3. Create a transaction log for each database by running the following commands:

    dbping -d -c "UID=DBA;PWD=sql;DBF=c:\server1\one.db"
    dbping -d -c "UID=DBA;PWD=sql;DBF=c:\server1\two.db"
    dbping -d -c "UID=DBA;PWD=sql;DBF=c:\server1\three.db"
  4. Copy the databases from the c:\server1 directory to the c:\server2 directory.

  5. Start the arbiter server:

    dbsrv11 
    -x tcpip(port=2640) 
    -n arbiter 
    -xa "AUTH=abc,def,ghi;DBN=one,two,three" 
    -xf c:\arbiter\arbiterstate.txt 
    -su sql
  6. Start the databases on server1:

    dbsrv11 
    -n server1 
    -x tcpip(PORT=2638) 
    -xf c:\server1\server1state.txt 
    -su sql 
    c:\server1\one.db 
    -sn mirrortutorial_one 
    -xp "partner=(ENG=server2;LINKS=tcpip(PORT=2639;TIMEOUT=1));
    auth=abc;arbiter=(ENG=arbiter;LINKS=tcpip(PORT=2640;TIMEOUT=1));
    mode=sync" 
    c:\server1\two.db 
    -sn mirrortutorial_two 
    -xp "partner=(ENG=server2;LINKS=tcpip(PORT=2639;TIMEOUT=1));
    auth=def;arbiter=(ENG=arbiter;LINKS=tcpip(PORT=2640;TIMEOUT=1));
    mode=sync" 
    c:\server1\three.db 
    -sn mirrortutorial_three 
    -xp "partner=(ENG=server2;LINKS=tcpip(PORT=2639;TIMEOUT=1));
    auth=ghi;arbiter=(ENG=arbiter;LINKS=tcpip(PORT=2640;TIMEOUT=1));
    mode=sync"
  7. Start the databases on server2:

    dbsrv11 
    -n server2 
    -x tcpip(PORT=2639) 
    -xf c:\server2\server2state.txt 
    -su sql 
    c:\server2\one.db 
    -sn mirrortutorial_one 
    -xp "partner=(ENG=server1;LINKS=tcpip(PORT=2638;TIMEOUT=1));
    auth=abc;arbiter=(ENG=arbiter;LINKS=tcpip(PORT=2640;TIMEOUT=1));
    mode=sync" 
    c:\server2\two.db 
    -sn mirrortutorial_two 
    -xp "partner=(ENG=server1;LINKS=tcpip(PORT=2638;TIMEOUT=1));
    auth=def;arbiter=(ENG=arbiter;LINKS=tcpip(PORT=2640;TIMEOUT=1));
    mode=sync" 
    c:\server2\three.db 
    -sn mirrortutorial_three 
    -xp "partner=(ENG=server1;LINKS=tcpip(PORT=2638;TIMEOUT=1));
    auth=ghi;arbiter=(ENG=arbiter;LINKS=tcpip(PORT=2640;TIMEOUT=1));
    mode=sync"

    After starting server2, the server1 database server messages window shows that server1 is the primary server in the mirroring system for databases one, two, and three. The messages also indicate that the mirror databases for one, two, and three (partners) are connected to server1.

    The arbiter messages show that both server1 and server2 are connected.

  8. Run the following command to start Interactive SQL and connect to database one on the primary server:

    dbisql -c "UID=DBA;PWD=sql;ENG=mirrortutorial_one;LINKS=TCPIP"
  9. Add sample data to the SQL Anywhere sample database by executing the following statements:

    CREATE TABLE test (col1 INTEGER, col2 CHAR(32));
    INSERT INTO test VALUES(1, 'Hello from server1');
    COMMIT;
  10. Determine which database server you are connected to by executing the following statement:

    SELECT PROPERTY( 'ServerName' );

    The name of the primary server appears.

  11. Disconnect from Interactive SQL.

  12. Initiate failover. You can do this by stopping the primary server in one of the following ways:

    • Click Shut Down in the database server messages window.

    • Use the Windows Task Manager to end its task.

    • Issue the following command:

      dbstop -y -c "UID=DBA;PWD=sql;ENG=server1"

    If a warning message appears indicating that the database server still has one connection, click Yes to shut it down.

    The arbiter database server messages window displays a message indicating that the primary server is disconnected.

    The arbiter database server messages window showing that server1 is disconnected.

    The database server messages window for server2 displays a message indicating that it is the new primary server:

    server2 database server messages window.
  13. Restart Interactive SQL by running the following command:

    dbisql -c "UID=DBA;PWD=sql;ENG=mirrortutorial_one;LINKS=tcpip"
  14. Execute the following statement to see that you are now connected to the mirror server:

    SELECT PROPERTY ( 'ServerName' );
  15. Execute the following statement to verify that all transactions were mirrored to the mirror database:

    SELECT * FROM test;
  16. Disconnect from Interactive SQL, and then click Shut Down on the database server messages window for the arbiter and server2 database servers.