sp_change_log_shipping_primary_database (Transact-SQL)

适用于:SQL Server

更改主数据库设置。

Transact-SQL 语法约定

语法

sp_change_log_shipping_primary_database
    [ @database = ] 'database'
    [ , [ @backup_directory = ] N'backup_directory' ]
    [ , [ @backup_share = ] N'backup_share' ]
    [ , [ @backup_retention_period = ] 'backup_retention_period' ]
    [ , [ @monitor_server_security_mode = ] 'monitor_server_security_mode' ]
    [ , [ @monitor_server_login = ] 'monitor_server_login' ]
    [ , [ @monitor_server_password = ] 'monitor_server_password' ]
    [ , [ @backup_threshold = ] 'backup_threshold' ]
    [ , [ @threshold_alert = ] 'threshold_alert' ]
    [ , [ @threshold_alert_enabled = ] 'threshold_alert_enabled' ]
    [ , [ @history_retention_period = ] 'history_retention_period' ]
    [ , [ @backup_compression = ] backup_compression_option ]
[ ; ]

参数

[ @database = ] 'database'

主服务器上的数据库名称。 @primary_database为 sysname,无默认值。

[ @backup_directory = ] N'backup_directory'

主服务器上的备份文件夹的路径。 @backup_directory为 nvarchar(500),没有默认值,不能为 NULL。

[ @backup_share = ] N'backup_share'

主服务器上的备份目录的网络路径。 @backup_share为 nvarchar(500),没有默认值,不能为 NULL。

[ @backup_retention_period = ] 'backup_retention_period'

在主服务器上的备份目录中保留日志备份文件的时长(以分钟为单位)。 @backup_retention_period为 int,无默认值,不能为 NULL。

[ @monitor_server_security_mode = ] 'monitor_server_security_mode'

用于连接到监视服务器的安全模式。

  • 1 = Windows 身份验证
  • 0 = SQL Server 身份验证

@monitor_server_security_mode为,默认值为 NULL。

[ @monitor_server_login = ] 'monitor_server_login'

用于访问监视服务器的帐户的用户名。

[ @monitor_server_password = ] 'monitor_server_password'

用于访问监视服务器的帐户的密码。

[ @backup_threshold = ] 'backup_threshold'

在引发@threshold_alert错误之前上次备份的时间长度(以分钟为单位)。 @backup_thresholdint,默认值为 60 分钟。

[ @threshold_alert = ] 'threshold_alert'

超过备份阈值时引发的警报。 @threshold_alert为 int,不能为 NULL。

[ @threshold_alert_enabled = ] 'threshold_alert_enabled'

指定在超出@backup_threshold是否引发警报。

  • 1:启用
  • 0:禁用

threshold_alert_enabled位,不能为 NULL。

[ @history_retention_period = ] 'history_retention_period'

保留历史记录的时间长度(以分钟为单位)。 @history_retention_period为 int。如果未指定值,则使用值 14420。

[ @backup_compression = ] backup_compression_option

指定日志传送配置是否使用 备份压缩。 SQL Server 2008(10.0.x)(及更高版本)企业版支持此参数,SQL Server 2016(13.x)上的所有版本都支持 Service Pack 1(及更高版本)。

返回代码值

0(成功)或 1(失败)。

结果集

无。

注解

sp_change_log_shipping_primary_database 必须从 master 主服务器上的数据库运行。 此存储过程执行以下操作:

  1. 根据需要更改记录中的 log_shipping_primary_database 设置。

  2. 如有必要,使用提供的参数更改 log_shipping_monitor_primary 主服务器上的本地记录。

  3. 如果监视器服务器与主服务器不同,则根据需要使用提供的参数在 log_shipping_monitor_primary 监视器服务器上更改记录。

权限

只有 sysadmin 固定服务器角色的成员才能运行此过程。

示例

此示例说明如何使用 sp_change_log_shipping_primary_database 更新与主数据库 AdventureWorks2022关联的设置。

EXEC master.dbo.sp_change_log_shipping_primary_database
    @database = N'AdventureWorks',
    @backup_directory = N'c:\LogShipping',
    @backup_share = N'\\tribeca\LogShipping',
    @backup_retention_period = 1440,
    @backup_threshold = 60,
    @threshold_alert = 0,
    @threshold_alert_enabled = 1,
    @history_retention_period = 1440,
    @monitor_server_security_mode = 1,
    @backup_compression = 1;