Sunteți pe pagina 1din 15

SQL KT Q. How Many databases do you handle? A.

We handle around 400 servers of which 150 are Production Databases and rest are development and test boxes. Q. What is the Max Size of the database that you handle? A. We have a database which is 1.2 TB in size and the rest range from 600Gigs to 100 Gigs, some are less than 100Gig. Q. RFC Strategies? A. 1) Emergency --- Needs Escalation or Proof of Incident 2) Normal --- For Production Servers, Planned Activity 3) Routine --- ITG and Development Q. GDBA TEAM A. PCPM Team (Problem Change and Performance Management Team) Change management Approval Por Team -- Responsible for enhancements, functionality etc.. Docs Team (Database Operations Center) Purely Production Support Team. Fixs runtime Bugs, Supports Mission Critical, Entity Essential and Normal Applications SLA Mission Critical Applications have Top Priority; have to be owned within 15 Min. and closed within 3 Hrs. time. Basic Problems Encountered by Docs Team are 1) Tlog issues. Like Tlogs full, failed backup etc Backup Strategy Followed By Hp. 1) Full Backup Taken Weekly mostly on Sundays at 2 am in the nights.On Tape 2) Differential Backup Taken Daily Except Sundays On Tape 3) TLog Backup Every 1Hr or 15 Min. depending on application Criticality. On Disk

Monitoring Tools Used At HP 1) DBSPY 2) SCOM (Microsoft system center operations manager) Day Day Responsibilities at HP 1) Service Desk -- DB Full, TLog Full, Backup Failures, and user requests. 2) Off Service Desk --- Health Check, Proactive work on clustered servers Password expirations Space issues (server space and database space 80%) Apply Patches (Before applying Patches or Upgrades test them on Test Servers and ITG then only perform on Production servers) 3) Every Box has Downtime Window. Have to inform users regarding maintenances even when performed during downtime window and raise RFC. Profiler: Used only on user request. Running Profiler hits the Performance Find out suitable time to Run Profiler from Application Team before Running Profiler.

Q. How do you start sql server in single user mode? A. To start SQL Server in single user mode: 1. Start a command session (start > Run > "cmd" [Return]). 2. To ensure that SQL Server is not running type: net stop MSSQLServer This may say that this will also stop another service (typically SQLSERVERAGENT), in which case allow it to continue. It will also indicate if the service is already stopped. 3. To start SQL Server in single user mode type: sqlservr -m If this is not recognised then cd to 'C:\Program Files\Microsoft SQL Server\MSSQL\BINN' and try again.

Note: Single User mode will allow only a single user to connect to the database. While SQL Server is in single user mode you should still be able to connect from SQL Server Query Analyzer if you connect using the "sa" account. You can set a single database into single user mode using an alternative procedure described here: How to set a single database into Single User Mode - but this process cannot be used to set the MASTER database into single user mode, for that you must start SQL Server in single user mode. To shutdown the server when it is in single user mode, simply type Control-C in the command window where sqlservr is running. It will then ask you if you wish to shutdown SQL Server. You can then restart SQL Server by restarting the SQL Server process: net start MSSQLServer be aware that this will not start any other processes which may have been stopped, such as SQLSERVERAGENT. So if any other processes where stopped then you will need to manually restart them (or reboot if that is easier - assuming the necessary services are set to start automatically)

Restoring master database requires the SQL Server running in single user mode. To start SQL Server in single user mode : Open "Control Panel->Administrative Tools->Services" Mouse right click on specified SQL Server instance service and select "Properties" menu to bring up following configuration window:

Specify start parameters as following: -s{ Instance name } -m or (for Named instance , -sSQL2000 -m) -m)

-m (for Default instance , Restart the SQL Server instance service

You must start an instance of SQL Server in single-user mode when you use DBCC CHECKDB/CHECKTABLE with REPAIR options The correct way to run a DBCC CHECKDB or DBCC CHECKTABLE statement with valid REPAIR options is to start SQL Server normally and then explicitly set the database in single user mode. You can do this from either the Enterprise Manager or the Query Analyzer. From Enterprise Manager: 1. Right-click the database name, and then click Properties. 2. In the Properties dialog box, click Options. 3. Select the single user option, and then click OK.

From Query Analyzer: Use master go sp_dboption dbname, single, true After the database is in single user mode, you can then run the DBCC CHECKDB or DBCC CHECKTABLE statements with the valid REPAIR options. If you are using SQL Server 2005 For more information about how to start SQL Server in single-user mode, visit the following Microsoft Developer Network (MSDN) Web site: http://msdn2.microsoft.com/en-us/library/ms188236(en-US,SQL.90).aspx Back to the top MORE INFORMATION If you start SQL Server in single user mode (by using -m) and then you run a DBCC CHECK statement (CHECKDB or CHECKTABLE) with one of the valid REPAIR options, SQL Server generates this error message: Repair statement not processed. Database needs to be in single user mode. DBCC execution completed. If DBCC printed error messages, contact your system administrator. The preceding error message corresponds to error number 7919. The following example illustrates the problem: 1. Start SQL Server from a command prompt by using: sqlservr -c -m 2. Make a connection to SQL Server by using the Query Analyzer and then run the following code: Use pubs go DBCC CHECKTABLE(Authors, REPAIR_REBUILD ) go These steps cause the error listed at the beginning of the "More Information" section to occur. This behavior is by design. When you start SQL Server in single user mode, you do not explicitly set the status of each database in single user mode. You only do that for the Master database. However, the DBCC CHECK statement checks the status for that specific database on which it is being run and if it is not set to single user the error message occurs. Q. How do you set a single database to single user mode? A. To set a single database in a SQL Server 2000 database into single user mode: 1. Connect to SQL Server using SQL Query Analyzer (or osql or similar). 2. Issue the command: alter database db-name set SINGLE_USER where "db-name" is the name of the database to place in single user mode. Note: This cannot be used to place the databases MASTER, MSDB or TEMPDB in single user mode. For these you will need to start SQL Server 2000 in Single User Mode.

To set a database back into normal multi-user mode use, issue the command: alter database db-name set MULTI_USER

Q. Run DBCC CHECKDB on each database using cursors? A. The simplest way to run 'dbcc checkdb' (to check the structural integrity of an SQL Server database) on each database in the system is to write a simple script that includes each database by name, for example: dbcc checkdb('MASTER') with no_infomsgs dbcc checkdb('MODEL') with no_infomsgs . . dbcc checkdb('TEMP') with no_infomsgs The disadvantage of this approach is that the script needs to be updated each time a new database is added or a database deleted. It is also unlikely to be portable from one server to another without being rewritten. An alternate and more adaptable approach is to let the script determine what databases are present and to run dbcc checkdb on each in turn: declare database_cursor CURSOR for select name from master..sysdatabases declare @database_name sysname open database_cursor fetch next from database_cursor into @database_name while @@FETCH_STATUS=0 begin print @database_name dbcc checkdb(@database_name) with no_infomsgs fetch next from database_cursor into @database_name end close database_cursor deallocate database_cursor The advantage of this approach is that the script does not need updating should a new database be added or one removed and it can be copied from one server to another and executed without change. Restoring Master Database Restore SQL Server 2000 MASTER Database The MASTER database can only be restored when the database is in single-user mode. To place it in single user mode: 1. Start a command session. 2. To ensure that SQL Server is not running type: net stop MSSQLServer This may say that this will also stop another service, in which case allow it to continue. It will also indicate if the service is already stopped.

3. To start SQL Server in single user mode type: sqlservr -m If this is not recognised then cd to 'C:\Program Files\Microsoft SQL Server\MSSQL\BINN' and try again. To restore the MASTER database from the backup use the following script (run in SQL Server Query Analyzer): use MASTER go Restore Database MASTER From Tape='\\.\Tape0' With File=3, NOUNLOAD go Note: While SQL Server is in single user mode you should still be able to connect from SQL Server Query Analyzer if you connect using the "sa" account. The above assumes that the file number is 3 for the MASTER database. If unsure on the file number then the list of file numbers can be found by issuing the command: Restore HeaderOnly from Tape='\\.\Tape0' with nounload the two fields to look at in the result set are the 'BackupName' and 'Position' which is the file number to be used in the above. Once the MASTER database has been restored (the restore will have caused the database to be shutdown) start the database by issuing the following command at the command line: net start MSSQLServer Remember that the password for the 'sa' account will now be what it was at the time of the original backup. Restore Other SQL Server 2000 MODEL, MSDB and other databases Each of the databases can now be restored: 1. Start SQL Server Query Analyzer (Start > Programs > Microsoft SQL Server > Query Analyzer) 2. Enter and run the following script: use MASTER go Restore Database MODEL from Tape='\\.\Tape0' with File=4, NOUNLOAD Restore Database MSDB from Tape='\\.\Tape0' with File=5 Restore Database MYDB from Tape='\\.\Tape0' with File=N1 Restore Database YOURDB from Tape='\\.\Tape0' with File=N2 Restore Database ANODB from Tape='\\.\Tape0' with File=N3 go Note: Be sure to check that the file numbers are the correct for your system. (To determine the file numbers see the notes on restoring the MASTER database above.) You must restore the MODEL and MSDB databases.

In the above replace the ficticious database names ('MYDB', 'YOURDB' and 'ANODB') with the real database names for the system. Also, be sure to check that the file numbers are the correct for your system. The 'nounload' only needs to be specified once. I would recommend completing the restore process by rebooting the server, this will ensure that any other processes which rely on the database should start normally. These notes have been tested against SQL Server 2000 running under Windows 2000. These notes are provided as is, to assist with the development of backup and restore scripts and procedures. Be sure to test the backup and restore of any system. No guarantee stated or implied.

Move a database file This procedure can be used for any database except 'tempdb' or 'master': To move one or more database files for a given database: 1. Consider backing up the database before you start, in case anything goes wrong. 2. Get a list of all the filenames for files currently used in the database. Do this using: Use MyDatabase Go Exec sp_helpfile This step is essential - you can only successfully reattach the database by specifying each and every file. 3. Detach the database. This prevents others from using it while the files are being moved. Do this using: Exec sp_detach_db 'MyDatabase' You will not be able to detach a database whilst it is in use. 4. Move the database files to their new location, or rename them, as appropriate to your needs. 5. Reattach the database, explicitly specifying the full pathname of every file that constitutes the database. This includes any files that were not moved or renamed. For example: Exec sp_attach_db 'MyDatabase', 'E:\MsSql7\NewHome\MyDatabase_Data.mdf', 'E:\MsSql7\NewHome\MyDatabase_Log.ldf' Notes: 'sp_attach_db' can only be used with up to 16 files. If the database has more than 16 files then instead use 'Create Database' with the 'For Attach' clause. If the detached database was enabled for replication and is attached to a DIFFERENT server then 'sp_removedbreplication' should be run to remove replication from the database. Only members of the 'sysadmin' server role can execute 'sp_detach_db' and 'sp_attach_db'. Move master database files

Procedure to move the master database: 1. Take a full backup that you are confident you can recover from, incase anything goes wrong. 2. Stop MS Sql Server. 3. Move the files that constitute the master database to their new location and/or rename them, as appropriate. 4. Change the start-up parameters for SQL Server to reflect the change. 5. The easiest way to do this is to edit the parameters in the registry, under: HKEY_LOCAL_MACHINE \SOFTWARE \Microsoft \MSSQLServer \MSSQLServer \Parameters Typical parameters are: SQLArg0 -dc:\MSSQL7\data\master.mdf SQLArg1 -ec:\MSSQL7\log\ERRORLOG SQLArg2 -lc:\MSSQL7\data\masterlog.ldf 6. Restart MS Sql Server. 7. Whilst it should be unnecessary, for confidence you may wish to check the database: dbcc checkdb (master) with no_infomsgs Move temporary database files To move a file that constitutes part of the temporary database use: Alter database tempdb modify file (name=<logical-name>, filename='<full-pathname>') For example: Alter database tempdb modify file (name=templog, filename='e:\mssql\data\templog.ldf') This change will take affect when the MS SQL Server is next restarted. To get the name of the current database: select db_name(dbid) from master..sysprocesses where spid=@@SPID alternately: sp_who @@SPID will give the name of the current database and other information about the current user

Determine the name of the user for the current session SQL Server provides a number of ways of getting information about the current user: o sp_who @@SPID will give the user name and other session information about the current user session. o The database variable 'SYSTEM_USER' returns the domain and login name of the user IF windows authentication is used. However if current user is logged on using SQL Server Authentication then 'SYSTEM_USER' returns the SQL Server login identification name. For example: print SYSTEM_USER might yield 'PRO_BRAIN\Brian Cryer', if the user 'Brian Cryer' were logged on using NT authentication from a workstation called 'PRO_BRAIN' (note 'XP' allows spaces in the user name whilst NT does not) or 'sa' if connected using the 'sa' account using SQL Server Authentication. o The database variable 'CURRENT_USER' (or 'SESSION_USER' - the two always give the same value) returns the database authorization name of the user that made the connection. o Other information can be found by interrogating the table 'master..sysprocesses' directly, for example: select nt_username, hostname, nt_domain, loginame, login_time, program_name from master..sysprocesses where spid=@@SPID To obtain the version number using SQL: select @@version List all currently connected users The simplest way to list all users and processes is to use the system stored procedure: sp_who to list all active users: sp_who 'active' to list details about a particular user: sp_who 'login-name' the same information (and more) can be found by interrogating the system table master..sysprocesses, for example the following is equivalent to 'sp_who': select spid, status, loginame, hostname, blocked, db_name(dbid), cmd from master..sysprocesses but the table master..sysprocesses also provides additional information such as the login_time, program_name and others. For full details of the master..sysprocesses table refer to SQL Server Books Online.

http://www.jobsdb.com.sg/SG/EN/job.asp?R=JDBS125035601

Takeaway: If the master database fails, Microsoft SQL Server can be brought to its knees. See how to recognize this event and learn the steps for recovering the master database using the Enterprise Manager and the Query Analyzer. As a Microsoft SQL Server administrator, you must know how to recover a corrupt master database. The master database stores your logins and, most importantly, the pointers to all of your databases. Without the master database, you can't successfully start SQL Server. I'm going to walk you through the process of recovering the master database in the event of corruption and show you how to rebuild the master database, if necessary. Have a plan It is important to have a plan for dealing with the corruption and/or failure of your master database. That will help you follow a methodical approach when disaster strikes, rather than acting too quickly under pressure. I have been in many situations where it would have been easy to panic, but I've managed to weather the storm by remaining calm and following the proper methodology when dealing with a problem. How do you know if your master database is corrupt? Before we discuss how to recover and rebuild your master database in the event of a failure, we need to look at how you can tell if it's corrupt. To demonstrate, I'll break a master database to show you what happens if your master gets corrupted. Let's pretend that your company had a power surge and your SQL Server rebooted. Upon reboot, SQL Server would not start. If you check the error log (Figure A), you'll see that the master database is either corrupt or missing. Now that you know what message to look for, lets see how to recover a master database.

Figure A

Recover your master database Your first step in recovering your master database is to use the Rebuild Wizard (Rebuildm.exe), located in the \Program Files\Microsoft SQL Server\80\Tools\BINN directory. Lets walk through the Rebuild Wizard to see how it works. Start by double-clicking Rebuildm.exe to bring up the screen shown in Figure B.

Figure B

On this screen, you can specify the collation settings of your database server and the location of your data files during your original install. To make the latter easier and faster, copy the x86 directory from the SQL CD to your hard drive and point to the local copy. Once you have verified all of this information, click Rebuild. You'll then be prompted to confirm the operation, as shown in Figure C. Figure C

Click Yes. Once the process is completed, you'll see a message telling you that the rebuild was successful. You now have a brand new master database and are ready to restore your master database.

First, start SQL Server in single-user mode by opening up a command prompt and issuing the command sqlservr.exe c -m from the \Program Files\Microsoft SQL Server\MSSQL\BINN\ directory. The results are shown in Figure D. Figure D

After you start SQL Server in single-user mode, you can restore your master database from a backup. You can restore it using either the Query Analyzer or SQL Enterprise Manager. If you're using Query Analyzer, run the query shown in Figure E. If you're using Enterprise Manager, right-click on the master database, choose All Tasks | Restore Database, and browse to where your device is located, as shown in Figure F. Click OK twice, and you have successfully restored your master database. Figure F

Once you've restored your master database, exit single-user mode and restart SQL Server in normal operation mode. If for some reason your restore operation does not work, you can try an alternative method. Simply rebuild the master database and attach all of your databases that reside in the data directory. You can attach the databases using Enterprise Manager or Query Analyzer. In Enterprise Manager, right-click on Databases and choose Attach Database, as shown in Figure G. In Query Analyzer, the sample script in Listing A shows how to attach your databases. Final word Now that you have learned how to successfully re-create your master database in the event of a disaster, you can add these techniques to your disaster recovery plan. That way, you wont be left scrambling when a corrupt master database in SQL Server brings your database server to a halt.

S-ar putea să vă placă și