How is tempdb
utilized as Failover occurs?
Let's say there are two servers, server 1 is primary and server 2 is secondary. Suddenly, Failover happens, so, how does tempdb
behave during this situation?
Tempdb doesn't move when an AG failover occurs. Each replica is its own standalone instance. Each has its own tempdb. Queries will break during the failover. Once the application reconnects after the failover is complete and crash recovery is also complete, the queries can then run on the other instance where it has its own tempdb.
A Failover Cluster Instance fails over at the instance level, so tempdb is affected. But not for Availability Groups.
There is a caveat here... if the local disk with the tempdb fails, SQL will not initiate a failover.
My colleague Twan and I have written an article detailing that on https://www.sqlservercentral.com/articles/do-not-place-tempdb-on-a-local-disk-in-a-sql-failover-cluster
TLDR: you need to check in SQL for the loss of the local disk, and initiate the failover yourself.