elearning Event ESSENTIAL SKILLS FOR SQL SERVER DBAS Session 2
Session 2 Session 1 DBAS: What, Why, and How. Primary Focus of DBAs: Availability and Security Basic SQL Server Engine and Security. Session 2: Database and File Management. Disaster Recovery
Sizing SQL Server Databases Disk is Cheap. (orly? hadn t noticed) Humans are wired for Scarcity. Best Practices: Grow Large (or grow fragmented) Don t try to scrimp on file space/utilization Rule of thumb: Log files 25% of database file size Make Sure you have enough space to grow or everything STOPs Log Files are also subject to fragmentation.
Sizing SQL Server Databases Disk is Cheap. (orly? hadn t noticed) Humans are wired for Scarcity. Best Practices: Grow Large (or grow fragmented) Don t try to scrimp on file space/utilization Rule of thumb: Log files 25% of database file size Make Sure you have enough space to grow or everything STOPs Log Files are also subject to fragmentation.
Sizing SQL Server Databases Disk is Cheap. (orly? hadn t noticed) Humans are wired for Scarcity. Best Practices: Grow Large (or grow fragmented) Don t try to scrimp on file space/utilization Rule of thumb: Log files 25% of database file size Make Sure you have enough space to grow or everything STOPs Log Files are also subject to fragmentation.
Shrinking Databases Performance Overhead Very Expensive for IO subsystem. Causes significant logging and fragmentation. When to Shrink Databases After Major Changes and Removal of Lots of Data. Multi-tenant system or really busy DB where space is a premium. Shrinking is ALWAYS a trade-off (overhead vs recovered disk) Worst Practices Regularly Shrinking your Databases Auto-Shrink Auto Close
Checking On Servers Mini Demo
Disaster Recovery
Logging Basics Transactions Bank Transfer Example:
Logging Basics Transactions Bank Transfer Example: $1000 Savings Process: Remove $1,000 From Savings Add $1,000 To Checking $3,000 $0 Checking
Logging Basics Transactions Bank Transfer Example: $1000 Savings $2,000 Process: Remove $1,000 From Savings <SERVER CRASH> Add $1,000 To Checking Checking $0 Woops!
Logging Basics Transactions Bank Transfer Example. Safe / Transactionally Sound Example:
Logging Basics Transactions Bank Transfer Example. Safe / Transactionally Sound Example: Log Entry Savings Before: $3,000 Checking Before: $0 Savings After: $2,000 Checking After: $1,000 Savings Process: start transaction Remove $1,000 From Savings Add $1,000 To Checking $3,000 $0 end transaction Checking
Logging Basics Transactions Bank Transfer Example. Safe / Transactionally Sound Example: Log Entry Savings Before: $3,000 Checking Before: $0 Savings After: $2,000 Checking After: $1,000 Savings $2,000 Process: start transaction Remove $1,000 From Savings <SERVER CRASH> Add $1,000 To Checking end transaction Checking $0
Logging Basics Transactions Bank Transfer Example. Safe / Transactionally Sound Example: Log Entry Savings Before: $3,000 Checking Before: $0 Savings After: $2,000 Checking After: $1,000 Savings Process: start transaction Remove $1,000 From Savings Add $1,000 To Checking $3,000 $0 end transaction Checking
Logging Basics Transactions / Transaction Logs Purpose: Ensure Data Accuracy. What they Record: Before/After values logged to log file. Recovery Process can use log file entries to ensure data validity. ACID (Atomicity, Consistency, Isolation, Durability) Logging Helps allow SQL Server to do EVERYTHING in memory. Memory is exponentially faster than disk. Data not in Memory is ALWAYS loaded from disk to Memory. Data is moved to/from disk/memory in 8KB Pages. SQL Server tries to keep data in memory as much as possible. Pages with modified data/rows/content = Dirty Pages. Benefits Transactional Safety/Accuracy AND Performance
SQL Server Log Files
Recovery Options Recovery Options: Full Transaction log details kept until log file backup. Simple Transaction log details purged at checkpoint Only useful when you DO NOT care about change-bychange recovery/rollbacks. Bulk-logged Behaves just like FULL recovery. More compact logging information. (Slightly less protection in the case of disaster in exchange for decreased disk use.)
RESTORE versus RECOVERY RESTORE MEDIA or data in your.mdf/.ndf Data Files RECOVERY TRANSACTIONS or operations you want to replay against data in your files. DISASTER RECOVERY ORDER OF OPERATIONS First: Restore your MEDIA get data into position/shape. Second: REPLAY transactions from the Log File to RECOVER to the point in time needed.
Backup Types and Coverage Two Primary Backup Types MEDIA (data) Backups: Full Backups Differential Backups (Data) File Backups (NONE OF THESE BACKUP TRANSACTION LOGS) TRANSACTION LOG Backups ONLY backs up Transaction Logs
How To: Backup, Restore, and Recover Backups Can be done via Script, or via GUI (SSMS). Restore/Recovery Can be done via Script or via GUI. Confidence Not the same as Comfort or Familiarity. You HAVE to get hands-on-practice with these techniques. Period.
Other Considerations (OR: stuff we don t have time for that s still important) Database Corruption 99.99%+ attributable to IO subsystem SQL Server is able to easily detect corruption. See Books Online for DBCC CHECKDB() Formalizing Disaster Recovery Solutions Documentation of DR proceedings Communication of DR concerns/goals to management: RTOs (Recovery Time Objectives) RPOs (Recovery Point Objectives)
The Role of Redundancy Storage of Backups Local. Faster recovery times (no network overhead). Off-box. Creates redundancy. Redundancy is Critical to Avoiding Disaster High Availability (HA) Solutions: Clustering Mirroring Log Shipping SQL Server Denali s Always On (Denali = next version of SQL Server. (SQL Server 2011?))
HA Best Practices Test Regularly Documentation Failover procedures Escalation details Failback considerations (what to do after disaster has been addressed). Environment HA / DR is more than just data. Make sure you account for security/environment
Conclusion Additional Resources and help listed on my blog: http://updates.sqlservervideos.com/ Confidence and Disaster Recovery Comfort and Familiarity aren t the same as Confidence There s no Substitute for Hands-on Practice Regular Testing: Builds your Skill-Level and Confidence Ensures that your solution isn t silently failing