Wednesday, October 12, 2011


Reboot required check fails while Installing SQL Server


Some times while installing new SQL Server installation or updating we get Reboot required check failed error, even after rebooting the server for several times we still receive the same error, after doing enough research and some google search came to know that it is due to the one of the registry key. Here are the steps to fix this issue hope this finds helpful:

1.       Go to run and type REGEDIT to open the registry editor.

2.       Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager and locate registry key called PendingFileRenameOperations.

3.       Most of the times by reading the value in this key would give you clear information about what file rename is pending and you can take appropriate actions or you can save the information for feature references if you want and then clear the data in the key.

4.       Now reboot the machine and rerun the installation, if you still happen to face same issues you can go ahead and perform first 3 steps and this time install SQL Server without rebooting the system.

5.       One more simple workaround if you’re installing via command prompt you may use parameter /SkipRules=VSShellInstalledRule RebootRequiredCheck to ignore this reboot check.

Thursday, September 8, 2011

How to add user to sysadmin role or to any other fixed server role

We can add users to sysadmin role or to any fixed server role using T-SQL or using SSMS(SQL Server Management studio) here are the both:
1.       Using T-SQL method
--Create SQL user account Login
USE [master]
GO
CREATE LOGIN [tesuser] WITH PASSWORD=N'test@123', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF

--Create windows user account login
USE master
GO
CREATE LOGIN [DominName\Username] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]
Note: Keep in mind as it is for test purpose I have given simple password, in any live enviorment try and keep complex passwords and if your environment permits use Expiration and policy options with SQL users(Via Active directory we can set password policy for windows users) for better security.
--Add user to sysadmin role
USE master
GO
EXEC master..sp_addsrvrolemember @loginame = N'User Name', @rolename = N'sysadmin'
Note: user name can be SQL user or Window user.
2.       GUI Method
Go to SSMS in the object explorer right click on Security then click on New and then Login you will get following screen
                                              
Key in the login name based on Authentication type (Window or SQL) and password if your are creating SQL Server authenticated user and then click on the Server roles (you can see it on your left hand side) and select sysadmin(shown below) and click OK.

3.       We can test by using following query for accuracy.
SELECT
   spm.name AS 'User Name',
   spr.name AS 'Server Role'
FROM
   sys.server_role_members srm
INNER JOIN
   sys.server_principals spr
   ON spr.principal_id = srm.role_principal_id
INNER JOIN
   sys.server_principals spm
   ON spm.principal_id = srm.member_principal_id
WHERE spm.name = 'testuser'

Tuesday, August 30, 2011

Different Types of backups in SQL Server

  • Full Backup: It’s just full backup of database, it backs up all data and objects that reside in the database but it will not backup objects like jobs and SQL Server logins which don’t reside in database. With the versions prior to the SQL Server 2005, if you execute a full database backup, you could not make any other backups (such as transactional log backup), until the full database backup is completed. But SQL Server 2005 allows you to do two concurrent backups at the same time. If you exceed two the third backup will fail. It’s advised that not to use more than one backup at a time as it will use high disk I/O. Full backup dose not truncate or backup transactional log. Full backup process:
1.       When backup command is executed, SQL server locks the database, blocking all transactions and check points is issued on the database, which writes all deity pages to disk. This ensures that all committed transactions up to the point of backup command will be part of the full backup.
2.       SQL Server makes a mark in the transactional log to point where the full back begins. This is important in the recovery process; SQL Server will use this mark to help validate what combination of files can or cannot be used to restore the database from the full backup, releases lock on the database.
3.       The data is then read out of the database files to the backup files, which is plain text file that is create on disk or tape.
4.       Lock the database, blocking all transactions, and issues checkpoint.
5.       When full backup is completed SQL Server makes another mark in the transaction log.
6.       Release database lock.
7.       Extracts all transactions between the two log marks and append to the backup, by maintaining the consistency of backup for e.g., if someone modifies the data on the pages while backup process, and if he restores the backup he might lose the modified data.
  • Differential database backup: A differential database backup contains only the changes made to the database since the last full backup. The main purpose of differential backup is to reduce the number of transactional log backups that needed to be restored at the time of recovery.  A differential database backup is possible because SQL Server keeps track of the extents that have changed, in an internal bitmap contained within the data file. When the full backup is made bitmap is reset. One bit is used per extent, which is eight physical contiguous 8kb pages (i.e., extent is 8X8 = 64kb), so single 8kb page can map to about 4GB of data. SQL Server creates one of these mapping pages for every 8,192 extents.
  • Transactional log backup: it is a backup of your current transactional log; you can take transactional log back up only if you have taken full backup of the database at least once in its life time. Log backup starts at the log sequence (LSN) number at which previous log backup completed or if it is 1st log backup, it will start at which the full backup was completed. SQL Server then backs up all the subsequent transactions until the backup encounters an open transaction. Once SQL Server encounters the open transaction the log backup completes. Any LSN’s that are backed up will be removed from the transactional log, which enables system to reuse the log space. From recovery standpoint no backup is critical than transactional log backup because it allows you to recover more granular point in time. To apply a transactional log, your database must be restored WITH NORECOVERY or WITH STANDBY. WITH NORECOVERY puts your database in pure loading state where it cannot be used for client connection, but WITH STANDBY puts your database in loading state where clients can access your database in read-only mode, but when a transaction is loaded, the database needs exclusive access to load the log, so it would be unavailable for clients use. Need to read more in page no. 43
  • File and File group backup: File and file group backups are based on the full and differential backups, if your database architecture uses multiple files and file groups, although you can do a standard full or differential backup, you now have the option of doing backups on files or file groups which will make recovery much easier. Although you can do file or file group backup from full or differential backup, the advantage of file or file group backup is when we are doing backup of multi terabyte databases.
  • Partial backup: It possible that some of the file groups in SQL Server database as read only and some of them both (read/write). In previous versions of SQL Server, a full backup captures all extents even if the file group is marker as read only, which meant that there were no changes to the data. SQL Server 2005 introduces a new parameter to the backup command to handle this situation. The READ_WRITE_FILEGROUPS clause causes the backup engine to skip any file groups that are marked as read only, saving time and space in the backup by having the backup engine gather only the set of extents that could change. E.g., BACKUP DATABASE PUBS READ_WRITE_FILEGROUPS TO DISK='C:\DEMO\BACKUP\PUBS1.BAK'
  • Mirror Backup: this is a new feature from SQL Server 2005 onwards, it is the ability to mirror your backup media.
Media Retention: It an instance level option where we can set how long SQL Server can retain backup set. Retaining means within SQL Server you cannot delete it (but it will not prevent doing anything physically on your media) this option is media retention and is considered an advanced configuration option within SQL Server. It is set in days, and the values can be from 0 (the default) to 365.

Configure a Linux Service to Start Automatically After a Crash or Reboot

Configure a Linux Service to Start Automatically After a Crash or Reboot Below articles defines how to start a service automatically after ...