Comparing SQL Server configurations via the command-line

Aireforge OmniCompare 0.9.0 was the first release to ship with the CLI module. This is a separate application, allowing comparisons to be called from 3rd party applications, such as SQL Server Agent jobs, custom scripts and software deployment tools including Octopus Deploy. OmniCompare CLI will then feedback basic information using termination or error codes; much like log shipping alerts.

The information required to perform the comparison and the credentials required to access the servers are stored within the .adc export file, therefore the main OmniCompare application will be required to perform any future changes such as new servers or new / updated comparisons.

 

What is OmniCompare?

OmniCompare performs a growing list of comparisons, which can be restricted if certain values are known to differ, such as core count or edition (e.g. Enterprise vs Developer). All comparisons in OmniCompare are available in OmniCompare CLI.
A common use case for OmniCompare is checking production against staging and staging against test. This manual task could be automated using a SQL Server Agent job or building OmniCompare into your deployment process, checking for differences and aborting the release if any are found.

Comparing trace flags via the command-line

Creating the comparison file

Open OmniCompare and select the servers you wish to compare. Once selected, you can now choose a full comparison or restrict it to individual checks.

For the purposes of this blog, we’ll limit the comparison to trace flags.

OmniCompare selection screem
Selecting servers to check and comparisons to run

Note: Although trace flag comparisons work for both SQL Server and AzureDB, many of them are not interchangeable as AzureDB is a very different database to SQL Server. AzureDB also has many trace flags enabled by default (17 at the time of writing).

 

Checking current values

If no differences are found, nothing will be displayed. Although it’s often interesting to check the current values. This can be done by changing the results filter from Differences only to All.

4_nodiff

Showing all results has highlighted that each instance has the non-standard trace flag 1222 enabled, which enabled by Redgate SQL Monitor to improve deadlock information.

OmniComapre results page showing trace flags
OmniCompare comparisons results without a filter

 

Exporting the comparison file

OmniCompare CLI is a lightweight application, therefore the comparison file must be created using the main OmniCompare application and exported. This exported file contains the servers to check, authentication credentials and the comparisons to perform.

To create the .adc file, select the command line icon at the top right of the comparisons section. You will then be prompted to enter a secure password and the location of the saved file.

We will save this file to d:\tf.adc.

Exporting OmniCompare comparison files
Comparison files are currently password protected

 Download OmniCompare (inc. CLI)

Using OmniCompare CLI

The OmniCompare CLI executable resides in the OmniCompare program folder. The argument for the application will be logged out if none are passed in or the help argument (-h) is use.

OmniCompare CLI Commands
omnicomparecli.exe -h

Performing a CLI comparison

To perform a trace flag comparison against the servers detailed above we simply pass in the comparison file and password.

For the purposes of this blog I have enabled full logging, although this should be used for debugging only as a lot of information is logged; especially during full comparisons of large estates.

omnicomparecli.exe -i d:\tf.adc -p <password> -v full
CLI_NoDiff.png
Successful OmniCompare comparison with error code 0

This command could then be run from a SQL Server Agent job or from software deployment tools or from your own custom scripts.

Handling differences

We will now enable trace flag 1117 on the SQL2014 instance to demonstrate how the application changes. OmniCompare CLI has highlighted the change and returned an error code of 1. This error code could be caught and an alert raised or a deployment aborted.

Unsuccessful OmniCompare comparison with error code 1
Unsuccessful OmniCompare comparison with error code 1

 

The information detailed above could be logged to file using the -o command, although a simpler option would be to run the comparison via the OmniCompare application.

OmniCompare difference in trace flag
TF1117 enabled for DEV1\SQL2014

Summary

Discrepancies between configuration settings or database objects can be difficult to identify, especially with larger estates or multiple developer environments. Custom scripts or policy-based management could be used to check some of these settings but they will require updating and only work if the script or rule has been created.

OmniCompare checks a large and growing number of settings, highlighting unexpected changes and preventing configuration drift between instances that should be the same.

Other useful pre-deployment checks

  • Counts of database objects (tables, columns, indexes, functions, views etc.).
  • Server triggers,
  • CLR assemblies,
  • Trace flags,
  • Operators, users or permissions have been applied,
    and database settings such as delayed durability, RCSI etc.

Download OmniCompare (inc. CLI)

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.