title | description | author | ms.author | ms.reviewer | ms.date | ms.service | ms.subservice | ms.topic | f1_keywords | helpviewer_keywords | dev_langs | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sp_add_log_shipping_secondary_database (Transact-SQL) |
Sets up a secondary database for log shipping. |
MashaMSFT |
mathoma |
randolphwest |
08/21/2024 |
sql |
system-objects |
reference |
|
|
|
[!INCLUDE SQL Server]
Sets up a secondary database for log shipping.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
sp_add_log_shipping_secondary_database
[ @secondary_database = ] 'secondary_database'
, [ @primary_server = ] 'primary_server'
, [ @primary_database = ] 'primary_database'
[ , [ @restore_delay = ] 'restore_delay' ]
[ , [ @restore_all = ] 'restore_all' ]
[ , [ @restore_mode = ] 'restore_mode' ]
[ , [ @disconnect_users = ] 'disconnect_users' ]
[ , [ @block_size = ] 'block_size' ]
[ , [ @buffer_count = ] 'buffer_count' ]
[ , [ @max_transfer_size = ] 'max_transfer_size' ]
[ , [ @restore_threshold = ] 'restore_threshold' ]
[ , [ @threshold_alert = ] 'threshold_alert' ]
[ , [ @threshold_alert_enabled = ] 'threshold_alert_enabled' ]
[ , [ @history_retention_period = ] 'history_retention_period' ]
[ ; ]
The name of the secondary database. @secondary_database is sysname, with no default.
The name of the primary instance of the [!INCLUDE ssDEnoversion] in the log shipping configuration. @primary_server is sysname and can't be NULL
.
The name of the database on the primary server. @primary_database is sysname, with no default.
The amount of time, in minutes, that the secondary server waits before restoring a given backup file. @restore_delay is int and can't be NULL
. The default value is 0.
If set to 1, the secondary server restores all available transaction log backups when the restore job runs. Otherwise, it stops after one file is restored. @restore_all is bit and can't be NULL
.
The restore mode for the secondary database.
0
: Restore log withNORECOVERY
1
: restore log withSTANDBY
@restore_mode is bit and can't be NULL
.
If set to 1
, users are disconnected from the secondary database when a restore operation is performed. The default is 0
. @disconnect_users is bit and can't be NULL
.
The size, in bytes, used as the block size for the backup device. @block_size is int with a default value of -1.
The total number of buffers used by the backup or restore operation. @buffer_count is int with a default value of -1.
The size, in bytes, of the maximum input or output request that is issued by [!INCLUDE ssNoVersion] to the backup device. @max_transfersize is int and can be NULL
.
The number of minutes allowed to elapse between restore operations before an alert is generated. @restore_threshold is int and can't be NULL
.
The alert to be raised when the backup threshold is exceeded. @threshold_alert is int, with a default of 14,420.
Specifies whether an alert is raised when @restore_threshold is exceeded. A value of 1
(the default) means that the alert is raised. @threshold_alert_enabled is bit.
The length of time in minutes in which the history is retained. @history_retention_period is int, with a default of NULL
. A value of 14420 is used if none is specified.
0
(success) or 1
(failure).
None.
sp_add_log_shipping_secondary_database
must be run from the master
database on the secondary server. This stored procedure does the following:
-
sp_add_log_shipping_secondary_primary
should be called prior to this stored procedure to initialize the primary log shipping database information on the secondary server. -
Adds an entry for the secondary database in
log_shipping_secondary_databases
using the supplied arguments. -
Adds a local monitor record in
log_shipping_monitor_secondary
on the secondary server using supplied arguments. -
If the monitor server is different from the secondary server,
sp_add_log_shipping_secondary_database
adds a monitor record inlog_shipping_monitor_secondary
on the monitor server using supplied arguments.
Only members of the sysadmin fixed server role can run this procedure.
This example illustrates using the sp_add_log_shipping_secondary_database
stored procedure to add the database LogShipAdventureWorks
as a secondary database in a log shipping configuration with the primary database [!INCLUDE ssSampleDBobject] residing on the primary server TRIBECA
.
EXEC master.dbo.sp_add_log_shipping_secondary_database
@secondary_database = N'LogShipAdventureWorks',
@primary_server = N'TRIBECA',
@primary_database = N'AdventureWorks2022',
@restore_delay = 0,
@restore_mode = 1,
@disconnect_users = 0,
@restore_threshold = 45,
@threshold_alert_enabled = 0,
@history_retention_period = 1440;
GO