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
推荐阅读
-
Variable SQLLOGDIR not found
-
intellij出现dependency ‘xxx‘not found
-
【未定义变量】Notice: Undefined variable解决方法
-
libxml2 configure: error: xml2-config not found. Please check your libxml2 installation.
-
Failed to load resource: the server responded with a status of 404 (Not Found)
-
.net core An assembly specified in the application dependencied mainfest<****.json>was not found解决办法
-
brew install php55 报错 BZip2 not found解决办法
-
安装PHP时显示,xml2-config not found怎么办?
-
It is possible that '(a)mxmlc' executable was not found or there are compilation
-
MYSQL:SQL_CALC_FOUND_ROWS和count(*)性能比较_MySQL