Are you facing SQL Server Error 5009?
This guide will help you.
Recently, one of our customers tried to add a log file to a database and then extend the size of it to a specific value.
He came across SQL Server error 5009 while creating the log file and got the same again while extending the size of this file.
SQL Server Error 5009 error indicates that you specified a file name or fileID in ALTER DATABASE or DBCC SHRINK* command that could not be resolved.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to resolve SQL related errors.
In this context, we shall look into how to fix Microsoft SQL Server Error 5009.
1. Microsoft SQL Server Error 5009 While Adding Database File
During a recent migration, we had to load huge data in a SQL Server database on the target server.
To optimize data load performance, we created a database with the final size on the destination server. Post import the final size of the database was around 800 GB.
In order to reduce the time we made some configuration changes. Extending database file size was one way to reduce data load time.
We decided to add another log file on a separate drive considering extensive log growth during data load.
However, while doing this, the error was triggered.
If there is not enough permission to create the file in the given location, it can cause this error.
In order to solve this, we suggest doing the following:
a. Set the Operating system permission on the .ldf file to full permission for the login account and SQL Server service account.
b. Change the location to the path where we have enough permission to create or add database files.
2. Microsoft SQL Server Error 5009 While Extending the Size of Log File
On the other hand, when we extend the size of the log file we may come across the error.
One of our customers assigned a bigger value to each data and log file. It was a success because Instant File Initialization (IFI) was already enabled to skip the zeros process on storage.
However, the error occurs again while we increase the size of log files. IFI does not work for transaction log files. So, extending the size of log files will take a lot of time:
Msg 5009, Level 16, State 9, Line 1
One or more files listed in the statement could not be found or could not be initialized.
To fix this error, we pass a small value to extend the file size, instead of passing a huge value in a single go.
Reducing the value while extending the log file fixes the issue and log files can extend to their future size successfully.
3. Microsoft SQL Server Error 5009 While Removing Database File
Sometimes, this error occurs while removing a logical file in SQL Server.
Whenever we add any database file, its entry captures in system catalog files. If we try to delete any database file there is a possibility that the logical name of the file that we try to remove is not unique in the system catalog tables.
In order to fix this, our Support Techs suggest the steps given below:
i. Create a new logical file with a different name and the same data type:
ALTER DATABASE [Ibmimedia]
ADD FILE ( NAME = N'Ibmimedia_Logical_Name_New’, FILENAME = N’T:\DATA\Ibmimedia_file4.ndf’, SIZE = 10MB, MAXSIZE = 100MB)
ii. Now we remove the logical file we created in step 1, as in the following example:
ALTER DATABASE [Ibmimedia] REMOVE FILE [Ibmimedia_Logical_Name_New]
iii. Run a transaction log backup of the database.
iv. Now we remove the logical file that we were trying to remove earlier.