This tutorial shows you how to set up a database mirroring system and what happens when failover occurs. For the purposes of this tutorial, all the database servers are running on the same computer. However in a real mirroring system, you would likely run the database servers on separate computers.
Create the following directories: c:\server1, c:\server2, and c:\arbiter.
Make a copy the sample database located in samples-dir\demo.db, and add it to c:\server1.
For information about samples-dir, see Samples directory.
Create a transaction log for the database located in c:\server1 by executing the following command:
dbping -d -c "UID=DBA;PWD=sql;DBF=c:\server1\demo.db" |
Make copies of the database file and transaction log in c:\server1, and add them to c:\server2.
Run the following command to start the arbiter server:
dbsrv11 -x tcpip(PORT=2639) -su sql -n arbiter -xa "auth=abc;DBN=demo" -xf c:\arbiter\arbiterstate.txt |
This command line specifies the following dbsrv11 options:
-x Instructs the database server to use TCP/IP communications over port 2639. The other servers also use TCP/IP, but communicate on different ports.
-su Specifies the password for the utility database.
-n Names the database server 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.
-xf Specifies the location of the state information file for the arbiter.
Run the following command (it must be typed on one line) to start server1:
dbsrv11 -n server1 -x tcpip(PORT=2638) -xf c:\server1\server1state.txt -su sql c:\server1\demo.db -sn mirrordemo -xp "partner=(ENG=server2;LINKS=tcpip(PORT=2637;TIMEOUT=1));auth=abc; arbiter=(ENG=arbiter;LINKS=tcpip(PORT=2639;TIMEOUT=1));mode=sync" |
This command line specifies the following dbsrv11 options:
-n Names the database server server1.
-x Specifies the port on which the database server runs.
-xf Specifies the location of the state information file for server1.
-su Specifies the password for the utility database.
-sn Specifies the alternate name for the database server. Both the primary and mirror server must have the same name so clients can connect without knowing in advance which server is the primary server, and which server is the mirror server.
-xp Provides information to the server that is being started so it can connect to its partner and the arbiter server.
Run the following command (it must be typed on one line) to start server2:
dbsrv11 -n server2 -x tcpip(PORT=2637) -xf c:\server2\server2state.txt -su sql c:\server2\demo.db -sn mirrordemo -xp "partner=(ENG=server1;LINKS=tcpip(PORT=2638;TIMEOUT=1));auth=abc; arbiter=(ENG=arbiter;LINKS=tcpip(PORT=2639;TIMEOUT=1));mode=sync" |
This command line specifies the following dbsrv11 options:
-n Names the database server server2.
-x Specifies the port on which the database server runs.
-xf Specifies the location of the state information file for server2.
-su Specifies the password for the utility database.
-sn Specifies the alternate name for the database server. Both the primary and mirror server must have the same name so clients can connect without knowing in advance which server is the primary server, and which server is the mirror server.
-xp Provides information to the server that is being started so it can connect to its partner and the arbiter server.
Start Interactive SQL and connect to the primary server by running the following command:
dbisql -c "UID=DBA;PWD=sql;ENG=mirrordemo;LINKS=tcpip" |
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; |
Determine which database server you are connected to by executing the following statement:
SELECT PROPERTY( 'ServerName' ); |
The name of the primary server appears.
Initiate failover. You can do this by stopping the primary server identified in the previous step 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=mirrordemo" |
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 database server messages window for server2 displays a message indicating that it is the new primary server:
Close Interactive SQL. If you receive an error message, click OK.
Restart Interactive SQL by running the following command:
dbisql -c "UID=DBA;PWD=sql;ENG=mirrordemo;LINKS=tcpip" |
Execute the following statement to see that you are now connected to the mirror server:
SELECT PROPERTY ( 'ServerName' ); |
Execute the following statement to verify that all transactions were mirrored to the mirror database:
SELECT * FROM test; |
Disconnect from Interactive SQL, and then click Shut Down on the database server messages window for the arbiter and server2 database servers.
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |