Contained DB? Did it do something wrong? Presented by Warren Sifre
About Professional Me… Senior Microsoft Consultant for Perpetual Technologies Inc. 14+ years in IT Industry 12+ years working with Databases Worked in the Document Imaging market space for over 10 years. Developed system integration solutions against many different database platforms. Architected the virtualization of over 80 physical databases servers onto a 10 physical server solution for a Hosted Managed Services organization. Passion in Solutions Architecture at both hardware and software levels. MCDBA, MCITP (2005/2008) Admin, MCTS 2008 (BI/Dev), MCSA (2003), MCSE (2003), CDIA, CEH (In Progress)
Agenda Review current database move process. Disclose new database move process enabled by contained databases. What is a contained database and why do were they introduced Benefits of contained databases Terms and Definitions Demo enabling an Instance to allow for contained databases. Demo configuring database for Containment. Demo moving and connecting to contained database. Things to keep in mind Useful T-SQL queries Use Cases for Contained Databases Questions
Current Move Database Process… Detach or Backup existing database Attach or Restore database to new instance Create SQL/Windows authenticated accounts Exec SP_Change_Users_Login (‘Auto_Fix’, <AccountNames>) for each user account. Migrate any dependent SQL Agent Jobs.
Contained DB Move Process… Detach or Backup existing database Attach or Restore database to new instance Migrate SQL Agent Jobs
What is Contained Database? A new feature available in SQL 2012. Contained databases are isolated from other databases and from the instance of SQL Server that hosts the databases. Separates the database application from the management of SQL Server.
Benefits of Contained Databases Simplifies the process of moving a database from one instance to another. Sorts taking place in the TempDB will now use the collation of a contained database instead of the instance default collation. Eliminates bad sorts because of collation mismatch. Simplifies the configuration of AlwaysOn Availability Groups, Log Shipping and Database Mirroring by eliminating the needs to syncronize instance logins. No data is left behind when a database is moved from instance to another. (i.e. Logins)
Terms and Definitions… Database Boundary (aka Application Boundary) – The boundary between a database and the instance of SQL Server and other databases. Contained – An element that exists entirely within the database boundary. Uncontained – An element that crosses the database boundary. Non-Contained Database – A database that has containment set to NONE within SQL Server 2012 (default value). All databases in versions earlier than SQL Server 2012 are non-contained. Partially Contained Database – A partially contained database is a contained database that can allow some features to cross the database boundary, but most features stay within the database boundary. Fully Contained Database – No features cross the database boundary.
Enable Instance to allow for Contained DB. DEMO
Demo Recap… Must Enabled instance to recognize Contained Databases exist. Can be enabled via T-SQL Scripts or GUI EXEC SP_CONFIGURE 'contained database authentication',1 Only Supported in SQL 2012.
Configure Database for Containment. DEMO
Demo Recap… Can create a SQL or Windows Authenticated logins Must select partial in the containment type drop down list.
Move and Connect to Contained DB… DEMO
Keep in mind… There may be situations where objects are not contained within the database boundaries… Stored Procedure access a database within the same instance. Process executing a stored procedure within the master database. Normal authentication prerequisites still exist; Instance must be configured for Mixed Mode authentication to be able to login to a contained database as a SQL authenticated login. Cannot use Replication, Change Data capture or Change Tracking
Useful Queries… This query shows what objects are not contained within a particular contained database: SELECT class_desc , OBJECT_NAME(major_id) ‘Object Name’ ,statement_type ,feature_name FROM sys.dm_db_uncontained_entities WHERE statement_type IS NOT NULL This query shows all accounts configured to be contained in a contained database: SELECT name,type_desc,authentication_type_desc FROM sys.database_principals WHERE authentication_type =2
Use Cases for Contained DB… Log Shipping Mirrored Databases AlwaysOn Availability Groups (New SQL 2012)
AlwaysON Availability Groups, huh? Latest SQL Server High Availability offering Uses subset of Database Mirroring and Failover Clustering features to allow multiple readable secondary replicas and groupings of databases for failover, backup and reporting. Only available on SQL Server 2012 Enterprise edition
Availability Group Listener How AlwaysOn Availability Groups work.. Application(1) Application(2) Application(3) Availability Group Listener SQL Node 1 SQL Node 2 SQL Node 3 SQL Node 4
AlwaysOn AG Prerequisites... Windows Server 2008 or greater Windows Failover Cluster Services SQL Server 2012 Enterprise Edition SQL Server Default Collation must be the same on all nodes An available IP Address (Static recommended for Production) Database must be read/write enabled. Database must be in FULL recovery model. Database cannot be configured in a Mirror. Database cannot exist in any existing Availability Groups.
Benefits of Availability Groups Have more than 1 failover option (4 secondary replicas) Off-Load Backups onto the secondary replicas Off-Load integrity checks onto the secondary replicas Off-Load Read Only connections to secondary replicas Support for Multiple Database Failover in one action Automatic Page Recovery if page corruption detected True Geo-Cluster support (Multi Subnet)
Connection String Information… Read/Write use connection string ("server=AO_Sample; database=AlwaysOn_SampleDB; user id=DB_User; password=DB_PW;) __________________________________________________ Read Only use connection string User id=DB_User;password=DB_PW; ApplicationIntent=ReadOnly")
Limitations and Suggestions… Differential Backups are not supported Suggest Drive letters across Cluster Nodes are the same. Additional Prerequisites for Failover Cluster Instances (FCI) Cannot have replicas outside of its current cluster. Failovers are not caused by database issues such as a database becoming suspect due to a loss of a data file, deletion of a database, or corruption of a transaction log Can include a replication publisher, but not the distributor Supports Contained Databases, FileStream and FileTables. Deleting the Availability Group will remove all WSFC configurations performed by SQL and none of the database replicas. Database Restorations are similar to Mirroring.
THANK YOU!!!! Warren Sifre Email: warren.sifre@pti.net Twitter: @WAS_SQL Company Website: www.pti.net