Enabling replication of truncate table

If you are using Adaptive Server Enterprise version 11.5 or later, you can enable replication of the truncate table command to particular destination database tables when you create or define a subscription.

The truncate table command can truncate one or more partitions. Replication Server will recreate the same command executed at the primary database. This requires the replicate site to have the same partition names, otherwise, DSI shuts down.

You have an option to skip the truncate table command and apply appropriate action at the replicate site, or use rs_truncate function string to customize the action in the replicate site. Replication Agent sends this command once the LTL version is set to 700.

To create or define a subscription that enables replication of truncate table, log in to Replication Server and enter:

create subscription subscription
	for table_rep_def 
	with replicate at data_server.database
	 ...
	subscribe to truncate table

When truncate table executes at the destination database, Adaptive Server deallocates whole data pages. It does not delete rows one at a time.

NoteReplication Server executes truncate table at the replicate database as the maintenance user. Among the permissions granted to maintenance user is replication_role. If you revoke maintenance user’s replication_role, you cannot replicate truncate table unless the maintenance user has been granted sa_role, the maintenance user owns the table, or the maintenance user is aliased as the Database Owner.

Warm standby applications can copy the execution of truncate table to standby databases without a subscription. See “Replicating truncate table to standby databases” on page 107 in the Replication Server Administration Guide Volume 2 for information about using this feature.

See define subscription and create subscription in Chapter 3, “Replication Server Commands” in the Replication Server Reference Manual for complete command syntax and usage guidelines.

Changing the Status of “subscribe to truncate table”

All subscriptions for a replicate table in a particular database must either support or not support replication of truncate table. You cannot create a subscription that enables replication of truncate table if all existing subscriptions for that table do not support replication of truncate table.

Use the sysadmin apply_truncate_table command to change the status of “subscribe to truncate table” for all subscriptions on a replicate table.

For example, to turn on replication of truncate table for all subscriptions to a replicate table, log in to the replicate Replication Server and execute this command at the isql prompt:

sysadmin apply_truncate_table, data_server,
 database, {table_owner|’’|””}, table_name'on'

where data_server is the name of the replicate data server, database is the name of the replicate database managed by the data server, table_owner is the owner of the replicate table, and table_name is the name of the replicate table.

If you specified a replicate table owner in the replication definition, you must also specify a table owner with the sysadmin apply_truncate_tablecommand. If you did not specify a replicate table owner in the replication definition, enter '' (two single-quote characters) or ““ (two double-quote characters) for the table owner name.

Refer to Chapter 3, “Replication Server Commands” in the Replication Server Reference Manual for more information about sysadmin apply_truncate_table command.