Subject Re: [firebird-support] shutdown database is it safe? - gbak - gfix
Author Helen Borrie
At 07:00 PM 15/02/2005 +0000, you wrote:


>I would like to ask 3 questions, if anyone could help
>because I have read many posts in various forums and
>I'm a little bit confused
>1) When we shutdown the database in force mode with 0 secs wait,
>are we absolutely sure that no one except SYSDBA and the
>creator can be/is connected to the database;

No. A wait of 0 give no users any opportunity to complete work. The
server will begin cleaning up, by rolling back uncommitted work and
disconnecting connections. This could well take some time and greatly
annoy users who had a big job running. Note that shutdown won't touch work
in progress being done under a SYSDBA or Owner login.

Shutting down a database is a way to get into the condition where SYSDBA or
Owner can get exclusive access. You shouldn't treat a forced shutdown as
an arbitrary way to spoil everyone's day. Always try to do a controlled
shutdown by giving a wait period and warning the connected users to finish
up.


>If yes then are we sure that the server itself doesn't do anything
>with the database for example garbage collection;

Once the shutdown -f wait period is over, the server will start cleaning
up, doing what it has to do to give SYSDBA or Owner the opportunity to log
in with exclusive access. If a GC thread or a sweep was running when the
timeout ended, it will complete. If the database was involved in a
cross-database transaction, there will be limbo flagging to do in the other
databases...and so on.

>If it does what is the meaning of the replace option in gbak since
>the only safe way to restore the database
>is to drop the original one and restore the backup;

This is a non-sequitur. Gbak is the backup program. Gbak
-replace_database is the UNSAFE way to restore any database, so much so,
that many of us think it should be removed as an option. You should never
drop the original database until you are sure that you have a backup that
can be restored. Gbak -b backs up data, warts and all. Any restore (
-create_database or -replace_database ) will croak on inconsistent
data. You will be in a bad place if you attempt gbak -r and the restore
croaks. You have a bad backup and a non-existent database.


>If no (shutdown doesn't guarantee that noone except
>SYSDBA and the db creator can connect)

Another non-sequitur. The purpose of shutdown -f is to prevent any more
connections or transactions from being started by non-privileged users.

>then droping the database and restoring from the backup is
>the only safe way to restore a database or is there any other
>way to shutdown the db for all?

Someone has given you a crazy idea, I'm afraid. You can backup the
database at any time, with or without exclusive access. You can even gbak
-r while users are logged in. Gbak -r *begins* by dropping the
database. It deletes the database file from disk. Please believe me when
I tell you that you should NEVER use it on a database you care about.


>2) If have read in many posts that backing up and restoring
>the database is much better than just gfix it once in a while.

Certainly, a restored database is squeaky clean, garbage-free, well
compacted and all indexes are nicely balanced. Kicking over to a restored
database is a good thing to do once in a while. Verifying a backup by
restoring it -c on another server and connecting to it is something you
should do after every backup.

Running gbak -b itself performs GC on the database, unless you set the -g
switch to prevent it. You should only set the -g switch if you plan to
kick over to a restored database.

In a well-behaved system, restoring a database might be something you do
once a year, or maybe only after an earthquake. In some systems, where
applications don't behave well, kicking in a restored database might be a
regular necessity just to keep things moving. In others, where
applications behave nicely, restored databases are commissioned only after
earthquake, flood or fire.

>But gfix seems to me better in the way it doesn't allow you
>to do anything unless it can get exclusive access to the
>database( does this mean excluding access form the server also;).

Gfix is a utility that gives access to a number of tools, including sweep
and validate. Gfix -sweep is a very good thing to do as part of regular
housekeeping. But you don't need exclusive access to run a sweep. But
sweeping is no substitute for maintaining backups.
Gfix -validate is good to do regularly if you have the kind of environment
where users do silly things like unplugging their workstations without
disconnecting from the database, because it will clean out unassigned pages
and free them up for re-use. It's also useful for finding corrupt
structures that can occur on dirty networks.

>But, am I missing anything if I just gfix the database regularly and
>ofcource perform regular backups and restore only in case of emergency;

Hard to say. What do you do with gfix regularly?

>3) Finally when gfix doesn't give any messages on the
>screen, means it has found no problems or something
>went wrong;

It depends what you are doing with gfix.

./hb