Subject Re: [firebird-support] Firebird 3 - Auto Garbage collection with Sweep interval = 0
Author Helen Borrie
Hello Arnaldo,
Friday, February 16, 2018, 2:19:19 AM, Arnaldo wrote:

> maybe i have always misunderstood the garbage collection mechanism, the
> sweep interval, etc.. and i'm realising only now, but:

> I have this database (Firebird 3.03 SuperServer x64)

> My question is : why garbage collection mechanism starts automatically
> when i browse these tables, despite the fact that i have Sweep Interval
> = 0 ? What is the point that i'm missing ?

Some more thoughts to add to Norm's comments...

Garbage collection (GC) and sweeping are separate, although
interrelated, processes. By setting the sweep interval to 0, you
disable automatic sweeping (according to the conditions described by
Norm) but you get GC regardless of the sweep interval setting. The
sweep interval setting has no effect on the GC that is being performed
constantly by the engine.

A GC run updates the record statistics but it does not remove the
stubs of deleted records.

There are three possible settings for the GcPolicy parameter in
firebird.conf to govern how GC is performed: background, cooperative
and combined. The GC mechanism described by Norm is 'cooperative':
each time a user opens a table, old record versions from others' work
will be flagged if they are no longer "interesting" and previously
flagged versions will be removed.

Superserver can also do 'background': that is, a worker thread that
wakes up periodically and runs in the background, doing the same
tasks that cooperative does. Background GC is not available in Classic
or Superclassic.

For SS, the default GcPolicy setting is 'combined': both background and
cooperative mechanisms are used. You can change this to 'background' or
'cooperative' if you want to test whether unexpected slowdowns are being
caused by one or other of the two GC mechanisms.

The GcPolicy setting has no effect on either the sweep interval or the
way the engine performs a sweep.

Periodic sweeping will be needed if auto sweeping is disabled. Watch
the statistics to determine how often you might need to do it. An "ad
hoc" manual sweep might be needed after a large batch of deletes, to
get rid of those delete stubs.

A gbak backup does a sweep by default, unless you run it with the -g
switch ( [no_]g[arbage-collection] ). If you have a regular backup
routine with the default settings, you might not need to run manual
sweeps at all. However, you will need them if you are relying only on
nBackup for your backups, as nBackup does not touch garbage.

HB