Could not restore a database - sql-server

I do not understand this error message:
There is insufficient free space on disk volume 'S:\' to create the database. The database requires 291.447.111.680 additional free bytes, while only 74.729.152.512 bytes are available.
It is true I have 74GB free on my disk S, but I'm trying to restore a backup file having only 2.4 GB.
Is it possible a backup of 2GB to fill 291 GB?
Later edit: Source database before backup has 52GB (data) + 225G (log).

You can use RESTORE FILELISTONLY FROM DISK = N'C:\Path\YourBackup.bak' to check the space used by the DB in the backup upon restoration. Basically, this will allow you to see how big it'll be, without actually restoring the backup.

You can restore the database on a separate drive. Let's say you are getting you don't have sufficient space on C: drive, then you can do it on another drive like D:\ , E:\ or anyone. You can do it like the below image

Related

Restore of database fails

I got the error message below while restoring the database from the shared folder.
Restore of database failed 'XYZ'. Modify file encountered operating system error 112 there is not enough space on the disk while attempting to expand the physical file.
The backup file size is 28 GB. Restore is to the H: drive having 500 GB of free space. How do I solve this?
Run the following command to get the file size of the backup and then you can check whether or not your drives have enough space available:
restore filelistonly FROM DISK='drive:\path\backup_file.bak'

sql- move log file to another drive

i'm working on huge DB, and while insert\work with big files, log file increase to 60GB and over, and eat all my drive so it can't continue processing.
i tried shrink log file but it work afterwards, and while working it increase again so i thought to move the log file (only) to my 2nd drive where i got more space.
i tried by Detach and Attach but it didnt work , error :
An error occurred when attaching the database(s). Click the hyperlink
in the Message column for details.
i also tried manually by alter command:
ALTER DATABASE [databasename]
MODIFY FILE ( NAME = filename , FILENAME = "new file location and name");
but it make the DB "recovery pending" and i had to restore it back from backup.
any other options?
Since you restored from backup, you can add the MOVE command to your restore command to move the log file to a new drive during the restore.
USE [master]
GO
RESTORE DATABASE [YourDatabase] FROM DISK = 'c:\mssql\backup\Full.bak'
WITH CHECKSUM,
MOVE 'YourDatabase_Log' TO 'E:\newdir\Log.ldf',
RECOVERY, REPLACE;
In order to keep your log file from growing too much, you need to increase the frequency of your log backups, assuming you aren’t on SIMPLE RECOVERY MODEL. Shrinking without backing up is not going to do much, if anything at all. When you backup a log file, the committed transactions are backed up and cleared from the log, freeing up space. As you have witnessed your log file will continue to grow based on the workload. Thus, regular shrinking of the log file isn’t really going to help you.

Can't backup database when LOG_BACKUP file is full

The problem that I encounter, is that the LOG_BACKUP file of one of my databases is full. This is a SQL Server 2012 environemnt. The problem occurs because there is a limited space allocated for the log file. The space on the disk itself is sufficient to do a backup. Normally on test systems I would set the recovery mode from FULL to SIMPLE, do a shrink file, and set it back to FULL.
However, I am now working on another system and I would like to preserve the backup chain. So the next thing I try is to increase the allocated space for the log file. This does not work because of the 9002 message (LOG_BACKUP full). Also doing a full backup of the database does not work, with the same message.
As far as I can find, these are the options to clear your LOG_BACKUP file. How can I resolve this issue?

Database drive size was overfilled due to log file how to fix it?

I had stuck with one of our team issue where database drive size was overfilled due to log file which was around 150 GB and there was no hope of making any space on server. So, they had detached the database and then deleted to log file. But, then they were then not able to attach the mdf file. I then tried to rebuild log file but it was too not successful as there was no clean shutdown in database. Has anyone gone through this problem and successfully recovered the database?
sp_attach_single_file_db followed by a DBCC CHECKDB should do the trick. Any uncommitted transactions that might still be in that log file will be lost.
If you have an offline database in your metadata, delete that one first with DROP DATABASE but make sure you have a backup of your MDF file.

Why do we need the LDF files along with MDF files?

What would happen if I delete the .ldf file that is in the same folder that my .mdf file?
The LDF file is the transaction log and is required for all SQL server configurations. Depending on the recovery mode, will determine how it is used. However all queries basically get stored here until successfully committed to the database (MDF).
You will not be able to delete it while SQL server service is running. You can detach the database, delete the log file (LDF) and reattach the data file (MDF). However it will just create a new log file. You really should not need to delete it. If it is getting too large you will need to manage it, typically through the backup process.
The database will be marked as suspect on SQL Server restart and inaccessible without some in depth fiddling to recover it.
The LDF is an essential part of the database: you need this file.
You can of course ignore us, and delete it and see for yourself...
As already pointed out, the .LDF file is crucial for the DB and the DB will not be available without one. The .LDF can be deleted only if the DB is offline, or detached or SQL Service is stopped.
Assuming that one of the above 3 scenario was true and you did delete the .LDF file, then the DB would be suspect when SQL server is restarted. If the DB was offline and you try to bring it back online, it will give you an error:
File activation failure. The physical file name "<<filename.ldf>>" may be incorrect.
Msg 945, Level 14, State 2, Line 1
Database '<<DB Name>>' cannot be opened due to inaccessible files or insufficient
memory or disk space. See the SQL Server errorlog for details.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
It is quite simple to fix this error, but you will need to delete all the Metadata pertaining to the DB from system files. The easiest way to do that would be to drop the DB. Here is what you will need to do.
Take the DB offline or detach the DB
Make a copy of the .MDF file to your backup directory
Now Drop the DB (You will have to reattach the DB, if you detached, of course)
Copy the .MDF back to the original location
After these steps, run the following:
SP_ATTACH_SINGLE_FILE_DB #dbname='<<DBName>>'
,#physname=N'<<filepath\filename.MDF>>'
This should return you the following:
File activation failure. The physical file name "<<Filepath\filename.ldf>>"
may be incorrect.
New log file '<<Filepath\filename.ldf>>' was created.
That would bring your DB back to an usable state.
The million $$$$ question still remains - why would anyone want to delete the .LDF file???
Raj
The best way to keep the size of .LDF file in check is:
to regularly take transaction log backups at least once a day or
change your recovery model from full to simple ( by default, its full)

Resources