SQL Server Failover +alwayson Add database to availability Group
The configuration of SQL Server Failover +alwayson has been described in detail in the previous articles, and today we mainly introduce the addition of 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 table
To insert data into a table
We add this database to the High Availability Group; The currently created database is not synchronized
We'll increase the database under the High Availability Group
Tip We need a full backup.
So we back up
We also back up the transaction log
After the backup is complete, we need to restore the backed up database and things Log on node 3
Restoring a Database
Restore status must be selected in the option when restoring: Restore with NORECOVERY
Database Restore Complete
We view the Restore status
Restore the Thing log again
Restore Options---We choose the second option---resotre with NORECOVERY
Restore complete
After we restore the database and transaction log, the state of the database is not being restored
And then we started adding databases to the AG.
We choose Join only
We link a replica server that already exists
Connection Successful
Join success
We look at the database information in AG
View the status of the cluster database and also become a synchronized
We look at the panel, everything works.
Combined with the above, we can use PowerShell to complete
$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" primaryserver\instancename "-backupaction ' Log ' restore-sqldatabase- Database "MyDatabase"-backupfile $DatabaseBackupFile-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"
SQL Server Failover +alwayson Add a database to an availability group