Successfully reported this slideshow.

SQL Server - High availability

1,341 views

Published on

How to ensure your SQL box is available 99.999 % of the time

Published in: Education
  • Be the first to comment

SQL Server - High availability

  1. 1. SQL Server 2008 for Developers<br />UTS Short Course<br />
  2. 2. Peter Gfader<br />Specializes in <br />C# and .NET (Java not anymore)<br />TestingAutomated tests<br />Agile, ScrumCertified Scrum Trainer<br />Technology aficionado <br />Silverlight<br />ASP.NET<br />Windows Forms<br />
  3. 3. Course Website<br />http://sharepoint.ssw.com.au/Training/UTSSQL/Pages/<br />Course Timetable<br />Course Materials<br />
  4. 4. Course Overview<br />
  5. 5. What we did last week<br />Basic T-SQL syntax<br />New Data Types<br />Inline variable assignment<br />Table Value Parameters<br />DDL (Data Definition Language) Triggers<br />CTE (Common Table Expressions)<br />TOP % WITH TIES<br />XML Queries<br />PIVOT/UNPIVOT<br />
  6. 6. Homework?<br />
  7. 7. CREATE DATABASE SSW_Training<br />GO<br />USE SSW_Training<br />GO<br />CREATE LOGIN LOG_USER WITH PASSWORD=N'LOG_u$er_01', DEFAULT_DATABASE=SSW_Training<br />GO<br />CREATE USER LOG_USER FOR LOGIN LOG_USER<br />GO<br />EXEC sp_addrolememberN'db_datareader', N'LOG_USER'<br />GO<br />EXEC sp_addrolememberN'db_datawriter', N'LOG_USER'<br />GO<br />
  8. 8. CREATE TABLE [ServerLogins](<br /> ID bigint IDENTITY(1,1) NOT NULL<br /> , [DateTime] datetime<br /> , PostTimenvarchar(100)<br /> , LoginNamenvarchar(100)<br /> , EventTypenvarchar(100)<br /> , ClientHostnvarchar(100)<br /> , [EVENTDATA] xml<br />) ON [PRIMARY]<br />GO<br />
  9. 9. CREATE TRIGGER logon_trigger_login_log<br />ON ALL SERVER WITH EXECUTE AS 'LOG_USER'<br />FOR LOGON<br />AS<br /> DECLARE @data xml<br /> SET @data = EventData()<br /> INSERT INTO SSW_Training.dbo.ServerLogins([DateTime], PostTime, LoginName, EventType, ClientHost, [EventData])<br /> VALUES<br /> (<br /> GETDATE()<br /> , CONVERT(nvarchar(100), @data.query('data(//PostTime)'))<br /> , CONVERT(nvarchar(100), @data.query('data(//LoginName)'))<br /> , CONVERT(nvarchar(100), @data.query('data(//EventType)'))<br /> , CONVERT(nvarchar(2000), @data.query('data(//ClientHost)'))<br /> , EVENTDATA()<br /> )<br />GO<br />
  10. 10. SELECTgeometry::STGeomFromText('LINESTRING (0 0, 0 2, 1 3, 2 2, 2 0, 0 2, 2 2, 0 0, 2 0)', 0) Envelope;<br />Homework?<br />
  11. 11. Session 3<br />SQL 2008 High Availability Features<br />
  12. 12. Agenda<br />Agenda<br />What is High Availability?<br />What can go wrong?<br />What can we do about it?<br />
  13. 13. What is high availability?<br />Different people have different definitions<br />Perceived uptime<br />Performance<br />What can go wrong?<br />How can we improve it?<br />
  14. 14. What is high availability?<br />Different people have different definitions<br />Perceived uptime<br />Performance Issues<br />What can go wrong?<br />How can we improve it?<br />
  15. 15. What can go wrong? (continued)<br />Hardware <br />Disk failure<br />Network failure<br />Power Outages<br />
  16. 16. What can go wrong?<br />Software<br />Virus (and Virus Scanners) – File locking issues<br />Disk space<br />Corrupted files<br />Bad upgrades<br />OS Upgrades<br />SQL <br />poor tuning or design<br />DB Maintenance<br />
  17. 17. What else can go wrong?<br />People (PEBKAC)<br />Administrators <br />Users<br />Bottlenecks & Concurrency<br />Acts of God<br />Lightning<br />Cleaners<br />
  18. 18.
  19. 19. What can we do about it? (continued 3-1)<br /><ul><li>1. Hardware Solutions</li></ul>UPS & Hardware Monitors<br />RAID / Mirroring<br />Off site server<br />Firewall<br />Physical Security<br />
  20. 20. What can we do about it? (continued 3-2)<br /><ul><li>2. Software Solutions</li></ul>Database Mirroring<br />Log shipping<br />Auto backup transaction log, and restore<br />Replication (Can also reduce availability)<br />Monitor, Change<br />Database Snapshots<br />Alerts<br />OS: Disk Space, ...<br />DB: Logs,...<br />Partitioned Tables<br />Firewalls<br />
  21. 21. What can we do about it? (3-3)<br /><ul><li>3. OS Level / Backup Solutions</li></ul>Security<br />Change Management<br />Performance Monitoring/Tuning<br />Hot/Warm/Cold standby servers<br />Standard daily backups<br />Verified procedure<br />Transaction logs<br />
  22. 22. What Will We Cover?<br />Implementing Database Snapshots<br />Configuring a Database Mirror<br />Partitioned Tables<br />SQL Agent Proxies<br />Performing Online Index Operations<br />Mirrored Backups<br />
  23. 23. Database Snapshots<br />
  24. 24. Database Snapshots<br />
  25. 25. Point-in-time reporting<br />Mirroring for reporting<br />Recover from administrative error<br />Protection from application or user error<br />
  26. 26. Database Snapshots<br />Snapshots are NOT a substitute for your backup and recovery setup<br />You cannot roll forward<br />If either the database or the database snapshot is corrupted, reverting from a snapshot is unlikely to correct the problem<br />Query from snapshot  current database<br />
  27. 27. Database Snapshots<br />CREATE DATABASE AdventureWorks_dbss1800 ON( NAME = AdventureWorks2008_Data, FILENAME = 'C:dataAdventureWorks_data_1800.ss' )AS SNAPSHOT OF AdventureWorks;GO<br />
  28. 28. Database Snapshots<br />
  29. 29. Snapshot vs. Backup vs. Detach<br /><ul><li>Snapshot
  30. 30. Only go back
  31. 31. SELECT statements
  32. 32. Backup
  33. 33. Rollback and Forward possible
  34. 34. Smaller
  35. 35. Detach database and copy
  36. 36. DB goes offline
  37. 37. Closes all connections</li></li></ul><li>Database mirror<br />
  38. 38. Configuring a Database Mirror<br />No special hardware<br />
  39. 39. Easy to setup<br />Transparent client redirect<br />Zero committed work lost<br />Maximum one mirror per DB<br />Configuring a Database Mirror<br />
  40. 40. Configuring a Database Mirror<br />Virtually no distance limitations<br />No special hardware<br />
  41. 41. Configuring a Database Mirror<br />Clients<br />Principal Server<br />Witness Server<br />Mirror Server<br />
  42. 42. Configuring a Database Mirror<br />Clients<br />Mirror Server<br />Witness Server<br />Principal Server<br />
  43. 43. Configuring a Database Mirror<br />Clients<br />Mirror Server<br />Witness Server<br />Principal Server<br />
  44. 44. Before you mirror your database<br />Principal<br /> Take a full backup and a log backup as well<br />Copy the full/log backups from Principal Instance to Mirror instance<br />Mirror<br />Restore with NORECOVERY option the full backup<br />Apply the log backup<br />
  45. 45. Using the Mirror Wizard<br />
  46. 46.
  47. 47.
  48. 48.
  49. 49. Configure End Point on the Principal<br />
  50. 50. Configure End Point on the Mirror<br />
  51. 51. Set the service accounts<br />Use NT AUTHORITYNETWORK SERVICE<br />
  52. 52.
  53. 53. Mirror is configured<br />
  54. 54. Warning about FQDN<br />
  55. 55. Mirror Operating Modes<br />High Performance (asynchronous)<br />Commits are done on the principal and transferred to the mirror<br />High Safety (synchronous)<br />Commits are written to both databases<br />
  56. 56.
  57. 57. Database Mirroring Failover<br />What happens when something bad happens to our principal server…<br />You can make it failover to the mirror<br />This means that the two servers swap roles for the time being<br />
  58. 58.
  59. 59. Database Mirroring Monitor<br />Lets you view the status and history of your current mirrors<br />
  60. 60.
  61. 61.
  62. 62. Thresholds<br />
  63. 63.
  64. 64. Might come in handy<br />Disable MirroringALTER DATABASE myDatabase SET PARTNER OFF<br />Put DB from "Recovering..." into available online modeRESTORE DATABASE myDatabase WITH RECOVERY<br />
  65. 65. Partitioned tables<br />
  66. 66. Partitioned Tables<br />
  67. 67. Partitioned Tables<br />Allows for maximum concurrency<br />Partitioned Table parallelism<br />Improved a lot in SQL 2008<br />Archive older data into different filegroups<br />
  68. 68. SQL Server agent<br />
  69. 69. SQL Server Agent (recap)<br />Windows Service<br />Executes SQL Server jobs<br />Administrative tasks<br />
  70. 70. SQL Agent Proxies<br />New credential system <br />Sits on Active Directory<br />Fine grained control of your jobs<br />Jobs can be run by proxies instead of user loginsPreviously to run cmd shell type functionality you needed a user in the administrator group which opened up security problems<br />
  71. 71. Online Index Operations<br />
  72. 72. Online Index Operations<br />- Table is accessible for read and update<br /><ul><li> Non-clustered indexes are available during</li></ul> clustered index creation<br />Index Created<br />Table<br />
  73. 73. Concurrent Users<br />Target (Clustered Index)<br />Locking<br />Source (Table)<br />Online Clustered Index Operation<br />CREATE CLUSTERED INDEX index_name ON table_name … WITH (ONLINE = ON)<br />
  74. 74. CREATE NONCLUSTERED INDEX IX_TextTable_MyKey<br /> ON [TestTable] ([MyKey])<br /> WITH (ONLINE = ON);<br />GO<br />
  75. 75. Mirrored Backups<br />
  76. 76. Mirrored Backup media<br />Backup<br />Mirror 2<br />
  77. 77. Mirrored Backup media<br />Mirror 1<br />Mirror 2<br />
  78. 78. Mirrored Backup media<br />Mirror 1<br />Mirror 2<br />
  79. 79. Session Summary<br />Implementing Database Snapshots<br />Configuring a Database Mirror<br />Partitioned Tables<br />SQL Agent Proxies<br />Performing Online Index Operations<br />Mirrored Backups<br />
  80. 80. Session 3 Lab <br />High Availability Features<br />Database snapshots<br />Mirrored backups<br />Online Index Operations<br />Download from Course Materials Site (to copy/paste scripts) or type manually:<br />http://tinyurl.com/utssql2009<br />
  81. 81. Where Else Can I Get Help?<br /><ul><li>Free chats and webcasts
  82. 82. List of newsgroups
  83. 83. Microsoft community sites
  84. 84. Community events and columns
  85. 85. SQL Server user groups (www.sqlserver.org.au)
  86. 86. www.microsoft.com/technet/community</li></li></ul><li>3things…<br />PeterGfader@ssw.com.au<br />http://peitor.blogspot.com<br />twitter.com/peitor<br />
  87. 87. what's next?<br />
  88. 88. Thank You!<br />Gateway Court Suite 10 81 - 91 Military Road Neutral Bay, Sydney NSW 2089 AUSTRALIA <br />ABN: 21 069 371 900 <br />Phone: + 61 2 9953 3000 Fax: + 61 2 9953 3105 <br />info@ssw.com.auwww.ssw.com.au <br />

×