Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SQL Server 2016 Failover + AlwaysOn add database to availability group

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

SQL Server Failover + AlwaysOn add database to availability group

Previous articles have described the configuration of SQL Server Failover + AlwaysOn in detail. Today we mainly introduce adding databases to availability groups under SQL Server Failover Cluster+AlwaysOn.

We first need to create a database and a table

Database name

HAGroupDB2

Create a tabl

Insert data into a table

We added this database to the high availability group; the currently newly created database is not synchronized

We add databases under the high availability group.

Hint requires us to make a full backup.

So we back up.

We also back up the transaction log

After the backup is completed, we need to restore the backed-up database and log on node 3.

Restore database

When restoring, the restore state must be selected in the option: RESTORE WITH NORECOVERY

Database restore completed

Let's check the restore status.

Then restore the log of things

Restore option-Let's choose the second option-RESOTRE WITH NORECOVERY

Restore completed

After we restore the database and transaction log, the state of the database is not being restored

And then we started to add databases to AG.

We chose Join only.

We link to an existing replica server

Connected successfully

Join successfully

We look at the database information in AG

To view the status of the cluster database, it has also become synchronized

Let's check the panel and everything's fine.

Combining the above operations, we can use powershell to do this.

$DatabaseBackupFile = "\\ share\ backups\ MyDatabase.bak" $LogBackupFile = "\\ share\ backups\ MyDatabase.trn" $MyAgPrimaryPath = "SQLSERVER:\ SQL\ PrimaryServer\ InstanceName\ AvailabilityGroups\ MyAg" $MyAgSecondaryPath = "SQLSERVER:\ SQL\ SecondaryServer\ InstanceName\ AvailabilityGroups\ MyAg" Backup-SqlDatabase-Database "MyDatabase"-BackupFile $DatabaseBackupFile-ServerInstance "PrimaryServer\ InstanceName" Backup-SqlDatabase-Database "MyDatabase"-BackupFile $LogBackupFile-ServerInstance "ServerInstance"-PrimaryServer 'PrimaryServer-InstanceName "- InstanceName $InstanceName -ServerInstance "SecondaryServer\ InstanceName"-NoRecovery Restore-SqlDatabase-Database "MyDatabase"-BackupFile $LogBackupFile-ServerInstance "SecondaryServer\ InstanceName"-RestoreAction 'Log'-NoRecovery Add-SqlAvailabilityDatabase-Path $MyAgPrimaryPath-Database "MyDatabase" Add-SqlAvailabilityDatabase-Path $MyAgSecondaryPath-Database "MyDatabase"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report