


Database principals (users), on the other hand, can be members of database roles and have permissions to database objects.įor a more detailed discussion on the SQL Server security model, read some of my earlier posts on principals, securables, permissions and execution context. Server-level principals (logins) can be members of server roles and have server-level permissions. The login connects to the user with a SID, a security identifier, which is a unique binary string.įor Windows authenticated logins, the SID is created from the Windows user or group, whereas SQL Server authenticated accounts cannot inherit a SID, so a new one is created in SQL Server. Users, thus, are referred to as database principals. Each login can map to any number of users, one for each database. The first one is the login, which is the server-level principal, the one that your clients and apps log on with. There are two types of so-called security principals you need to keep track of. However, some companies can’t or won’t use dbaTools, so I’ll leave this post up for posterity. If you can, I would advise you to use dbaTools to synchronize your stuff instead of this script. See Copy-DbaLogin, and this post on how to use it. One of those allows you to synchronize not only logins, but tons of other things that are not covered in this post. The logic holds true if you have multiple AGs, it just gets trickier.ĮDIT: Since I wrote this post, quite a few years ago, I learned about dbaTools, which is an amazing collection of Powershell commandlets for DBAs. For the sake of simplicity, I’ll assume that you have a primary replica with a single AG and any number of secondary replicas. You could sync these manually (as is often the case), but wouldn’t you just love to have an automated process do all this for you?

Things that are not included in AGs include logins, SQL Server Agent jobs, SSIS packages stored in SQL Server, linked servers and server settings. But there are a few gotchas, the most obvious of them being that Availability Groups only synchronize specific user-databases, not the entire server setup. AlwaysOn Availability Groups are a reasonably simple way to set up disaster recovery (DR) for your SQL Server environment, and with fairly little effort, you can get a bit of high availability (HA) from it as well.
