Syspolicy_Purge_History job failing at Step 3 – Erase Phantom System Health Records.

Tonight when I connected to one of the servers to fix something else, I noticed Syspolicy_Purge_History job has been failing and it has been failing for long time.

In SQL server 2008 Policy Based Management was introduced. When policies  are checked for compliance the resulting data is saved in MSDB. The tables are :

  • syspolicy_policy_execution_history_internal
  • syspolicy_policy_execution_history_details_internal
  • syspolicy_policy_category_subscriptions_internal.

The SYSPOLICY_PURGE_HISTORY job is created automatically at the time of install. This job keeps clearing above tables from historical data (older than retention period)

Now, coming to the job, it has been failing on Step 3 for a long time.

s1

A check in job failure log (history) shows :

The job script encountered the following errors. These errors did not stop the script: A job step received an error at line 1 in a PowerShell script. The corresponding line is ‘(Get-Item SQLSERVER:\SQLPolicy\XXXXSQLXX\DEFAULT).EraseSystemHealthPhantomRecords()’. Correct the script and reschedule the job. The error information returned by PowerShell is: ‘SQL Server PowerShell provider error: Could not connect to ‘XXXXSQLXX\DEFAULT’. [Failed to connect to server XXXXSQLXX. –> A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)] Failed to connect to server XXXXSQLXX. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. Correct the script and reschedule the job.

So, the SQL server is not able to connect to itself? Lets see the job step, what is it trying to do. Its trying to run a power shell script:

(Get-Item SQLSERVER:\SQLPolicy\XXXXSQLXX\DEFAULT).EraseSystemHealthPhantomRecords()

That explains. The script is trying to connect to the node instead of the SQL Server instance. XXXXSQLXX is a node name e.g. XXXXSQL01 and XXXXSQL02. The instance name or virtual name is XXXXSQLVSXX.

Change the script to connect to the instance name and save it:

(Get-Item SQLSERVER:\SQLPolicy\XXXXSQLVSXX\DEFAULT).EraseSystemHealthPhantomRecords()

Now the job runs successfully:

S2

About: Niraj Kumar


Leave a Reply

Your email address will not be published. Required fields are marked *