Using Aliases with SQL Server
Even an old dog can learn new tricks

I had an Aha! moment recently. For my entire career as a DBA I have generally considered aliases for connections a workaround for bad behaving applications. Whenever someone said «alias» my mind immediately heads to SQL Server client configuration aliases which I try to avoid if at all possible (since they are configured on each client) It never snapped to me until recently that DNS aliases may be a good solution to a few problems we're currently experiencing.
For disaster recovery reasons, as well as for manageability reasons we have decided to start using DNS aliases for every application connection to database servers. This should allow us to have the luxury of moving databases from server to server without having to reconfigure multiple applications which would normally be a whole process in itself since the code was already migrated to production which is locked.
Using DNS aliases should also allow us to swap highly important applications over individually to a remote datacenter, which could have less computing power, without having to switch every application and thus kill the performance of that standby server.
There are certainly limitations to this, if for instance you want to move applications from one named instance to another. In our current environment this isnt much of an issue since many of our production instances are indeed default. The other major limitation to this is any change will have a small amount of downtime while the DNS changes are propgated throughout the network.
One more «gotcha» that weve already run into is vendor applications (surprise surprise) that resolve the DNS name to an ip address and then store that inside the application configuration.
We decided on working out a naming standard that looks like this:
For direct database access, where an application only connects to 1 database the following is used
dsDBNameEnvName
i.e. dsCustomerProd
for an application (like sharepoint) where many databases are going to be accessed we change it a bit
dsAppNameEnvName
i.e. dsSharepointProd
While this isnt necessarily a «new» idea, it was certainly a different idea in our environment and I suspect there are other «DBA's» out there like myself that dont have a habit for using our network skills on a regular basis
Photo courtesy: Ronn Ashore
4 comments
1 month and 17 days ago
Awesome, great timing as this is the exact solution I just implemented thanks to you and the rest of the SQL tweeps via the the #sqlhelp tag. Thanks again!
1 month and 17 days ago
I'm not a network guy - but is this what is also referred to as a CNAME?
If so - I'm doing this exactly, and it helped us seamlessly move databases off of a misconfigured machine with a minimum of downtime and NO app changes. Without CNAMEs, it would have either taken much more downtime, had to have been done piecemeal, and/or would have resulted in apps breaking because we «missed» an obscure configuration setting.
We have a CNAME for each atomic set of databases that we want kept together. Sometimes that means multiple CNAMEs point to the same physical machine, sometimes not.
Works great - no drawbacks so far!
1 month and 17 days ago
Yes, this is exactly describing using a CNAME record in the DNS Server but, you can also use a Host(A) record and point directly back to the IP adress. In our environment, I dont have any say in that matter and we use new Host(A) records pointed directly to IP's. I dont think it really matters but, you're absolutely right Aliases make moves simple.
22 days ago
I'm currently in a migration that will be making use of dns aliases, and have done some testing of moving from a default instance to named instances. You actually can use this still for moving applications from one named instance to another, you have to configure your named instances to listen on the default port 1433. If your named instances listen on 1433 you can connect to them via your alias without specifying the instance name. If these instances reside on the same server, they will need to listen on their own ip addresses so both can use 1433.
The ability to omit the instance name when connecting to an instance listening on 1433 using a dns alias does not appear to work with SQL 2000 client, only 2005 and newer.
Write a comment
If you want to add your comment on this post, simply fill out the next form:
* Required fields
You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>.
No trackbacks
To notify a mention on this post in your blog, enable automated notification (Options > Discussion in WordPress) or specify this trackback url: http://www.allenkinsel.com/archive/2010/01/using-aliases-in-sql-server/trackback/