Replace a MS SQL Database in AlwaysOn AG with DBATools

There is a database in AG and you need to drop it and restore from backup (which is sometimes a transition from developer to prod )
You don’t need any prerequisite for cluster nodes and AG names.
The script find the instance in local windows server and find the db AG nodes and listener.
So finally you need the database name and the location of the backup folder which can be an Ola backup solution folder.

SQL AO AG failover in cluster group and check the synchronization status

Get info from Cluster:

Failover general example, you can use Invoke-DbaAgFailover for SQL server:

DBATools makes your life happy, you can find the SQL server instances and you can failover them.

To find  all of the SQL instances in a cluster server . To Check AG before and after the failover, and failover the SQL Server AO AG :


 

if you have to wait a lot for synchronization you can check how many servers are synchronized.


 

 

Find and list read and writeable user databases which are only in local instance or in primary AG group

List database names, which are in AO AG:

Local databases , which are outside of AO AG:

Writeable databases : primary db or only in local instance

 

AOAG Synchron Commit time

Átlagos tranzakció végrehajtási ideje:

SQL szerver válasz ideje ms-ban:

wait_type waiting_tasks_count wait_time_ms time_per_wait
HADR_SYNC_COMMIT 10809645 135666120 12