Shrink a database log file which is synchronized (Always on Group)

Sai 126 Reputation points
2021-11-18T15:03:30.753+00:00

How to shrink a database log file which is synchronized(Always on Group).
SQL version: SQL server 2017 Enterprise edition

I have seen huge growth in log file(mdf- 500GB and ldf - 800GB).
Preforming transactional log backup every 30 mins and full backup every day night.
But didn't see any improvement from 1 week.

Please suggest.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,814 questions
0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Sai 126 Reputation points
    2021-11-21T07:15:37.53+00:00

    I checked with developers, They create and delete lots of tables weekly. They were asking us to delete logs during the maintenance.

    Can I ask them, Delete large number of rows and tables without growing the transaction log?

    Will it help instead of planning to shrink database log file regularly?

    This database is in always on group and with Full recovery model.

    0 comments No comments

  2. Ronen Ariely 15,096 Reputation points
    2021-11-21T11:18:07.147+00:00

    Delete large number of rows and tables without growing the transaction log?

    DELETE rows is a transactional action which log all the information, but <As Erland mentioned> DROP table is mainly a metadata action which logs only a few rows in the transaction log. Moreover, It does not really delete any data from the data file as well (the data place is re-useable but at the DROP point in time it is still on the disk).

    Another action which you can take if you want to delete all the rows is TRUNCATE TABLE, which also is a metadata action.

    It should be faster to TRUNCATE 1000000000000 rows than to DELETE 100000 usually, and log file will not need to grow.

    Note! focus on Erland explanation and don't be harry to take the first idea that come to your mind if you have issue. Transaction log is big => many jump to confusion or fast wrong recommendation to make it smaller instead of thinking about the impact of such action.

    Even when someone ask "how to shrink" the answer is usually NOT the explanation on how to shrink but on how to avoid the need to shrink!

    It is what call XY problem. You ask about X while the source of the issue is y, and you should have solve y and not X.
    https://en.wikipedia.org/wiki/XY_problem

    In general, if you came to a situation that you need to shrink your files regularly, then you need to take 2 step back and think about your system design.