Replication database commands

You can use commands to modify the replication database configuration.

The commands are as follows:
  • CREATE DATABASE <db_name> REPLICATION SET <replsetname>

    Creates a new replicated database and assigns it to the specified replication set. You must issue this command from the primary; issuing it from a replica results in an error. To add an existing database to the set, use the ALTER DATABASE command.

  • ALTER DATABASE <db_name> REPLICATION SET <replsetname>

    Adds an existing database to a replication set. You must issue this command from the primary.

    Issuing the ALTER DATABASE...REPLICATION SET command initiates by-value replication, which can degrade performance.

    After adding a database to a replication set by using this command, you must perform the required initialization steps by using the nzreplanalyze -needsrecovery command (unless you add the database to the replication set before registering the replica), nzreplbackup command, and nzreplrestore command. After you initialize or recover the node, by-SQL replication resumes.

  • ALTER DATABASE <db_name> REPLICATION NEEDS RECOVERY FOR <sub_node>

    Manually marks the named database on the specified replica node for recovery. When you add a replica node to a replication set or when you add a database for replication, the software automatically marks the database for recovery, so this command is not needed. Use the command only when you determine that due to circumstances other than those mentioned, a replica's database needs recovery.

    After a database is marked, transactions that read from or write to the database are replicated by value on all nodes in the replication set until you recover the database on the replica. (This can degrade performance.) The primary continues logging transactions that read from or write to the marked database. The recovering replica continues replicating other databases but skips transactions for the database that is being recovered. Some of the skipped transactions will never be applied, and some will be applied after recovery, depending on whether the transactions occur before or after the recovery data is acquired on the primary. Either way, other replicas in the set continue replicating. Also, there is an additional period in which the primary continues logging by value until all previously active transactions are complete (are committed or rolled back).

    Run the command from the primary. In the cases of both manual and automatic marking, use the nzreplanalyze -needsrecovery, nzreplbackup, and nzreplrestore commands to recover the replica, which removes the mark and reinitiates by-SQL replication.

  • ALTER DATABASE <db_name> REPLICATION RECOVERED AT <master_node> <recovered_to_CSN>

    Marks the specified database as being recovered through an external method other than the nzreplanalyze, nzreplbackup, and nzreplrestore command procedure. For example, you might be able to use the nz_migrate utility or an ETL tool for recovery, but every situation depends on the circumstances. Use the ALTER DATABASE command with caution, however, because you can use it to mark a database as recovered even if it is not entirely synchronized. Marking a database as recovered allows the primary to replicate by SQL and allows the recovered replica to start replicating transactions for the recovered databases. If the database is not in sync, primary-replica data divergence can result.

    Run this command from the replica that needs database recovery.

  • ALTER DATABASE <db_name> REPLICATION SET NONE

    Removes the specified database from the replication set. Run this command only on the primary node.

    If there are no active transactions against the specified database or active transactions against other replicated databases that reference the specified database, the command removes the specified database from the replication set. No further updates to the database are replicated.

    If there are active update transactions against the database, the transactions are not logged, but they are processed normally and do not fail. When all corresponding replicated transactions that relate to this database are finished being applied on the replica nodes, the database becomes a normal, local database on all nodes.

    The ALTER DATABASE <db_name> REPLICATION SET NONE command requires exclusive access to the database. If the command does not have exclusive access, it fails.

  • ALTER DATABASE <db_name> RENAME TO <new_db_name>

    Alters the name of the specified database. This is an NPS® command, but it impacts the replication environment. You cannot alter the name of a database with running update transactions. In that case, the command fails and generates an error message. When you apply the command to a replicated database, you must run the command on the primary.