If the secondary is up and running, when the log block is flushed to disk (either because it is full or a commit), the record gets pushed to the log writer on the primary and to the log scanner (log reader) process on the primary simultaneously. Then the log scanner communicates with the secondary and the secondary then pulls the transaction from the log scanner on the primary to the secondary and processes the log record. The primary log writer doesn't push transactions across, it just communicates with the secondary, it only does that to see if it is up so that it knows it doesn't have to mark the replica as NOT SYNCRONIZED.
When the secondary is not up, then the log writer cant communicate with the secondary so it marks it as NOT SYNCHRONIZED and stores the records in the tran log on the primary. If you look at sys.databases.log_reuse_wait_desc column it should show AVAILABILITY_REPLICA which means the primary is hanging on to all the records.
Once the secondary is up, it will communicate with the primary to request a log scan, it then processes the transactions and communicates with the primary using progress messages to indicate the hardened LSN, presumably the primary is then adjusting its MinLSN, which in turn means the records prior to MinLSN will get deleted as checkpoints happen and hence VLFs will get truncated releasing space when you do a log backup.
But yes short answer is, if your secondary is down you need as big a log file as you need for as long as it is down. Once it is backup and synched at some time you may need to remove the db from the always on group to shrink the log if it is humungous and you dont want it that big.
First step is to change the recovery mode to FULL.
Take a full backup (with compression), and restore the full backup to new server with NORECOVERY
. This will allow you to restore additional log backups.
Now configure logshipping from the primary (old) to secondary (new) server.
During the time of cutover, take a tail log backup and bring the secondary server online by restoring the log backup WITH RECOVERY
.
make sure you have instant file initialization enabled on both servers to cut down the restore times.
Refer to my answer for Moving Databases to New Datacenters for more detailed steps.
Best Answer
I found the solution. It is because my account doesn't have sufficient permission.