Disk space constraint when attempting to delete data from DB - sql-server

I need to delete some old logs from the database, however due to lack of space in the physical hard disk, there isn't enough space to sustain the growth of transaction log resulting from the delete activity.
My question is:
If i were to write a cursor to delete the data, would this action still contribute to the transaction log growth from this activity? I think yes, but just to confirm.
If #1 is not an option, then what else can I try? Physical disk space increase is not an option either.
Hope I've provided sufficient information to get some help. Please let me know if more is required.
Thanks in advance for any help received.

#GarethD is this a viable solution?
Perform full backup of the entire database into a remote location – ensure that this backup copy can be restored successfully.
Assuming that you wish to retain the data from years 2012 to present day, export out ONLY all the data that you wish to retain from UGCALL.
Ensure that this export can be imported into an empty table successfully and the data is not corrupted.
Truncate the UGCALL table. Check the disk space once truncate operation has been completed.
Re-import the data exported in step (2) into the UGCALL table and verify that the import is successful.
Check the disk space usage once more to see if remaining space is sufficient.

Yes, deleting row-at-a-time by a cursor will cause the same problem.
As noted, only a TRUNCATE TABLE will delete all rows without logging them individually. It uses less log space, but still some.

Related

recover space after dropping user in oracle

I have virtualbox with oracle database. So, I had 5 gb space left. I tried to import 2gb something dmp file, and it failed after disk became full. So, I tried to drop it by using "DROP USER ABC";
The username was dropped but the space was not recovered.
Please let me know I would be able recover this space?
Thank you.
Did you use the "CASCADE" option? If the user dropped without that option, then it didn't own any database objects and would not have recovered any space. There are other ways you could have lost the space, too, besides from the data itself: archived transaction logs, space for indexes (that don't store data in the dmp files), and the growth of the TEMP tablespace come immediately to mind.
Use the DBA_SEGMENTS view to establish which objects are actually taking up space in your database, which users own them, and which tablespaces they're located in:
https://docs.oracle.com/en/database/oracle/oracle-database/19/refrn/DBA_SEGMENTS.html
http://dba-oracle.com/t_dba_segments.htm
Also check your archivelog location, automatic diagnostic repository (ADR) for log and trace file growth, and see if you can reduce the size of your TEMP tablespace (if it seems to have grown).

Sql Server LDF file taking too large space

Why is my database log file taking to high space? Its almost taking up 30GB of my HDD. Even after deleting 1,000,000 records, its not freeing up any space.
So,
1.Why is the log file taking this much space (30gb)?2.how can I free up the space?
1.Why is the log file taking this much space (30gb)?
Or because of your recovery not SIMPLE and ldf grown eventually to such size
Or because there was a large one-time DML operation
Or because of other reasons, as noted by #sepupic in another answer
2.how can I free up the space?
IF recovery is other than SIMPLE:
Firstly backup transaction log file
Perform a shrink, like DBCC SHRINKFILE(2,256)
IF recovery is SIMPLE:
Just shrink it to desired size, like DBCC SHRINKFILE(2,256)
If the database log still did not reduce to a target size, then the exact reason to be checked, by using a code snippet of #sepupic
Some members still give and advice to physicaly remove LDF files.
I highly suggest to not do this. Remarkable related post of Aaron Bertrand:
Some things you don't want to do:
Detach the database, delete the log file, and re-attach. I can't
emphasize how dangerous this can be. Your database may not come back
up, it may come up as suspect, you may have to revert to a backup (if
you have one), etc. etc.
1. Why is the log file taking this much space (30gb)?
It was because the Autogrowth / Maxsize was set 200,000 MB
2. how can I free up the space?
As described Here i used the following command and the file is now less than 200mb
ALTER DATABASE myDatabaseName
SET RECOVERY SIMPLE
GO
DBCC SHRINKFILE (myDatabaseName_log, 1)
GO
ALTER DATABASE myDatabaseName_log
SET RECOVERY FULL
I have also set Autogrowh/Maxsize in the database properties to 1000 as Limited (See the image below).
The link describes more, so I recommend referring it for detailed description and other options.
Thanks #hadi for the link.
Why is my database log file taking to high space?
There can be more causes, not only the 2 mentioned in another answer.
You can find the exact reason using this query:
select log_reuse_wait_desc
from sys.databases
where name = 'myDB';
Here is a link to the BOL article that describes all the possible causes under log_reuse_wait:
sys.databases (Transact-SQL)
how can I free up the space?
First you should determine the cause using the query above, then you should fix it, for example, if it's broken replication you should remove it or fix it.
You need a maintenance job to backup the transaction log, and do it often: like every 10 minutes or so.
A FULL backup once per day isn't good enough.
Alternatively, you can change the Recovery Model of the database from FULL to SIMPLE. But if you do this, you'll lose the ability to do point-in-time restores.
In my case the DB names was with bad characters so the script doesn't worked.
I found out and follow this article, which worked perfect in two steps: changing backup log from full to simple and shrink DB log file more than 95%

Why does my SQL Server logfile have 99% space available after giving me a full warning?

While deleting a large number of records, I get this error:
The transaction log for database 'databasename' is full
I found this answer very helpful, it recommends:
Right-click your database in SQL Server Manager, and check the Options page.
Switch Recovery Model from Full to Simple
Right-click the database again. Select Tasks Shrink, Files Shrink the log file to a proper size (I generally stick to 20-25% of the size of the data files)
Switch back to Full Recovery Model
Take a full database backup straight away
Question: in step 3, when I go to shrink > files and choose log from the file type dropdown menu, it tells me that 99% of the allocated space is free.
Out of ~4500MB of allocated space, there is ~4400MB free (the data file size is ~3000MB).
Does that mean I'm good to go, and there is no need to shrink?
I don't understand this. Why would that be the case, given the warning I received initially?
I'm not one for hyperbole, but there are literally billions of articles written about SQL Server transaction logs.
Reader's digest version: if you delete 1,000,000 rows at a time, the logs are going to get large because it is writing those 1,000,000 deletes in case it has to roll back the transaction. The space needed to hold those records does not get released until the transaction commits. If your logs are not big enough to hold 1,000,000 deletes, the log will get filled, throw that error you saw, and rollback the whole transaction. Then all that space will most likely get released. Now you have a big log with lots of free space.
You probably hit a limit on your log file at 4.5gb and it wont get any bigger. To avoid filling your logs in the future, chunk down your transactions to smaller amounts, like deleting 1,000 records at a time. A shrink operation will reduce the physical size of the file, like from 4.5gb down to 1gb.
https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-shrinkfile-transact-sql?view=sql-server-2017

PostgreSQL failed imports still claim hard disk space? Need to clear cache?

I have a PostgreSQL (10.0 on OS X) database with a single table for the moment. I have noticed something weird when I'm importing a csv file in that table.
When the import fails for various reasons (e.g. one extra row in the csv file or too many characters in a column for a given row), no rows are being added to the table but PostgreSQL still claims that space on my hard disk.
Now, I have a very big csv to import and it failed several time because the csv was not compliant to begin with - so I had tons of import fails that I fixed and tried to import again. What I've realized now is that my computer storage has been reduced by 30-50 GB or so because of that and my database is still empty.
Is that normal?
I suspect this is somewhere in my database cache. Is there a way for me to clear that cache or do I have to fully reinstall my database?
Thanks!
Inserting rows into the database will increase the table size.
Even if the COPY statement fails, the rows that have been inserted so far remain in the table, but they are dead rows since the transaction that inserted them failed.
In PostgreSQL, the SQL statement VACUUM will free that space. That typically does not shrink the table, but it makes the space available for future inserts.
Normally, this is done automatically in the background by the autovacuum daemon.
There are several possibilities:
You disabled autovacuum.
Autovacuum is not fast enough cleaning up the table, so the next load cannot reuse the space yet.
What can you do:
Run VACUUM (VERBOSE) on the table to remove the dead rows manually.
If you want to reduce the table size, run VACUUM (FULL) on the table. That will lock the table for the duration of the operation.

SQL-Server: Truncate of transaction-logs inf FULL-BACKUP-Mode

I found a link expaining very well the main factors of transaction-log. But there is 1 statements I don't understand completly:
The FULL recovery model means that every part of every operation is
logged, which is called being fully logged. Once a full database
backup has been taken in the FULL recovery model, the transaction log
will not automatically truncate until a log backup is taken. If you do
not want to make use of log backups and the ability to recover a
database to a specific point in time, do not use the FULL recovery
model. However, if you wish to use database mirroring, then you have
no choice, as it only supports the FULL recovery model.
My question are:
Will the transaction-logs get truncated if I have a database in Full-Backup-Mode but have neither taken an full-backup than an log-backup? Will the free space overwriten after next checkpoint? And when will those checkpoints be reached? Do I need to set a soze limit for the transaction logs to force the truncation or not?
Many thanks in advance
When your database is in full recovery mode,only log backup frees the space in log file..
This space won't be available for file system,but will be internally marked as free,so that new transactions can use this space
Will the free space overwriten after next checkpoint? And when will those checkpoints be reached? Do I need to set a size limit for the transaction logs to force the truncation or not?
You need not do anything,just ensure log backups are taken depending on your requirements

Resources