Variable SQLLOGDIR not found
昨天在一数据库(sql server 2008 r2 sp3)上部署了一个作业,今天早上收到告警邮件,作业执行报错“unable to start execution of step 1 (reason: variable sqllogdir not found). the step failed”,刚开始有点莫名其妙,后面检查发现出错的原因是因为在高级选项(advanced)里面的output file使用了标记(tokens),而sql server 2008r2不支持这个。
作业是在sql server 2017下创建、测试的,然后生成作业的相关脚本,部署到sql server 2008 r2上,部分具体的代码如下所示:
exec @returncode = msdb.dbo.sp_add_jobstep @job_id=@jobid, @step_name=n'yoursqldba_index_statistics_maintenance_step_one',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=n'tsql',
@command=n'execute [dbo].[indexoptimize]
@databases = ''user_databases'',
@logtotable = ''y''
execute dbo.indexoptimize @databases = ''user_databases'',
@fragmentationlow = null,
@fragmentationmedium = ''index_reorganize,index_rebuild_online,index_rebuild_offline'',
@fragmentationhigh = ''index_rebuild_online,index_rebuild_offline'',
@fragmentationlevel1 = 5,
@fragmentationlevel2 = 30,
@sortintempdb = ''y'',
@maxdop = 0,
@updatestatistics=''all'',
@statisticssample=80,
@logtotable = ''y''',
@database_name=n'tmisdb',
@output_file_name=n'$(escape_squote(sqllogdir))\indexoptimize_$(escape_squote(jobid))_$(escape_squote(stepid))_$(escape_squote(strtdt))_$(escape_squote(strttm)).txt',
@flags=0
关于标记(tokens) sqllogdir的介绍如下;
(sqllogdir) sql server 错误日志文件夹路径的替换标记 – 例如 $(escape_squote(sqllogdir))。
其实sql server agent的标记(token) sqllogdir是从sql server 2014之后才开始支持的。所以需要修改output file设置,取消标记sqllogdir.
如需测试当前数据库版本是否支持这个比较,可以创建一个简单作业执行下面命令,个人测试发现,sql server 2014以及后续版本才支持这个标记。sql server 2008r2、2012等版本皆不支持。
print '$(escape_squote(sqllogdir))'
参考资料:
https://docs.microsoft.com/zh-cn/sql/ssms/agent/use-tokens-in-job-steps?view=sql-server-2017
上一篇: Web前端开发入门技术之网页制作三要素
推荐阅读
-
mac上adb command not found
-
HTTP 错误 404.3 - Not Found
-
输出出现未定义变量提醒:Notice: Undefined variable: str in
-
PHP localhost Not Found
-
mysql启动报错-server PID file could not be found解决_MySQL
-
linux下配置lamp时候出现The requested URL /info.php was not found on this server问题
-
No Session found for current thread 咋解决?ehcache失效 咋解决?
-
报错:library not found for -lstdc++.6.0.9
-
ORA-01403:no data found 及 select a into b 空值
-
请教Fatal error: Class 'COM' not found in