March 31, 2023 at 12:00 am
Comments posted to this topic are about the item Shrink Database Log Files One by One
:-PManie Verster
Developer
Johannesburg
South Africa
I can do all things through Christ who strengthens me. - Holy Bible
I am a man of fixed and unbending principles, the first of which is to be flexible at all times. - Everett Mckinley Dirkson (Well, I am trying. - Manie Verster)
March 31, 2023 at 2:36 am
I've just started reading your article, Manie. I don't believe you'll find many experts that would crucify anyone for using a cursor for process control. RBAR process of rows? Yeah, fair game but not for things like the subject of your article.
A lot of people will say you could have avoided the cursor by using that bloody sys.sp_MSforeachdb system stored procedure. Apparently, very few of those folks have look at that proc... it's actually a Cursor on steroids! They also don't realize that it's not the Cursor that's going to take the time here.
I do have a question for you, though... why are these database bases in the FULL Recovery Model? It sounds like you may not be taking regularly scheduled full and log file backups. If you are, then we need to make a couple of additions to your script but I don't want to take the time to write those suggestions up if you're not backing up these databases. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
March 31, 2023 at 4:00 am
Hey, we got a similar script in our Madeira toolbox:
March 31, 2023 at 5:58 am
Keep in mind, your LOG file(s) may not shrink at first attempt !!!
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
March 31, 2023 at 6:18 am
Keep in mind, your LOG file(s) may not shrink at first attempt !!!
Even there, they don't mention that you should do a CHECKPOINT first and then wait for the rocks to stop moving. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
March 31, 2023 at 8:04 am
Good article, and it does brign up the question of why a database is in full recovery model with no backups being made to keep the log file contained.
This process would be hard to execute in a Availability Group database as you first need to remove the database from the AG group before altering the recovery model.
And not to try to tear things apart but the use of nvarchar(max) is not a good habit to practice.
Those things aside, thank you for taking the time that you did in your contributions with this article.
----------------------------------------------------
March 31, 2023 at 9:47 am
indeed. Good point.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
March 31, 2023 at 10:42 am
That's what Powershell is for.
Invoke-DBAShrink -SQLInstance Instance -AllUserDatabases -FileType Log
March 31, 2023 at 10:49 am
This was removed by the editor as SPAM
March 31, 2023 at 11:51 am
You're a day early if this is an April Fools day joke.
Unless the DBs need FULL recovery model for something, just change them to SIMPLE. Do you need point-in-time recovery, log shipping, or always or availability groups? If not just change them to simple recovery model.
If they need point in time recovery you need to set up a regularly scheduled transaction log backup.
March 31, 2023 at 12:19 pm
Another approach is to back it up to NUL
CHECKPOINT
BACKUP LOG [databasename] TO DISK = 'NUL'
March 31, 2023 at 12:53 pm
That doesn't shrink the file.
And the logfile of a simple database can also grow large if you try to do everything in one transaction.
March 31, 2023 at 12:56 pm
March 31, 2023 at 12:56 pm
Agree 100%,, I will add that you will need the DBATools cmdlets https://docs.dbatools.io/ . They even have a video on how to install it, you only need to install on your workstation or a dev box that you use to manage your SQL servers.
March 31, 2023 at 12:56 pm
Viewing 15 posts - 1 through 15 (of 26 total)
You must be logged in to reply to this topic. Login to reply