The primary and the replicate database can be refreshed from a different database source while existing replication definitions and subscriptions continue to be used.
If the source database has never participated in replication, temporarily add the database to a Replication Server so that it has all the tables and stored procedures needed for replication, before making a copy of it.
This scenario uses a third database (for example, a production database) to populate the source and target database environment (for example, a test database). You would use this scenario when you want to refresh a test system from a copy of a production database.
use pri go sp_reptostandby pri go The replication status for database 'pri' is 'ALL'. The replication mode for database 'pri' is 'off'. (return status = 0)
use pri go sp_setreplicate go Name Type ---- ---------- t1 user table t2 user table rs_marker stored procedure (3 rows affected) (return status = 0)
use pri go dbcc gettrunc go secondary trunc page secondary trunc state dbrepstat ------------------- --------------------- ------- 2669 1 173 generation id database id database name ltl version ------------- ------------ ------------- --------- 0 7 pri 720
use PRS2_RSSD go rs_helpuser go User Name Permission(s) Name ------------ ------------------------------ PRS2_id_user no grants sa sa PRS2_ra connect source PRS2_rsi connect source PRS2_RSSD_prim source, primary subscr Maintenance Users User name Destination DS.DB ------------ ------------------------------------- PRS2_RSSD_maint sunak1505x.PRS2_RSSD pri_maint sunak1505x.pri pri_maint sunak1505x.rep (return status = 0)
In this example, “pri_maint” is the maintenance user for both the connection to the primary database, sunak1505x.pri. and replicate database, sunak1505x.rep.
You can stop all user activity to the source database; however, it is not required.
When a new database is brought online, Adaptive Server creates a database that is transactionally consistent at the time of the dump.
sp_stop_rep_agent pri go The Replication Agent thread for database 'pri' is being stopped. (return status = 0)
isql –Usa –P –SPRS2 suspend connection to sunak1505x.pri go Connection to 'sunak1505x.pri' is suspended suspend connection to sunak1505x.rep go Connection to 'sunak1505x.rep' is suspended.
dump database diffprim to '/c11014900/sybase1520x/diffprim.dmp' go
load database pri from '/c11014900/sybase1520x/diffprim.dmp' go
online database pri go
use pri go sp_adduser pri_maint go New user added. (return status = 0) grant execute on rs_get_lastcommit to pri_maint go grant all on rs_lastcommit to pri_maint go
sp_addlogin <maintenance user>, <maintenance userpassword>, <database> go sp_role "grant", replication_role, <maintenance user> go
alter connection to <dataserver>.<database> set password to <new password> go
use pri go dbcc settrunc (ltm,ignore) go secondary trunc page secondary trunc state dbrepstat -------------------- --------------------- -------- 2667 0 166 generation id database id database name ltl version ------------- ------------ ------------- ---------- 0 7 pri 720
sp_config_rep_agent pri,'disable' go Replication Agent disabled for database 'pri'. The secondary truncation point in the database is no longer active. (return status = 0)
sp_config_rep_agent pri, 'enable','PRS2','PRS2_ra','PRS2_ra_ps' go Replication Agent enabled for database 'pri'. The Replication Agent thread needs to be started using sp_start_rep_agent. (return status = 0)
use PRS2_RSSD go rs_zeroltm sunak1505x,pri go Locater has been reset to zero. (return status = 0) isql –Usa –P –Ssunak1505x use pri go dbcc settrunc (ltm,valid) go secondary trunc page secondary trunc state dbrepstat -------------------- --------------------- -------- 2670 1 167 generation id database id database name ltl version ------------- ------------ ------------- ---------- 0 7 pri 720
dbcc settrunc (ltm,gen_id,1) go secondary trunc page secondary trunc state dbrepstat -------------------- --------------------- -------- 2670 1 167 generation id database id database name ltl version ------------- ------------ ------------- ---------- 0 7 pri 720
load database rep from '/c11014900/sybase1520x/diffprim.dmp' go
online database rep go
use rep go sp_adduser pri_maint go New user added. (return status = 0) grant execute on rs_get_lastcommit to pri_maint go grant all on rs_lastcommit to pri_maint go
sp_addlogin <maintenance user>, <maintenance userpassword>, <database> go sp_role "grant", replication_role, <maintenance user> go
alter connection to <dataserver>.<database> set password to <new password> go
use rep go dbcc settrunc (ltm,ignore) go secondary trunc page secondary trunc state dbrepstat -------------------- --------------------- -------- 2667 0 166 generation id database id database name ltl version ------------- ------------ ------------- ---------- 0 7 pri 720
sp_config_rep_agent rep,'disable' go Replication Agent disabled for database 'rep'. The secondary truncation point in the database is no longer active. (return status = 0)
truncate table rs_lastcommit go
grant all on t1 to pri_maint go grant all on t2 to pri_maint go
isql -Usa -P –SPRS2 sysadmin hibernate_on go The Replication Server has now entered hibernation mode. sysadmin sqm_purge_queue, 104,1 go sysadmin sqm_purge_queue, 106,0 go sysadmin hibernate_off go The Replication Server has now finished hibernation mode.
resume connection to sunak1505x.pri go Connection to 'sunak1505x.pri' is resumed. resume connection to sunak1505x.rep go Connection to 'sunak1505x.rep' is resumed.
sp_start_rep_agent pri go Replication Agent thread is started for database 'pri'. (return status = 0)
admin who go Spid Name State Info ---- -------- ------------ ------------------ 139 DSI EXEC Awaiting Command 104(1) sunak1505x.pri 135 DSI Awaiting Message 104 sunak1505x.pri 129 DIST Awaiting Wakeup 104 sunak1505x.pri 130 SQT Awaiting Wakeup 104:1 DIST sunak1505x.pri 123 SQM Awaiting Message 104:1 sunak1505x.pri 56 SQM Awaiting Message 104:0 sunak1505x.pri 142 REP AGENT Awaiting Command sunak1505x.pri 143 NRM Awaiting Command sunak1505x.pri 145 DSI EXEC Awaiting Command 106(1) sunak1505x.rep 144 DSI Awaiting Message 106 sunak1505x.rep 124 SQM Awaiting Message 106:0 sunak1505x.rep