Robert's SQL Blog

My thoughts on SQL Server, PowerShell and Microsoft products in general.
@rhartskeerl
Follow me on Twitter

[Dutch] SQL Zaterdag komt er weer aan!

Komend najaar organiseert PASS Nederland alweer de 4e SQL Zaterdag. De vorige editie was ondanks het stralende lente weer goed bezocht en een groot success.

De komende tijd is het druk op SQL gebeid. Denali CTP3 is pas vrijgegeven voor het publiek en hierin zitten genoeg leuke dingen om een hele zaterdag mee te vullen. Maar ook buiten Denali om is er nog heel wat te beleven.

Waarom moet je naar SQL Zaterdag komen? Ten eerste, het kost je niets! Alleen een vrije zaterdag. We streven ernaar om SQL Zaterdag op zaterdag gratis te houden. Voor de meesten is dit namelijk al kostbare vrije tijd. Ten tweede, je ontmoet mensen met een passie voor SQL, je leert nieuwe dingen, kan anderen nieuwe dingen leren en wie weet vind je hier het antwoord op een langlopend probleem. Op dit moment is er nog geen datum en locatie bekend maar reken op een zaterdag in november ergens in de buurt van Zeist. Reken ook op internationale sprekers (en zeker niet de eerste de beste!). Houd in ieder geval de website http://www.sqlzaterdag.nl in de gaten of http://twitter.com/sqlzaterdag.

Laat het ook weten als je een onderwerp graag voorbij ziet komen. PASS Nederland en SQL Zaterdag zijn community evenementen en het heeft geen nut als het één grote marketing show wordt van nieuwe features en tools. Om het meeste uit SQL Zaterdag te halen moet je zelf aan de slag.

Heb je een leuk idee gebruik dan één van deze kanalen om het te laten weten:

Email: mailto:robert@hartskeerl.nl
Twitter: http://twitter.com/rhartskeerl of http://twitter.com/sqlzaterdag
Facebook: http://www.facebook.com/rhartskeerl
LinkedIn: http://www.linkedin.com/rhartskeerl

Tot SQL Zaterdag 4

 

Why is syspolicy_purge_history failing?

If you are running SQL Server 2008 you might know this job. It’s created when you install SQL Server and maintains some of the policy subsystem. Some if you might have experienced errors with this job. Especially when you are running on a cluster. Some information on this error can be found in the following KB article: http://support.microsoft.com/kb/955726.

Recently I came across a failing syspolicy job on a cluster. Immediately I thought the KB article applied here, especially when the client mentioned the job had never succeeded. But this was not the case. The error was different and over time the error changed as well. Step 3, the PowerShell command, was failing with an “cannot create process because file is in use.”.

So, that’s all, no mentioning what file whatsoever. I took the statement from the jobstep and ran it in a SQLPS sessions. That worked. So, nothing wrong with PowerShell (how could it be?).

Next step was to identify what file was in use. For this I used Process Monitor from SysInternals, available on TechNet. I started Process Monitor and started the job waiting for it to fail. I then took the output from Process Monitor and filtered it on the SQLAGENT process, searching for clues. And I found this:


10:29:39.4536352 AM	SQLAGENT.EXE	5620	QueryOpen	C:\Program	SUCCESS	CreationTime: 5/21/2011 5:12:59 PM, LastAccessTime: 5/21/2011 5:12:59 PM, LastWriteTime: 5/21/2011 5:12:59 PM, ChangeTime: 5/29/2011 8:10:54 AM, AllocationSize: 0, EndOfFile: 0, FileAttributes: A
10:29:39.4539617 AM	SQLAGENT.EXE	5620	QueryOpen	C:\Program	SUCCESS	CreationTime: 5/21/2011 5:12:59 PM, LastAccessTime: 5/21/2011 5:12:59 PM, LastWriteTime: 5/21/2011 5:12:59 PM, ChangeTime: 5/29/2011 8:10:54 AM, AllocationSize: 0, EndOfFile: 0, FileAttributes: A
10:29:39.4541972 AM	SQLAGENT.EXE	5620	CreateFile	C:\Program	SHARING VIOLATION	Desired Access: Read Data/List Directory, Execute/Traverse, Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: n/a, ShareMode: Read, Delete, AllocationSize: n/a
10:29:39.4544379 AM	SQLAGENT.EXE	5620	CreateFile	C:\Program	SHARING VIOLATION	Desired Access: Execute/Traverse, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: n/a, ShareMode: Read, Delete, AllocationSize: n/a
10:29:39.4548114 AM	SQLAGENT.EXE	5620	WriteFile	F:\MSSQL10_50.KCCSQL\MSSQL\Log\SQLAGENT.OUT	SUCCESS	Offset: 10,784, Length: 464

So, the Agent was trying to get a handle on a file named C:\Program but couldn’t. I checked the file system and there was indeed a file Program in C:. Actually, Windows already warned about this file when I logged onto the machine. The file was 0KB in size and created some time ago. Next step was to identify the process that was creating this file. Since the file was in use according to the Agent it should be easy to get the process using another SysInterals tool, Process Explorer. I opened Process Explorer and searched for C:\Program. It returned the guilty program for me.

Next step was to find out why this program created this file. In this case it turned out someone forgot to put double quotes around a value in a configuration file. After I corrected this and restarted the service I was able to delete the file Program. I went back to the Agent and started the syspolicy job. This time with success.

Again, the SysInterals tools prove to be of great value when searching for problems beyond the obvious. Although it’s questionable why a program would create a file named Program in this folder but it shouldn’t fail the job.

A new summer, a new job

Summer is a few days away, although in Holland the best days are already behind us. When spring comes we clean our houses, get stuff organized and loose these extra Christmas pounds so we can enter the summer with brand new energy. All of the above apply to me but this year I will add “Start a new job” to the list.

As per July 1st I will be joining Microsoft as a Premier Field Engineer. I’m really excited about this job and can’t wait to get started. Homebase will be the nice office at Schiphol in the Netherlands and from there I will be assisting Premier customers with their SQL related questions and problems. Of course, after the proper training.

Will I keep blogging here? Time will tell, but if it’s not on this blog it will be on another. I love getting into SQL Server and share my experience with others!

A great DevDays Experience

In the past I have attended DevDayhs several times. A nice local event with great sessions about development. Either with .NET, Wp7, Blend, Lego or anything. This year I went in as a speaker. Which was fun to. I had a great time doing the session on SQL Server and PowerShell. As promised I have a link here to the scripts I used and the Powerpoint.

Add-Sql Script from BooksOnline
SqlServer Script with SMO functions like backup, create DB
Powerpoint slides

If you missed DevDays or want to view some of the sessions you missed check them out at Channel 9, http://channel9.msdn.com/Events/DevDays/DevDays-2011-Netherlands

The sessions are a mix of Dutch and English. All non-dutch speakers are English of course, but some of the dutch speakers did an English session as well.

If you have questions feel free to contact me through this site or twitter.

Unable to install Windows Installer MSP file

Sometimes when you patch SQL Server you get an error. Most times when you get an error it’s your own fault, or better someone else’s. I had such an experience recently and wanted to share some information on why this is happening and of course how to resolve it. There is already a great blog post on the subject. Although the error number is different it does apply; http://blogs.msdn.com/b/sqlserverfaq/archive/2009/01/30/part-1-sql-server-2005-patch-fails-to-install-with-an-error-unable-to-install-windows-installer-msp-file.aspx

So what’s the problem. In this case a SQL 2005 installation was upgraded to SP1 – SP2 – CUSomething and needed to be patch to the next CU. But applying this CU failed with the error in this title. First thing to check with installer errors is the summary.txt file in the Bootstrap\Log folder. So here is an excerpt of my log file.

Product Installation Status
Product                   : SQL Server Database Services 2005 (MSSQLSERVER)
Product Version (Previous): 3077
Product Version (Final)   :
Status                    : Failure
Log File                  : C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\LOG\Hotfix\SQL9_Hotfix_KB976952_sqlrun_sql.msp.log
Error Number              : 1635
Error Description         : Unable to install Windows Installer MSP file

As this is a summary there is not much detail about the actual error. All you can tell I’m coming from SQL 2005 build 3077. Luckily the location of the detailed log is mentioned. Now, here are some lines of interest from that file.

MSI (s) (A4:A8) [13:20:30:996]: Opening existing patch ‘C:\WINDOWS\Installer\3d482d64.msp’.
MSI (s) (A4:A8) [13:20:30:996]: Note: 1: 2203 2: C:\WINDOWS\Installer\3d482d64.msp 3: -2147287038
MSI (s) (A4:A8) [13:20:30:996]: Couldn’t find local patch ‘C:\WINDOWS\Installer\3d482d64.msp’. Looking for it at its source.
MSI (s) (A4:A8) [13:20:30:996]: Resolving Patch source.
MSI (s) (A4:A8) [13:20:30:996]: User policy value ‘SearchOrder’ is ‘nmu’
MSI (s) (A4:A8) [13:20:30:996]: User policy value ‘DisableMedia’ is 0
MSI (s) (A4:A8) [13:20:30:996]: Machine policy value ‘AllowLockdownMedia’ is 0
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Media enabled only if package is safe.
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Looking for sourcelist for product {4A35EF4A-D868-4B15-A84D-3E8925AA9558}
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Adding {4A35EF4A-D868-4B15-A84D-3E8925AA9558}; to potential sourcelist list (pcode;disk;relpath).
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Now checking product {4A35EF4A-D868-4B15-A84D-3E8925AA9558}
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Media is enabled for product.
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Attempting to use LastUsedSource from source list.
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Trying source e:\01dddf5653431568a309\HotFixSQL\Files\.
MSI (s) (A4:A8) [13:20:30:996]: Note: 1: 2203 2: e:\01dddf5653431568a309\HotFixSQL\Files\sqlrun_sql.msp 3: -2147287037
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Source is invalid due to missing/inaccessible package.
MSI (s) (A4:A8) [13:20:30:996]: Note: 1: 1706 2: -2147483647 3: sqlrun_sql.msp
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Processing net source list.
MSI (s) (A4:A8) [13:20:30:996]: Note: 1: 1706 2: -2147483647 3: sqlrun_sql.msp
MSI (s) (A4:A8) [13:20:30:996]: SOURCEMGMT: Processing media source list.
MSI (s) (A4:A8) [13:20:32:011]: SOURCEMGMT: Resolved source to: ‘sqlrun_sql.msp’
MSI (s) (A4:A8) [13:21:27:667]: Note: 1: 1314 2: sqlrun_sql.msp
MSI (s) (A4:A8) [13:21:27:667]: Unable to create a temp copy of patch ‘sqlrun_sql.msp’.
MSI (s) (A4:A8) [13:21:27:667]: Note: 1: 1708
MSI (s) (A4:A8) [13:21:27:667]: Note: 1: 2729
MSI (s) (A4:A8) [13:21:27:667]: Note: 1: 2729
MSI (s) (A4:A8) [13:21:27:683]: Product: Microsoft SQL Server 2005 — Installation failed.

There is one thing that you can notice here. Apparently 3d482d64.msp and file sqlrun_sql.msp are missing. One file from C:\Windows\Installer and one apparently from the temporary folder we are installing the hotfix from. The first answer is correct, the second not. During extraction of the hotfix I noticed the folder getting created and it was different then the one listed here. So, a file is missing. All you  need to find out is which file.

Now there are a couple of leads to get you to the actual missing file. It’s not sqlrun_sql.msp. This file is included with all packages and the 3d482d64 is actually a randomly renamed version of sqlrun_sql.msp at the time the patch was applied. We need to know what the original package was.

A search for the guid inside the registry failed (4A35EF4A-D868-4B15-A84D-3E8925AA9558). It turns out the installer saves the guid in a different format. There is some documentation on this. Basically the characters are reversed by sequence. The complete string in my case became A4FE53A4868D51B48AD4E39852AA5985 which can be found in the registry. Another key from the package was the instance key (this is one of the first guids in the logfile). With the same conversion trick you can find that in the registry under the key HKLM\Software\MicrosoftWindows\CurrentVersion\Installer\UserData\S-1-5-18\Products\<GUID>. This is the key for the installed instance, in my case SQL Server 2005. More interesting, underneath it is a subkey Patches with a value of the earlier guid (4A35EF4A etc.). One of the values there stated SQL Server 2005 Service Pack 2.

In the post mentioned earlier it stated to copy the correct msp file with the correct name to Windows\Installer. That works if you are only upgrading one part of SQL, eg the engine. If you are also updating Reporting Services or Integration Services more files need to be copied. What I did was download the servicepack 2 files, exctracted them by running the setup with the /x parameter. When asked for the path, I provided the path from the logfile (e:\01dddf5653431568a309). After the package was extracted I ran the hotfix that failed before again and it succeeded.

Lesson learned is to never throw away files in system folders. We all know this but in this case diskspace was getting tight and someone decided to remove old files. Even then, get bigger disks. Again, look at this post: http://blogs.msdn.com/b/sqlserverfaq/archive/2009/01/30/part-1-sql-server-2005-patch-fails-to-install-with-an-error-unable-to-install-windows-installer-msp-file.aspx. It’s somewhat different from my problem but the steps outlined are quite alike. There are some good resources mentioned there as well.

 

Why not use Local System?

As a security best practice you run SQL Server under a domain account and the agent runs under another domain account. These domain accounts are not in the Domain Users group and certainly not in the Domain Admins group. Well, that’s how it should be and luckily most of the times it is. In most companies it’s also not uncommon to see a separation of duties between roles. The most skilled Windows professionals have Administrator privileges on the Operating System but cannot access installed SQL Server installations. And there is no direct need for SQL DBA’s to access the Operating System. In short, Windows Admin equals Administrator and DBA equals SYSADMIN.

Recently I have come accross a lot of installation that use LOCAL SYSTEM as the service account for SQL Server. This is not a best practice and I wanted to take this moment to show why you should not do this. And I will it works two ways as well. If you are an OS Admin you don’t want it and if you are a DBA you don’t want it as well.

First off, why should an OS Admin care if SQL is running as LOCAL SYSTEM. That’s easy, xp_cmdshell runs in the context of the service account, regardless the user who is executing the command. With LOCAL SYSTEM an SQL User can gain all sorts of permissions on the operating system you don’t want it to have. All a hacker has to do is try to elevate his permissions in SQL and since a simple webportal requires SYSADMIN permissions these days this should be no problem. Of course that’s not true but a lot of people still don’t understand what least privileged means. Running as LOCAL SYSTEM is bad from an OS perspective because you are running with the highest credentials.

But for DBA’s it’s a problem as well and this comes down to the same part as the OS Admins. If you are running SQL as LOCAL SYSTEM and thus granting LOCAL SYSTEM SYSADMIN privileges you are implicit granting all services and processes running under the LOCAL SYSTEM context full control over your SQL installation. Do you wonder what that is? Try this simple powershell oneliner to get all running services that run as LOCAL SYSTEM:

gwmi win32_service | where {$_.StartName -eq “localSystem” -and $_.Started -eq $true} | ft

So, that’s around 45 on my Windows 2008 R2 system. This means 45 processes I don’t control have access to my installation. So, now you might reconsider running SQL as LOCAL SYSTEM. Perhaps this little demonstration will make DBA’s understand the danger.

I have a plain SQL Instance, nothing fancy, just running as LOCAL SYSTEM. The only users on the system are all the builtin users present after the installation.

All an attacker, or co-worker who want access to the data, has to do is get a handle to a LOCAL SYSTEM process, create a SYSADMIN user or elevate privileges and he is off. This isn’t as hard as you think. Windows has made it real easy for you, provided you have the proper OS privileges, to start a process with LOCAL SYSTEM credentials. One way is called Windows Scheduler. The Windows Scheduler runs as LOCAL SYSTEM. All there is to it, is to schedule a task that runs a SQL Query and schedule it for one time in the future nearby, like one minute away. Get some coffee and when you return the scheduler has kicked the process and you are now officially SYSADMIN. The next screenshot shows an example of a scheduled task adding a login and granting it SYSADMIN privileges. The task is set to run as NT AUTHORITY\SYSTEM and scheduled for 19:25.

At the given time the task will run and if you query sys.server_principals you will see a user is added at the time the task ran.

And this is just one example. Almost all hacking scenarios involve getting control over high privileged system processes. True, only admins on the box can do this, but they can be your biggest threat. I used to work in a highly secured environment where we did not have to worry about people from the outside getting in, this was just not possible. The biggest threat becomes the people on the inside. Administrators who want the job done quickly and elevate their permissions, users who try to gain more access than required. Sometimes without meaning to, but sometimes with a cause. It’s not an uncommon scenario these days people on the inside are getting the information outside or use this information to their advantage. So, should you care about securing yout environment and tighten security on the inside as well. I think you should. At least be aware of dangers and risks involved. If they don’t apply to your organization that’s fine, if they do; follow the best practices and use a domain account. And remember, this domain account does not have to be a Domain User as well. This is done by default, but not necessary to run SQL Server. And remember, it’s no use to use a Domain account and then add LOCAL SYSTEM as user granting it SYSADMIN because some other service needs this.

[Dutch] SQL Bits aan zee dag 3

Inmiddels zit het  erop en ben ik weer veilig op nederlandse bodem. SQL Bits heeft een goede indruk op mij achtergelaten. Het niveau van de sessies was hoog en de keuze divers. De locatie was prachtig en goed bereikbaar. Het station was 10 minuten lopen en een treinritje naar Gatwick Airport kost rond de 9 pond. Een half uur later sta je op het vliegveld. Vliegen naar Amsterdam was in een uurtje gedaan dus voor je het weet zit je weer in Nederland.

Ik eindigde de tweede dag met een sessie van Allan Mitchell over StreamInsight. Er wordt veel over gepraat en iedereen heeft inmiddels wel de demo’s gezien over beurskoersen etc. Allan liet echter ook een voorbeeld zien dat DBA’s meer aanspreekt waarbij hij profiler tracedata via een StreamInsight adapter liet zien. StreamInsight heeft zeker toekomst maar het is mij nog steeds niet helemaal duidelijk waar en wanneer ik nu StreamInsight krijg. De dag werd afgesloten met een hapje en een drankje. Drankjes waren niet gratis maar vouchers kon je verdienen door met de sponsors te praten of tijdens sessies goede vragen te stellen. Of in de buurt van Andre Kamman te blijven die een soort voucher magneet heeft/is.

De laatste en gratis dag was ook het drukst bezocht. Deze dag was ook volgepakt met sessies waarvan de eerste al om 08:10 begon. Dus als je dacht dat SQL Zaterdag al vroeg was, het kan vroeger. De eerste sessie heb ik overgeslagen om echt even van een prachtige ochtend te genieten. Ik was op tijd terug om de sessie van Ross Mistry over het consolideren en virtualiseren van SQL Server. Een aantal kent Ross Mistry nog wel van de Euro Pass Conference waar hij ook regelmatig aanwezig was. Tegenwoordig werkt hij voor Microsoft. Hij heeft diverse boeken geschreven over diverse onderwerpen. Het was echt een goed verhaal waar goed de verschillen naar voren kwamen tussen consolideren van databases, instances of virtualiseren. Maar ook de kosten en het beheer dat hiermee gepaard gaat. Dit was ook een van de eerste sessies over dit onderwerp waarbij ik zag dat virtualisatie vaak ook meerdere verschillende Windows versies, verschillende SQL versies etc. met zich meebrengt. Ook zie je vaak dat het aantal virtuele servers behoorlijk toeneemt ten opzichte van het aantal fysieke servers.

Daarna heb ik een sessie gevolgd van Gary Short over ORM tooling en het beeld dat daarbij leeft. Traditioneel is er een mismatch tussen dba’s en developers. DBA’s willen alles netjes in stored procedures terwijl developers het liefst los gaan met LINQ en dynamic SQL. Hij had voor beide kanten goede punten en uiteindelijk is het beste van twee werelden mogelijk, stored procedures in combinatie met een ORM tool. Hij sloot zijn sessie af met een pleidooi voor NoSQL achtige toepassingen en liet een demo zien van RavenDB. Het zal zeker toepasbaar zijn en schalen maar niet overal en altijd. Net als met SQL, it depends.

De laatste sessie voor de lunch was van Klaus Aschenbrenner die een verhaal en wat demo’s had over de interne structuur van een datafile. Dingen die je wel gelezen of gehoord hebt maar hier ineens tot leven kwamen. Na de lunch was het weer tijd voor de sponsorsessies. Omdat de lunch bestond uit een ondefinieerbare lunchbag heb ik van de gelegenheid gebruik gemaakt  om in Brighton te gaan lunchen. Ik kwam 10 minuten te laat terug voor de sessie van Andre Kamman. Omdat ik deze gemist had op SQL Zaterdag wilde ik hem graag zien. Dit was echter jammer maar helaas. Andre had zeker niet de grootste ruimte maar het zat echt stampvol. Gelukkig was het ook vanuit de deuropening te volgen. Uiteindelijk werd de zaterdag afgesloten met een sessie over Performance Tuning en aansluitend weer een hapje en een drankje.

Terugkijkend was het een geslaagd evenement. Ook de prijs was zeker goed voor het niveau van de sessies. Zelfs de volgepakte zaterdag had voor iedereen iets. Ik nodig ook iedereen uit om op de SQL Bits site  (http://www.sqlbits.com) te kijken naar de opgenomen sessies en het volgende keer in levende lijve mee te maken.

Nu kijken of er een locatie is voor een SQL Zaterdag aan zee….

[Dutch] SQL Bits aan zee Dag 1 en 2

Deze week wordt voor de achste maal SQL Bits georganiseerd door de SQL Community in Engeland. Ooit vergelijkbaar met onze versie van SQL Zaterdag maar inmiddels uitgegroeid tot een top evenement verspreid over drie dagen. Om een globale indruk te geven hoe het eruit ziet:

Dag 1: Training day
Deze dag staat in het teken van een onderwerp dat de hele dag behandeld wordt. Dit zijn uiteenlopende zaken zoals StreamInsight, BI methodologie en High Availability. Dat zijn slechts voorbeelden. Deze worden over een hele dag onder de loep genomen en echt in detail uitgewerkt.

Dag 2: Sessies
Dag 2 begint met een keynote gevolgd door verschillende paralelle sessies. Deze dag zie je de beste sprekers en de meest gewilde sessies en pakken de sponsoren uit met gratis WP7 telefoons, XBOX Kinects, licenties voor hun software etc.

Dag 3: Nog meer sessies
Dag 3 begint heel vroeg en heeft maar liefst 33 sessies, waarvan 6 sponsor sessies.

Dag 1 en 2 zijn betaald en dag 3, de zaterdag, is gratis.

Meer informatie kun je vinden op de SQL Bits site zelf inclusief alle voorgaande edities. Kijk ook vooral naar de eerste SQL Bits en het aantal sessies en vergelijk dat eens met deze editie.

De dag van gisteren stond in het teken van een training day. Ik heb de sessie van Alan Hirt gevolgd over High Availability (http://www.sqlbits.com/information/Event8/Practical_SQL_Server_High_Availability/TrainingDetails.aspx). En omdat de sessie verspreid was over een hele dag ging hij vrij diep in op de materie. Persoonlijk vond ik het ook erg goed dat hij verschillen tussen Windows 2003 en Windows 2008 (R2) belichtte maar ook combinaties met SQL Server 2000, 2005 en 2008 (R2). Wat wel duidelijk naar voren kwam is dat clustering behoorlijk verbeterd is in Windows 2008. Het offline halen van de SQL resources wanneer je een disk wilt toevoegen is bijvoorbeeld niet meer nodig. En ook MS DTC is gewijzigd in Windows 2008 waar we nu een MS DTC per instance kunnen maken. Verder werd ook security onder de loep genomen. Blijkbaar hoef je geen domain admin te zijn om een cluster te bouwen, verrassend. Het voorlaatste deel was bestemd voor de mogelijkheden buiten clustering zoals Database Mirroring, Log Shipping en replicatie en hoe deze met elkaar samenwerken of juist niet. Als afsluiter dan de nieuwe features in Denali.

Vandaag was een sessies dag. De ochtend bestond uit een keynote van Mark Souza, general manager van het SQL Server team. En als je dacht dat hij alles wel verteld had over Denali dan had je moeten komen. Vriendelijk verzoek van Mark was om hetgeen dat hij liet zien niet verder te vertellen, voorlopig. Er zitten zeker wat interessante wendingen in en ik ben vrij zeker dat Denali een grote impact gaat maken. Maar helaas, nog even wachten dus. In het laatste stuk van Mark zijn keynote zat nog een verhaal van Fusion IO. Het was een heel kort verhaal maar werd netjes naar de essentie teruggebracht. En wat zij aanhaalden heb ik wel eerder gezien. De processor capaciteit en vermogen groeit harder dan de IO’s die we naar disk kunnen sturen of ons netwerk. Dit betekend dat we onze processoren niet volledig kunnen gebruiken. En dit is natuurlijk goed nieuws voor een heleboel virtualisatie consultants maar het probleem ligt ergens anders. En deze trend zet alsmaar door. Processoren worden sneller terwijl de subsystemen achter blijven. Het probleem is dat dit vaak niet duidelijk naar voren gehaald wordt. Maar als je de processor verbeeld als een fabriek met arbeiders en de disks en netwerk als een lopende band dan wordt duidelijk dat wanneer je veel medewerkers hebt maar een langzame lopende band, de medewerkers het relatief rustig hebben. Je zou dan met minder medewerkers af kunnen. Dat is een verlies dat direct zichtbaar is en dagelijks voorkomt in onze processoren. Nu lost Fusion IO dat probleem niet direct voor je op maar als jij afstapt van een SAN (dat niet goedkoop is) en teruggaat naar ouderwets lokale storage kun je uiteindelijk goedkoper uit zijn en betere performance halen en meer gebruik maken van de processor capaciteit.

Ik heb een sessie gevolgd van Conor Cunningham over update queries. Een goed en duidelijk verhaal hoe updates (en insert/deletes) werken en hoe je dit kan lezen uit het query plan. Uiteindelijk klinkt het allemaal heel logisch en had je het zelf kunnen verzinnen, sort of. De volgende sessie was een verhaal over Modeling for Extreme DW van Tomas Kejser van het SQL Cat team. Het was een theoretisch verhaal, duidelijk en to the point. De derde sessie van de dag was een sponsor sessie. Niet de meest populaire denk ik en daarom had Simon Sabin in de opening verteld wat je allemaal kon winnen bij welke sessie. Ik ben naar de sessie van Kevin Kline gegaan puur omdat ik weet dat het een goede spreker is en hij niet continu Quest software aan het verkopen is. Hij zal het zeker noemen maar alleen wanneer nodig. De keuze was goed. Het was een hele leuke sessie met Bingo en trivia vragen over SQL Server en IT in het algemeen. Degene die bingo had als eerste en alle vragen goed kon een WP7 telefoon winnen. De sessie liep uit omdat er meer bingo ballen waren dan vragen maar uiteindelijk kwam er een winnaar uit en zijn de meeste antwoorden behandeld. De vragen liepen uiteen van; hoevel bits zitter er in een byte, hoevel non clustered indexen kun je hebben op een tabel in SQL Server 2008 tot wat was de naam van het eerste internet en welk bedrijf had een reclame in de superbowl van 1984. Heel leuk en goed gedaan. En ja, er kwamen ook twee vragen over Quest software.

Morgen een update over de andere sessies van vandaag en de eerste van morgen. En om nog een gelijkenis met SQL Zaterdag te trekken, een foto van het weer.

 

Denali style availability groups for SQL 2005+

One of the new features in Denali is Availability Groups. We can fail-over databases as a group and as an extra bonus we can have multiple mirrors. Back in November Andre Kamman (@andrekamman) returned from the PASS Summit and showed the new features to the Dutch audience. One of the remarks was the need for Windows Clustering. I was pretty sure at that moment it was used to control the fail-over of a group and connect to a virtual name. Later at the 24 Hours of PASS there was another Denali HADR demo where the configuration was explained in more detail. From that moment I was really sure why they we’re using Windows Clustering.

Now, new versions are great but at this moment a lot of people are still using SQL 2000. So, it could be some people cannot use these new features simple because they do not use the latest version of SQL Server. This could be budget, company regulations or any other reason.

Given the techniques used in Denali I was sure some of these could apply to SQL 2005 and higher. SQL 2000 would be out of the picture simply because it doesn’t support database mirroring. I wanted to accomplish the following:

  • Fail-over databases as a group
  • Allow connections to be made to a virtual name instead of Principal and Mirror in connection string

I did some scanning and playing with the Cluster Administration and found it was possible to add a Generic Service as a cluster resource. This led me to a solution where a service running inside a Windows cluster would control the group fail-overs. Also, the cluster would register a network name and IP-address that could be used to connect to the databases. And this turned out te be a great solution. It was some work to get things connected but with the use of an extra table in MSDB and watching the WMI Database Mirror State Change it turned out to be easy. So, what’s going on.

  • I created a table in MSDB. This one table holds the configuration. It contains the names and service-names of the two SQL Servers involved (Principal and Mirror), the name of the group to distinguish the group and a delimited list of the databases in this group. This table needs to exist on both SQL Servers and contain the same information.
  • A Windows Service is created and installed. By default it runs as LOCAL SYSTEM and is set to manual. A configfile is included with this service and contains the connectionstrings for both nodes and the Virtual Server name. Different services can be installed for each group. Pretty much like SQL Server instances.
  • Next up is a Windows Cluster. If you have the basic cluster running create a new Application. This is al straightforward. Choose Generic Service as the application and you will be presented with a list of all installed services including the one we just installed. We are not using shared disks or shared registries so we can skip these options. Provide a network name and IP-address when asked.
  • When that’s done our service lives as a cluster resource. If the service is started it checks if the databases for this group are on that machine, if so, nothing happens. If the databases are running on the other node, it will fail-over all databases to this node.
  • If all databases are on the same node as the service is running it just sits and waits until something happens. If you fail-over one of the databases in the group, it will be detected by the service and the service will failover as well. When the service starts on the other node it will again check if all databases are on that node and will fail these over if needed.
  • A client can connect on the virtual network name, simply because this resolves to the active node as well thanks to the Windows cluster.

The code I used is at the end of the post. To install the service you run: installutil.exe /servicename <Name of the service> <path to the executable>. To run multiple instances of the service you must create multiple directories, as with SQL. Change the config files according to your situation, they are pretty self explanatory.

You need to create a table in MSDB as well on both SQL Servers and insert the configuration. A .sql file is included in the solution. In this example I used the LOCAL SYSTEM account for the service. This required me to add the computer account (DOMAIN\HOSTNAME$) as a login to be able to fail over. For simplicity I did put this account in SYSADMIN but that’s not required. I know this is very bad, but allowed for testsystems, at least in my environment.

So it needs some polishing and more shining here and there but I am satisfied with the first result. I am able to mimic the behaviour of Denali Availability Groups. Let me know if this is something you would want to use. If people are interested I might polish it.

Download Visual Studio 2010 solution here.

Installing SQL Denali on Windows Core Ed. Can it be done?

When SQL Server 2008 was released within the timeframe of Windows Server 2008 R2 some people posted on installing SQL on Windows Core Edition. The installation required .NET so we had to wait for Windows Server 2008 R2. The Windows Core editions are console based, there is no GUI, no taskbar, no start button and no way to accidentally click on Shutdown Server.
Installing Core edition is faster because less stuff is needed, less memory is used and less patches and hotfixes are needed. And who needs a GUI on a server anyway. I have used Linux in the past, at present and will in the future and I like how easy it is to set up servers with it. Installation is quick, startup is fast and typing commands is a lot quicker than clicking through intuitive user interfaces. Luckily Windows can provide you the same experience with the Core edition.
I’ve installed SQL 2008 on Core Ed. before and I wanted to see if it could be done with Denali, the next version of SQL Server. I tried this back in november when CTP1 was released and found it unsuccessful. Why, because Denali needs the .NET Framework 4.0 which cannot be installed on Core editions. That is, up until now. With the release of SP1 for Windows 2008 R2 support for installing the .NET Framework 4.0 is added. You might missed it between all the news about virtualization changes but it is there. Download this special .NET 4.0 Core installation package. To install Denali on 2008 R2 Core follow the following steps.

  1. Install Windows 2008 R2 Core Edition with SP1. This is a breeze, just follow onscreen instructions.
  2. Change password upon first login when prompted.
  3. Use sconfig to rename the server, configure the network etc. Restart the machine if needed.
  4. Install WOW64: DISM /Online /Enable-Feature /FeatureName:ServerCore-WOW64
  5. Install .NET 2.0: DISM /Online /Enable-Feature /FeatureName:NetFx2-ServerCore
  6. Install .NET 2.0 WOW64: DISM /Online /Enable-Feature /FeatureName:NetFx2-ServerCore-WOW64
  7. Install .NET 3.5: DISM /Online /Enable-Feature /FeatureName:NetFx3-ServerCore
  8. Install .NET 3.5 WOW64: DISM /Online /Enable-Feature /FeatureName:NetFx3-ServerCore-WOW64
  9. Install .NET 4.0 by running the downloaded package.
  10. Enable PowerShell: DISM /Online /Enable-Feature /FeatureName:MicrosoftWindowsPowerShell
  11. Run sconfig and apply all patches.

Now there is a problem running the SQL installation. SQL failed because it will need a reboot package. This is the same on a normal installation but I could not get it installed on Core edition. I kept getting back the message that the update did not apply to my system. Either the package is confused or I already have the update. But SQL would not install and fail on the check if this fix was already installed.
To get around this problem I used a trick,an undocumented feature in the installation which you should never use on production machines. But who’s running CTP1 in production? Nobody right? This is the full command I used to install SQL on my Core installation.

setup.exe /q /ACTION=Install /FEATURES=SQL /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT=&quot;NT AUTHORITYSYSTEM&quot; /AGTSVCACCOUNT=&quot;NT AUTHORITYNETWORK SERVICE&quot; /IACCEPTSQLSERVERLICENSETERMS /INDICATEPROGRESS /AGTSVCSTARTUPTYPE=Automatic /SQLSYSADMINACCOUNTS=DOMAINUSER /TCPENABLED=1 /SkipRules=NoReboot

To break it down (it’s all in Books Online though):

  • - ACTION=Install means install it.
  • - FEATURES=SQL means to only install the DB Engine,Full-Text Search and Replication
  • - Then Instancename, SQL Service account, Agent Service account
  • - IACCEPTSQLSERVERLICENCETERMS is mandatory when performing unattended installations.
  • - INDICATEPROGRESS puts the output to the console. Handy if you are a fast reader.
  • - SQLSYSADMINACCOUNTS is required to gain access to SQL after installation.
  • - TCPENABLED is to enable TCP connection. Remember to open up the correct port in the windows firewall.
  • - SkipRules=NoReboot is the catch. This will skip the rule that checks the existence of the required package.

And when that’s all finished, reboot again (shutdown -r -t 0) et voila (SKU 13 is Standard Core Edition, see the WIN32_OperatingSystem class for more info).

Denali Core Install