Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

SQL Interview Questions on SQL Server Backup and Restore Part 2

$
0
0

The following is the list of SQL interview questions covering backup and restore, accidental deletes and updates and more.

SQL interview questions 1:Have you ever encounter the issue “media family on device is incorrectly formed”? If yes what is the reason and how you resolved it?

Yes! I have seen the error “The media family on device is incorrectly formed. SQL Server cannot process this media family” many times. There are a few common cases that raise this error: Trying to restore backup from higher version to lower version.

Example:

Backup taken from 2014 and trying to restore to 2008 R2. Trying to restore a backup using SSMS or T-SQL in a native method when the backup is taken using a third-party tool.

Example:Lite-speed

Trying to restore a backup file where the backup copy is still in progress. Backup file might be corrupted.

SQL interview questions 2:We have been using SQL Server 2014 and we need to rebuild the system databases due to a corruption in the master database. Do we need to get the installation DVD or Media to rebuild the system databases?

No! Not required. SQL Server can get these original files from a cache location called “Template” folder. These (System Databases) are cached into this folder at the time of installation.

SQL interview questions 3:Ok, so my instance system databases MDF and LDF files are initially cached to Template folder. My question is if we can directly copy and use these MDF and LDF files from Template location instead of running REBUILD when we see a corruption in master database and we need to rebuild the system databases?

No! We are not supposed to directly copy files from Template location to DATA and LOG folders. If we manually copied these files and tried to restart the SQL Server, it might fail with the errors as it cannot identify the location of MDF and LDF files for other system databases. The reason is that simple Master database is a copy of the initial DB when it got installed. It contains the default path for MSDB and MODEL database file locations. But, in reality, we usually don’t keep system databases on C drive.

If we rebuilt the system databases, setup would move the files from Template location to the proper location and it would modify the path of other databases which are stored in the master database.

SQL interview questions 4:We have an 800GB database. We are taking a full backup on daily basis, which takes 3 to 4 hours. You are asked to propose a solution for speeding up the backup process. What would you suggest?

Full and Differential: We can plan for a weekly full backup and daily differential backup and transactional backup based on SLA for data loss acceptance. Differential backup doesn’t take much time when compared to full backup. Make sure the latest differential backup is in safe place as it requires restoring the database with the minimum data loss.

File/File Group backup: Categorize the tables into “Master,” “Lookup” and “Transactional” and keep these files into different file groups. Perform backup only on the tables where there are daily data changes. This is one way but we should do a lot of research before applying this method. This is really useful when databases are huge.

If a full backup, however, is required on daily basis, then your response to SQL interview questions 4 should be something of the below.

Backup database to Multiple Files: If your business demands a full backup on daily basis then you can choose this method. Split backup into 3 or 4 files on different drives. Let’s say I have a database with 1 TB in size and it is taking 4 hours to perform a full backup. If we split this backup into 4 files on 4 different disks, then the full backup time comes to 1 hr. Logic is we have 4 files writing on 4 different physical drives, each drive has a separate thread and all these threads execute in parallel. Remember we should make sure all these files are available for a successful restore when we do split backup.

Backup during off hours/less traffic: This is one of the best practices in scheduling backup.

Backup to local disk and then archive: Avoid using a network path in the backup and make it be like a three-tier architecture:

Perform backup to local disk Schedule a job to copy/move from local to network Then you can continue with moving to the tape

Backup Compression: This is one technique that is mostly used when there is a space issue. But sometimes compression can reduce backup time when we have a lot of CPU cycles free and enough IO bandwidth.

SQL interview questions 5:You are leading a DBA team and one of your team members came to you and reported that he had executed an UPDATE command without WHERE CLAUSE on a production database. Now that entire table has gotten updated with the wrong data, what would you do?

That’s a really embarrassing situation. I actually faced it earlier in my previous role. The command was provided by release team and one of our DBAs has executed it, but he immediately identified the problem and reported it to us. The solution that worked out:

Made database to single user mode Identified the “Transaction ID” and “Begin Time” by reading log file using sys.fn_dblog() Performed a log backup Created a dummy database on the same instance and restored it with this database’ latest full backup Restored the latest differential backup followed by all transaction log backups except the last one that we have taken Restored the latest transactional backup that we performed in the step 3 with the point in time recovery. The time we gave was just before the transaction begin time that we identified in the step 2, i.e.: Transaction Begin Time: “2016-07-26 15:26:39” then recover data till “2016-07-26 15:26:38” We got our original table in dummy database and applied an update statement by joining the same table from the original database and the dummy database where we had the correct data and did the required changes Made the original database to multi user mode Dropped the dummy database

SQL interview questions 6:For the accidental situations like “DELETE WITHOUT WHERE,” “UPDATE WITHOUT WHERE” or “DROPPING A TABLE” do we have any other option except restoring full/diff/log file?

I don’t think we have a native support tool/method to roll back the committed operations. But there are a few third-party tools which can be really helpful in these situations.

ApexSQL: ApexSQL Log

Redgate: SQL Log Rescue

I hope you have found this set of SQL interview questions helpful. Feel free to post any feedback or ask any questions in the comments below.


Viewing all articles
Browse latest Browse all 3160

Latest Images

Trending Articles