Subject | Re: Mass Deletes and Backup/Restore questions to make a database smaller in size |
---|---|
Author | Adam |
Post date | 2008-12-22T22:29:11Z |
--- In firebird-support@yahoogroups.com, "SoftTech" <miket@...> wrote:
activities on others. Then do a backup and restore to make the size
of the database smaller.
production database until I'm sure this will work.
records in it and we have decided to do some house keeping on this
table by keeping the last 30 activity results for each account and
deleting the rest of the records.
one field ACCT_ID) and then loop through each record in this dataset
which then calls a stored procedure that selects all records for this
account in descending order and deletes any record past the first 30
records.
successfully did the job in several hours returning that over 3-1/2
million records were deleted.
Not if you intend to do a backup/restore cycle immediately afterwards.
It is neither good nor bad. It comes down to your business
requirements. Keep in mind that Firebird can not truly delete the
records straight away in case some concurrent snapshot transaction
needs that data. Instead it flags each record as deleted. Eventually,
the record can be physically removed in a process called garbage
collection. This garbage collection may be costly (especially on 1.5
or earlier with certain indices), so you must take this into
consideration or you will end up impacting the performance of your users.
the backup take longer now because of the mass delete?
* You will need exclusive access to the database during this cycle,
(or at least make sure no-one else can write to the database, because
any transactions committed after the backup starts will not be
included in the backup file). I physically rename the database file.
* If you intend to do a backup-restore, use the -g switch in gbak.
There is no point waiting for garbage collection if you intend on
deleting the original file anyway. If you have deleted a bunch of
records, the backup file will be smaller and the restore will be quicker.
* Restore the database to a different name. If for whatever reason the
restore fails, you don't want to have overwritten the original
database file.
* Don't allow anyone to connect until the restore has completed.
Forget file size. Firebird will re-use disk space if you manage your
transactions. If you have running transactions for hours/days on end,
garbage collection won't be able to keep up which will cause you
problems, but if you run a cron job every night to purge records older
than X, I would expect your database size to stabilise and grow only
in proportion to the growth in records.
Adam
>database and keep the last 30 days on some tables and the last 30
> Greetings All,
>
> Firebird 1.5.3
> Delphi 5.1
>
> My goal is to do house keeping on all of the history tables in our
activities on others. Then do a backup and restore to make the size
of the database smaller.
>production database so that I could test my work and not affect the
> Please keep in mind that I did the following on a backup of the
production database until I'm sure this will work.
>from a predictive dialer. The table currently has over 5-1/2 million
> One of the tables in our database (DIALER_RESULTS) stores results
records in it and we have decided to do some house keeping on this
table by keeping the last 30 activity results for each account and
deleting the rest of the records.
>DIALER_RESULTS_ACCT table into a TClientDataSet (This table has just
> I have created a program that selects all records from the
one field ACCT_ID) and then loop through each record in this dataset
which then calls a stored procedure that selects all records for this
account in descending order and deletes any record past the first 30
records.
>on the same server used for the production database) and it
> I ran this program on a weekend with no one else around (as I ran it
successfully did the job in several hours returning that over 3-1/2
million records were deleted.
>force garbage collection?
> Q: Should I have done a select statement against this database to
Not if you intend to do a backup/restore cycle immediately afterwards.
>one table?
> Q: Is it a good thing to delete this many records at one time from
It is neither good nor bad. It comes down to your business
requirements. Keep in mind that Firebird can not truly delete the
records straight away in case some concurrent snapshot transaction
needs that data. Instead it flags each record as deleted. Eventually,
the record can be physically removed in a process called garbage
collection. This garbage collection may be costly (especially on 1.5
or earlier with certain indices), so you must take this into
consideration or you will end up impacting the performance of your users.
>backup normally takes a few hours to run on a 6-1/2 GB database. Will
> Q: Any gotchas when it comes to doing a backup and restore? The
the backup take longer now because of the mass delete?
* You will need exclusive access to the database during this cycle,
(or at least make sure no-one else can write to the database, because
any transactions committed after the backup starts will not be
included in the backup file). I physically rename the database file.
* If you intend to do a backup-restore, use the -g switch in gbak.
There is no point waiting for garbage collection if you intend on
deleting the original file anyway. If you have deleted a bunch of
records, the backup file will be smaller and the restore will be quicker.
* Restore the database to a different name. If for whatever reason the
restore fails, you don't want to have overwritten the original
database file.
* Don't allow anyone to connect until the restore has completed.
>what all should be done to make the size of the database smaller?
> Q: Any guidelines available on the best ways to do a mass delete and
Forget file size. Firebird will re-use disk space if you manage your
transactions. If you have running transactions for hours/days on end,
garbage collection won't be able to keep up which will cause you
problems, but if you run a cron job every night to purge records older
than X, I would expect your database size to stabilise and grow only
in proportion to the growth in records.
Adam