Firebird Utils WIP
Firebird Utils WIP
Norman Dunbar
Table of Contents
1. Introduction ....................................................................................................................................... 1
2. Gsec - Firebird Password File Utility .................................................................................................. 3
Introduction ................................................................................................................................... 3
Commandline Options .................................................................................................................... 4
Gsec Commands ............................................................................................................................ 5
Interactive Mode ............................................................................................................................ 6
Displaying User Details .......................................................................................................... 7
Adding New Users ................................................................................................................. 7
Deleting Existing Users .......................................................................................................... 7
Amending Existing Users ....................................................................................................... 8
Help ...................................................................................................................................... 8
Version Information ............................................................................................................... 8
Batch Mode ................................................................................................................................... 9
Displaying User Details .......................................................................................................... 9
Adding New Users ................................................................................................................. 9
Deleting Existing Users ........................................................................................................ 10
Amending Existing Users ..................................................................................................... 10
Version Information ............................................................................................................. 11
Running Gsec Remotely ............................................................................................................... 11
Gsec caveats ................................................................................................................................ 12
Normal Versus Privileged Users ........................................................................................... 12
Differences Between Batch And Interactive Mode ................................................................. 12
Batch Mode Exit Codes ........................................................................................................ 13
Errors In Batch Mode Swap To Interactive Mode .................................................................. 13
3. Gfix - Firebird Database Housekeeping Utility ................................................................................... 14
Introduction ................................................................................................................................. 14
Command Line Options ................................................................................................................ 14
Gfix Commands ........................................................................................................................... 15
Shadow Files ............................................................................................................................... 16
Activating Shadows .............................................................................................................. 17
Killing Shadows ................................................................................................................... 18
Set Database Page Buffers ............................................................................................................ 19
Limbo Transaction Management ................................................................................................... 20
Listing Limbo Transactions .................................................................................................. 20
Committing Or Rolling Back ................................................................................................ 21
Automatic Two-phase Recovery ............................................................................................ 22
Cache Manager ............................................................................................................................ 22
Changing The Database Mode ...................................................................................................... 22
Setting The Database Dialect ........................................................................................................ 24
Database Housekeeping And Garbage Collection ........................................................................... 25
Garbage ............................................................................................................................... 25
Setting Sweep Interval .......................................................................................................... 26
Manual Garbage Collection .................................................................................................. 27
Disabling Automatic Sweeping ............................................................................................. 28
Database Startup and Shutdown .................................................................................................... 28
Database Shutdown .............................................................................................................. 28
Starting a Database .............................................................................................................. 30
New Startup and Shutdown States in Firebird 2.0 .................................................................. 30
iv
Commandline Utilities
Database Page Space Utilisation ...................................................................................................
Database Validation and Recovery ................................................................................................
Database Validation ..............................................................................................................
Database Recovery ...............................................................................................................
Database Write Mode ...................................................................................................................
Version Number ...........................................................................................................................
Caveats ........................................................................................................................................
Shadows ..............................................................................................................................
Response Codes Are Always Zero ........................................................................................
Force Closing a Database .....................................................................................................
Limbo Transactions ..............................................................................................................
4. Gsplit - Firebird Backup File Splitting Filter ......................................................................................
Introduction .................................................................................................................................
Gsplit Command line Options .......................................................................................................
Gsplit Command Parameters .........................................................................................................
Splitting Backups .........................................................................................................................
Joining Backup Files ....................................................................................................................
5. Assorted Firebird Scripts On Linux/Unix Systems ..............................................................................
Introduction .................................................................................................................................
Changing SYSDBA's Password ....................................................................................................
Creating Database Alias Names ....................................................................................................
createAliasDB.sh Parameters .................................................................................................
A Helping Hand With Makefiles ...................................................................................................
fb_config Options .................................................................................................................
Changing The Firebird Server Run User ........................................................................................
SSchangeRunUser.sh Parameters ...........................................................................................
Restoring root As The Firebird Server Run User ............................................................................
Running Embedded Or Client Server Applications .........................................................................
6. Still to come ... ................................................................................................................................
Appendix A: License notice ..................................................................................................................
31
32
32
34
34
35
35
35
35
36
36
38
38
39
39
40
41
42
42
42
43
43
44
44
45
45
46
46
48
49
Chapter 1
Introduction
The Firebird distribution kit installs a number of useful utility programs to assist in the running of your Firebird
server & databases. This book introduces you to the various utilities, some of which are more useful than others.
The utilities can all be found in the /bin directory (or \bin folder on Windows) under the Firebird installation
root. On Linux the utilities can be found in /opt/firebird/bin while on Windows, the default location is
c:\program files\firebird\firebird_x_y\bin. Where 'x' and 'y' depend on the version of Firebird
installed.
Fb_lock_print is the utility which prints out details of the internal database lock page.
Gbak is the database backup & restore utility. It also allows various parameters internal to the database to
be changed.
Gdef is a metadata utility which was removed from Interbase 4.0 and returned in the Open Source version
6. Gdef is probably redundant.
Gfix allows attempts to fix corrupted databases, starting and stopping of databases, resolving 'in limbo' transactions between multiple database, changing the number of page buffers and so on.
Gpre is the pre-processor which converts source code, which can be written in a number of languages, containing various embedded SQL 'pseudo code' into correctly formatted calls to the Firebird engine.
Gsec is the security database manipulation utility. It allows the DBA (or any privileged user) the ability to
maintain user accounts for various Firebird databases. Using various options, users can be added, amended
or deleted from the security database.
Gsplit is a filter which allows the limitations on maximum file sizes, found on some operating systems, to
be avoided when creating backups of large databases. This utility is supplied on Windows only and, unfortunately, seems not to work. Luckily, gbak allows backup files to be split into multiple parts, so gsplit is not
required. On Unix systems there are suitable operating system utilities that can be used instead of gsplit, if
required.
Gstat allows the Firebird administrator the ability to gather statistics about the general health and utilisation
of various parts of the database.
Isql is the interactive utility that allows ad-hoc queries to be run against a Firebird database. It is console
based - as are many of the utilities - and is supplied with all distributions of Firebird. Isql is usually the best
place to try out your scripts and commands in the first instance.
Qli is the original Query Language Interpreter which was removed from Interbase 4.0 but returned in Interbase
6.0 because of the decision to Open Source Interbase.
There are also various shell scripts installed under Linux and other Unix systems.
Introduction
Note
This book is a work in progress. Each chapter details a separate utility and as each one is completed to my
satisfaction, I shall add it to the CVS repository where it will be available for download. In this manner, there
will be a slow and gradual build up of hopefully useful manuals.
Chapter 2
Gsec - Firebird
Password File Utility
Introduction
Gsec is the security database manipulation utility. It allows the DBA (or any privileged user) the ability to
maintain user accounts for various Firebird databases. Using various options, users can be added, amended or
deleted from the security database.
Normal users, ie those not endowed with DBA privileges, can only see their own user details from version 2.0
of Firebird. They can, however, change their own passwords with the new version. Previous to the new version,
the DBA had to make the changes.
Note
It is possible on some operating systems that users will not be able to run gsec, even if they know the sysdba
password. This is because those operating systems allow the system administrator to set filesystem permissions
which prevent execution of certain programs and utilities for security reasons.
The Firebird database holds details of all users in a single security database. This is located on the server in
a normal Firebird database named security.fdb for Firebird 1.5 or security2.fdb for Firebird 2.0 onwards. The default locations for this file are :
C:\Program Files\Firebird\Firebird_1_5 for Windows.
/opt/firebird for Linux and other Unix systems.
The security database has two tables, users and host_info. The host_info table is empty and the users table holds
the details of each user allowed to access any Firebird database. Having said that, database roles and privileges
will prevent users logging into and manipulating databases to which they have no rights.
The gsec utility manipulates data in the users table in the security database, and by doing so, allows users to
be added, amended and deleted from the system. Not all columns of the users table are able to be displayed,
even though they can be amended. The user's password column is never shown by gsec, but you can change it,
for example.
Like most of the command line utilities supplied with Firebird, gsec can be run in interactive or batch mode and
has a help screen showing all of the utility's options, we'll be seeing that a little later on.
Coming up in this chapter, we have :
Commandline options for gsec.
Gsec commands and their parameters.
3
Commandline Options
Regardless of the mode that gsec is run in, there are a number of options that can be supplied on the command
line. These are :
-user <username>
Allows the username of the sysdba user to be specified if the database is to be modified, or a normal username if the database is to be displayed only. This need not be supplied if ISC_USER and ISC_PASSWORD
environment variables exist and have the correct values.
-password <password>
Supplies the password for the username specified above. This need not be supplied if ISC_USER and
ISC_PASSWORD environment variables exist and have the correct values.
-role <SQL role name>
Allows the specification of the role to be used by the connecting user.
-database <server:security database name>
You can specify the full pathname of a security database to gsec and this will allow you to remotely administer
the users for that server. The whole parameter should be enclosed in quotes if there are any spaces in the
path to the security database.
-z
Displays the version number of the gsec utility.
-help
Help displays the following screen of information :
gsec utility - maintains user password database
command line usage:
gsec [ <options> ... ] <command> [ <parameter> ... ]
interactive usage:
gsec [ <options> ... ]
GSEC>
<command> [ <parameter> ... ]
available options:
Gsec Commands
After the assorted options, comes the command that you wish to run. The following commands are available in
both batch and interactive modes, but for interactive mode the leading minus sign is not required.
-add <name> [ <parameter> ... ]
This command adds a new user to the database. You may optionally add other details such as first, middle
and last names plus a password for the new user, all in the same add command. Alternatively, you may add
a user then modify it to fill in the missing details.
-delete <name>
This command removes the named user from the database. All details of the user are removed and cannot
be undone unless you add the user back again.
-display [ <name> ]
This command displays the details of a single named user, or all users in the database. The password is never
displayed.
5
Interactive Mode
To run gsec in interactive mode, start the utility using the command line :
C:\>gsec -user sysdba -password masterkey
GSEC>
The GSEC> prompt shows that the utility is waiting for a command. The -user and -password options are those
of the user who wishes to manipulate the security database. Obviously, the username supplied must be a valid
sysdba user if updates are to be carried out. Normal users may only read the database.
To exit gsec in interactive mode, the quit command is used :
GSEC> quit
C:\>
The following sections show how to carry out various commands in interactive mode. It is assumed that you
are already running the utility as a sysdba user.
6
To display details of a single user, pass the username as a parameter to the display command.
GSEC> display epocman
user name
uid
gid
full name
-----------------------------------------------------------------------EPOCMAN
0
0
Benoit Gilles Mascia
GSEC>
If you enter the name of a non-existent user as a parameter of the display command, nothing is displayed and
gsec remains in interactive mode.
GSEC> display alison
GSEC>
uid
gid
full name
If, on the other hand, you try to delete a non-existing user, gsec will display an error message, and exit.
GSEC> delete newuser
record not found for user: NEWUSER
C:\>
If you wish to remove one or more of a user's attributes, don't pass a (new) value for that attribute.
GSEC> modify norman -mname -fname -lname
GSEC> display norman
user name
uid
gid
full name
-----------------------------------------------------------------------NORMAN
0
0
Now I can be known as 'the man with no name', just like Clint Eastwood !
Help
The help command, in interactive mode, displays the same help screen as shown above.
Version Information
The version of gsec can be obtained using the z command.
GSEC> z
Batch Mode
Note
In the following descriptions of batch mode operations, assume that I have set the ISC_USER and
ISC_PASSWORD environment variables. This allows gsec to be run without always having to specify the user and -password switches. This in turn reduces the amount of code on the command line, which means
that when this XML file is rendered into pdf, all the commandline will fit on the width of an A4 page.
It is not secure to have these variables set all the time, so don't do it !
Warning
If you are using gsec from Firebird version 1.5 (and possibly version 1.0 as well) then when you are running
in batch mode, you may think that you can check the result of an operation by checking %ERRORLEVEL% in
Windows, or $? in various flavours of Unix. This doesn't work. The result is always zero.
In gsec from Firebird version 2.0 onwards, this problem is fixed and the exit code will be zero for everything
was ok, or a non-zero value for error conditions.
To display details of a single user, pass the username as a parameter to the display command.
C:\>gsec -display epocman
user name
uid
gid
full name
-----------------------------------------------------------------------EPOCMAN
0
0
Benoit Gilles Mascia
If you wish to remove one or more of a user's attributes, don't pass a (new) value for that attribute.
C:\>gsec -modify norman -mname -fname -lname
C:\>gsec -display
user name
uid
gid
full name
-----------------------------------------------------------------------SYSDBA
0
0
NORMAN
0
0
EPOCMAN
0
0
Benoit Gilles Mascia
Version Information
The version of gsec can be obtained using the -z command. However, note that it leaves you in interactive mode
on completion. It doesn't exit like the other batch mode commands do, so you have to use the interactive quit
command to exit. There is a way around this problem as shown in the following. The first part shows the problem.
C:\>gsec -z
gsec version
GSEC>
The solution is to have a small file containing the command quit and force gsec to read this file when it needs
user input, as follows.
C:\>copy con fred
quit
^Z
1 file(s) copied.
C:\>gsec -z <fred
gsec version WI-V1.5.0.4306 Firebird 1.5
GSEC>
C:\>
This could be a good idea for any of the commands which leave you 'stuck' in the interactive mode when you
thought you were running in batch mode. By redirecting input from a command file, gsec will read a line of text
from that file any time it requires user input. By forcing it to read the quit command, you make it exit.
Note
The -z command doesn't need a -user and -password, it will display the version details and then tell you
that you don't have a username/password - but you can safely ignore this message.
Note
In the above example, I have split the full commandline over two lines. This is to prevent it 'falling off' the
right side of the page when this chapter is rendered as a PDF document. The whole command should, and must,
be typed on a single line.
Also note that if there are spaces in the database name, you must enclose the whole parameter in double quotes.
11
Gsec caveats
The following is a brief list of gotchas and funnies that I have detected in my own use of gsec. Some of these
are mentioned above, others may not be. By collecting them all here in one place, you should be able to find
out what's happening if you have problems.
A normal users can only display details from the security database.
C:\>gsec -user norman -password norman -display
user name
uid
gid
full name
-----------------------------------------------------------------------SYSDBA
0
0
NORMAN
0
0
Norman Dunbar
EPOCMAN
0
0
Benoit Gilles Mascia
Note
From Firebird version 2 onwards, there are slight changes to the above. Users are now able to change their own
passwords and can no longer display details of other users that may be present in the security database.
The above user, running under Firebird 2.0 would see the following :
C:\>gsec -user norman -password norman -display
user name
uid
gid
full name
-----------------------------------------------------------------------NORMAN
0
0
Norman Dunbar
Note also that you will be left in interactive mode when an error occurs. The correct commandline should have
a minus in front of the display command, as follows :
C:\>gsec -user sysdba -password masterkey -display
user name
uid
gid
full name
-----------------------------------------------------------------------SYSDBA
0
0
NORMAN
0
0
Norman Dunbar
EPOCMAN
0
0
Benoit Gilles Mascia
This time, gsec performed its duties, displayed all known users and quit from the utility.
Warning
If environment variables ISC_USER and ISC_PASSWORD have been defined, and this isn't a very good idea
for security reasons, gsec can be run without passing the -user or -password options.
Warning
As with all of the command line utilities, it is best to use the version of the gsec utility that was supplied with
your database.
13
Chapter 3
14
Gfix Commands
Note
In the following discussion, I use the full parameter names in all examples. This is not necessary as each
command can be abbreviated. When the command is shown with '[' and ']' in the name then these are the
optional characters.
For example, the command -validate is shown as -v[alidate] and so can be specified as -v, -va, val and so on up to the full -validate version.
For almost all of the options in the following sections, two of the above command line options will be required.
These are -u[ser] and -pa[ssword]. These can be supplied for every command as parameters on the command line, or can be configured once in a pair of environment variables.
-u[ser] username
Allows the username of the SYSDBA user, or the owner of the database to be specified This need not be
supplied if the ISC_USER environment variable has been defined and has the correct value.
-pa[ssword] password
Supplies the password for the username specified above. This need not be supplied if the ISC_PASSWORD
environment variable has been defined and have the correct value.
To define the username and password as environment variables on a Linux system:
linux> export ISC_USER=sysdba
linux> export ISC_PASSWORD=masterkey
15
Warning
This is very insecure as it allows anyone who can access your session the ability to perform DBA functions
that you might not want to allow.
Note
The line that starts with 'Unable to perform' above, has had to be split to fit on the page of the PDF file. In
reality, it is a single line.
Warning
Anyone on the same Linux or Unix server where you are running the above command may be able to use the
ps command and view the password you have used.
You will notice, hopefully, that some commands do not give any printed output at all. gfix, in the main, only
reports when problems are encountered. Always check the response code returned by gfix to be sure that it
worked. However, see the caveats section below for details because it looks like the response code is always zero.
Note
When logging into a database on a remote server, you will always be required to pass the -u[ser] and pa[ssword] parameters.
Shadow Files
A shadow file is an additional copy of the primary database file(s). More than one shadow file may exist for any
given database and these may be activated and de-activated at will using the gfix utility.
The following descriptions of activating and de-activating shadow files assume that a shadow file already exists
for the database. To this end, a shadow was created as follows:
16
It can be seen that the database now has two separate shadow files created, but as they are manual, they have
not been activated. We can see that shadows are in use if we use gstat as follows:
linux> gstat -header my_employee | grep -i shadow
Shadow count 2
Note
Sometimes, it takes gstat a while to figure out that there are shadow files for the database.
Note
Shadow file details can be found in the RDB$FILES table within the database.
Activating Shadows
The command to activate a database shadow is:
gfix -ac[tivate] <shadow_file_name>
This makes the shadow file the new database file and the users are able to continue processing data as normal
and without loss.
In the event that your main database file(s) become corrupted or unreadable, the DBA can activate a shadow file.
Once activated, the file is no longer a shadow file and a new one should be created to replace it. Additionally,
the shadow file should be renamed (at the operating system prompt) to the name of the old database file that
it replaces.
Warning
It should be noted that activating a shadow while the database itself is active can lead to corruption of the
shadow. Make sure that the database file is really unavailable before activating a shadow.
Once a shadow file has been activated, you can see the fact that there are active shadows in the output from gstat:
linux> gstat -header my_employee | grep -i shadow
Shadow count 2
Attributes
active shadow, multi-user maintenance
17
Note
The DBA can set up the database to automatically create a new shadow file in the event of a current shadow
being activated. This allows a continuous supply of shadow files and prevents the database ever running without
one.
Killing Shadows
The command to kill all unavailable database shadows, for a specific database, is:
gfix -k[ill] database_name
In the event that a database running with shadow files loses a shadow, or a shadow becomes unusable for some
reason, the database will stop accepting new connections until such time as the DBA kills the faulty shadow
and, ideally, creates a new shadow to replace the broken one.
The following (contrived) example, shows what happens when the database loses a shadow file and an attempt
is made to connect to that database. There are two sessions in the following example, one is connected to the
database while the second deletes a shadow file and then tries to connect to the database. The command line
prompts shows which of the two sessions we are using at the time.
First, the initial session is connected to the database and can see that there are two shadow files attached:
linux_1>isql my_employee
Database: my_employee
SQL> show database;
Database: my_employee
Owner: SYSDBA
Shadow 1: "/home/norman/firebird/shadow/my_employee.shd1" manual
Shadow 2: "/home/norman/firebird/shadow/my_employee.shd2" manual
...
In the second session, we delete one of the shadow files, and then try to connect to the database
linux_2> rm /home/norman/firebird/shadow/my_employee.shd2
linux_2> isql_my_employee
Statement failed, SQLCODE = -901
lock conflict on no wait transaction
-I/O error for file "/home/norman/firebird/shadow/my_employee.shd2"
-Error while trying to open file
-No such file or directory
-a file in manual shadow 2 in unavailable
Use CONNECT or CREATE DATABASE to specify a database
SQL> quit;
The second session cannot connect to the database until the problem is fixed. The DBA would use the gfix k[ill] command to remove details of the problem shadow file from the database and once completed, the second
(and subsequent) sessions would be able to connect.
linux_2> gfix -kill my_employee
linux_2> isql my_employee
Database: my_employee
SQL> show database;
Database: my_employee
18
The database now has a single shadow file where before it had two. It is noted, however, that gstat still shows
the database as having two shadows, even when one has been removed.
linux> gstat -header my_employee | grep -i shadow
Shadow count 2
Attributes
active shadow, multi-user maintenance
Note
In addition to the above strange result, if I subsequently DROP SHADOW 1 and COMMIT, to remove the remaining shadow file, gstat now shows that the shadow count has gone up to three when it should have gone
down to zero!
19
If the command is run against the remote database then nothing will be listed because that database does not
have any limbo transactions - the transaction that went into limbo, when the network failed, for example, was
initiated on the local database.
20
When committing or rolling back all limbo transactions, the -p[rompt] option can be specified. It is, however,
not permitted when processing a single transaction. An example of using the -p[rompt] option has been shown
above under listing limbo transactions.
21
Cache Manager
When the help page for gfix is displayed there is a message in the output for the -ca[che] option which states:
...
-ca[che]
...
However, when called this option simply displays the help page again. It is assumed that, at version 2.0 of
Firebird, this option does not yet work.
The question that immediately springs to my mind is, if we can shutdown the cache manager with this option,
how do we start it back up again?
Note
Firebird uses SQL internally to maintain its internal structures with details about transactions, for example, and
this is the reason that a database must be placed on a read/write file system regardless of whether only SELECT
statements are run or not.
Note
Only databases in dialect 3 can be changed to read only mode.
If there are any connections to the database in read/write mode when you attempt to convert the database to read
only, the attempt will fail as shown below.
linux> gfix -mode read_only my_employee
lock time-out on wait transaction
-lock time-out on wait transaction
23
Warning
As with many failures of gfix, the response code returned to the operating system is zero.
Because you cannot use gstat remotely, you may also use the isql command SHOW SQL DIALECT from a remote
location to see which dialect your client and database are using, as follows:
remote> isql my_employee -user norman -password whatever
Database: my_employee
SQL> show sql dialect;
Client SQL dialect is set to: 3 and database SQL dialect is: 3
24
To set dialect 2 for your client connection, you use isql as follows:
linux> isql my_employee
Database: my_employee
SQL> set sql dialect 2;
WARNING: Client SQL dialect has been set to 2 when connecting to Database SQL dialect 3 database.
SQL> show sql dialect;
Client SQL dialect is set to: 2 and database SQL dialect is: 3
Note
The WANRING line above has had to be split to fit on the page of the PDF version of this manual. In reality,
it is a single line of text.
In the Super Server version of Firebird 2.0, garbage collection has been vastly improved. There are now three
different ways of operation and these are configurable by setting the GCPOLICY parameter in the firebird.
conf configuration file. By default, Super Server uses combined while Classic Server uses cooperative. The
other option is background.
Note
Classic Server ignores the setting and always uses cooperative garbage collection.
Note
This doesn't mean that every 20,000 transaction a sweep will take place. It will take place when the difference
between the OIT and the next transaction is greater than the sweep interval.
An interesting transaction is one which has not yet committed. It may be still active, in limbo or may have been
rolled back.
The sweep facility runs through the database and gets rid of old rows in tables that are out of date. This prevents
the database from growing too big and helps reduce the time it takes to start a new transaction on the database.
Note
If you find that starting a new transaction takes a long time, it may be a good idea to run a manual sweep of
the database in case the need for a sweep is causing the hold-up.
You can check if a manual sweep may be required by running the gstat utility to check the database header page
and extract the oldest and next transaction numbers from the output. If the gap is small (less than the sweep
interval) then a manual sweep may be in order. Alternatively, the SHOW DATABASE command in isql will also
show the details you need.
A manual sweep can be run by using the -s[weep] command. (See below).
To alter the database's automatic sweep interval, use the following command:
gfix -h[ousekeeping] INTERVAL database_name
The INTERVAL parameter is the new value for the sweep interval. The database name parameter is the database
upon which you wish to alter the setting for automatic sweeping. The following example shows the setting being
changed from the default to a new value of 1,000.
linux> gfix -h 1000 my_employee
linux> gstat -header my_employee | grep Sweep
Sweep interval:
1000
Database Shutdown
If there is maintenance work required on a database, you may wish to close down that database under certain circumstances. This is different from stopping the Firebird server as the server may well be running other databases
which you do not wish to affect.
The command to close a database is:
gfix -shut OPTION TIMEOUT database_name
The TIMEOUT parameter is the time, in seconds, that the shutdown must complete in. If the command cannot
complete in the specified time, the shutdown is aborted. There are various reasons why the shutdown may not
complete in the given time and these vary with the mode of the shutdown and are described below.
The OPTION parameter is one of the following:
-at[tach] - prevents new connections.
-tr[an] - prevents new transactions.
-f[orce] - simply aborts all connections and transactions.
When a database is closed, the SYSDBA or the database owner can still connect to perform maintenance operations or even query and update the database tables.
Note
If you specify a long time for the shutdown command to complete in, you can abort the shutdown by using the
-online command (see below) if the timeout period has not completed.
28
of the SYSDBA and the database owner. The shutdown will fail if there are any sessions connected after the
timeout period has expired. It makes no difference if those connected sessions belong to the SYSDBA, the
database owner or any other user. Any connections remaining will terminate the shutdown with the following
details:
linux> gfix -shut -attach 5 my_employee
lock conflick on no wait transaction
-database shutdown unsuccessful
Anyone other than the SYSDBA or database owner, attempting to connect to the database will see the following:
linux> isql my_employee -user norman -password whatever
Statement failed, SQLCODE = -901
database my_employee shutdown
Use CONNECT or CREATE DATABASE to specify a database
SQL>
Connections in the database will still be able to start new transactions or complete old ones.
If there are any active transactions after the timeout period has expired, then the shutdown will fail as follows:
linux> gfix -shut -tran 5 my_employee
lock conflick on no wait transaction
-database shutdown unsuccessful
If any user connected to the database being shutdown with the -tr[an] tries to start a new transaction during
the shutdown timeout period, the following will result:
SQL> select * from test;
Statement failed, SQLCODE = -902
database /home/norman/firebird/my_employee.fdb shutdown in progress
Statement failed, SQLCODE = -902
database /home/norman/firebird/my_employee.fdb shutdown in progress
Statement failed, SQLCODE = -901
Dynamic SQL Error
-SQL error code = -901
-invalid transaction handle (expecting explicit transaction start)
Force Closure
-f[orce] : shuts down with no regard for the connection or transaction status of the database. No new con-
nections or transactions are permitted and any active sessions are terminated along with any active transactions.
Anyone other than SYSDBA or the database owner trying to connect to the database during the timeout period
will not be able to connect successfully or start any (new) transactions.
29
Starting a Database
Once all maintenance work required on a database has been carried out, you need to restart the database to allow
normal use again. (See shutdown option above for details of closing a database.)
The -o[nline] command allows a database to be restarted. It takes a single parameter which is the database
name as follows:
gfix -o[nline] database_name
The following example shows a closed database being started.
linux> gfix -online my_employee
There is a hierarchy of states for a database. The above list shows them in order with normal at the top and
full at the bottom.
30
multi-user maintenance
single-user maintenance
full shutdown
linux>
The following example sets the page usage back to the default:
linux> gfix -use reserve my_employee
linux> gstat -header my_employee | grep Attributes
Attributes
If you are using full page utilisation then the Attributes show up with 'no reserve' in the text. This doesn't appear
for normal 80% utilisation mode.
When a database is validated the following checks are made and corrected by default:
Orphan pages are returned to free space. This updates the database.
Pages that have been misallocated are reported.
Corrupt data structures are reported.
There are options to perform further, more intensive, validation and these are discussed below.
Default Validation
The command to carry out default database validation is:
gfix -v[alidate] database_name
32
Full Validation
By default, validation works at page level. If no need to go deeper and validate at the record level as well, the
command to do this is:
gfix -v[alidate] -full database_name
using this option will validate, report and update at both page and record level. Any corrupted structures etc
will be fixed.
Read-only Validation
As explained above, a validation of a database will actually validate and update the database structures to,
hopefully, return the database to a working state. However, you may not want this to happen and in this case, you
would perform a read only validation which simply reports any problem areas and does not make any changes
to the database.
To carry out a read only validation, simply supply the -n[o_update] option to whichever command line you
are using for the validation. To perform a full validation, at record and page level, but in reporting mode only,
use the following command:
gfix -v[alidate] -full -n[o_update] database_name
On the other hand, to stay at page level validation only, the command would be:
gfix -v[alidate] -n[o_update] database_name
Database Recovery
If the database validation described above produces no output then the database structures can be assumed to
be valid. However, in the event that errors are reported, you may have to repair the database before it can be
used again.
Note
Firebird defaults to synchronous mode (forced writes enabled) on Linux, Windows NT, XP, 2000, 2003 and
Vista.
Warning
If your database was originally created with Interbase 6 or an early beta version of Firebird then the database
will be running in asynchronous mode - which is not ideal.
Version Number
The -z option to gfix simply prints out the version of the Firebird utility software that you are running. It takes
no parameters as the following example (running on Linux) shows.
linux> gfix -z
gfix version LI-V2.0.0.12748 Firebird 2.0
Caveats
This section summarises the various problems that you may encounter from time to time when using gfix. They
have already been discussed above, or mentioned in passing, but are explained in more details here.
Shadows
The gstat seems to take some time to respond to the addition of shadow files to a database. After adding two
shadows to a test database, gstat still showed that there was a Shadow count of zero.
Even worse, after killing the second shadow file and running the DROP SHADOW command in isql to remove
the one remaining shadow file, gstat decided that there were now three shadow files in use.
Note
In the above, the line warning about the shutdown mode being incorrect has had to be split over two lines. They
are, in fact, a single line of text. The PDF generation requires long lines be split in this manner.
Limbo Transactions
There are a couple of problems with limbo transactions as discovered by Paul in his testing.
36
In the above example, the original database my_employee.fdb was first of all copied using the operating system
command cp to my_new_employee.fdb and then renamed to my_old_employee.fdb.
Gfix was then run on the copy named my_new_employee.fdb and it noted the limbo transaction. However, it could
not find the original database file as it had been renamed, so gfix prompted for the path to the original database
file. When this was entered, gfix happily listed the details.
Warning
This implies that if you have a database with limbo transactions and you copy it using the operating system
utilities and subsequently run gfix against the new database, it is possible to have gfix fix limbo transactions
in the original database file and not in the one you think it is updating - the copy.
It is also a good warning about making copies of databases without using the correct tools for the job.
37
Chapter 4
Warning
In testing with Firebird 1.5, on Windows XP Home, gsplit doesn't seem to work and always returns error 9.
Because of the problems in getting gsplit to work correctly, as you shall see in the remainder of this chapter,
you are advised to use the splitting and joining facilities of the gbak utility itself rather than trying to make
gsplit work for you.
38
Note
Take note of the error in the above help text. The correct command line option to join multiple sections of a
large backup file is not -JOINT_BK_FILE as shown, but is in fact -JOIN_BK_FILE.
Splitting Backups
To run gsplit , you need to use it as a filter on the command line for gbak, as the following example shows :
C:\>gbak -b norman.fdb stdout |
gsplit -split norman_1.fbk 1m norman_2.fbk 1m norman_3.fbk
Warning
The command above assumes that ISC_USER and ISC_PASSWORD have been defined. For the sake of this
demonstration, this is acceptable, but in a real system, consider the security implications before defining these
variables.
In addition, the above command line has been split over two lines to allow the pdf generation of this manual
to work. In reality, the command must be typed on a single line.
It is unfortunate that the utility doesn't seem to work, as the following shows :
C:\>gbak -b norman.fdb stdout |
gsplit -split norman_1.fbk 1m norman_2.fbk 1m norman_3.fbk
fail to read input from ib_stdin, errno = 9
gsplit: progam fails to generate multi-volumn back-up files
Done with volume #0, "stdout"
Press return to reopen that file, or type a new
name followed by return to open a different file.
Name:^C
If you type a filename at the prompt it will simply be used as a destination for a full dump of the database, so
be careful not to overwrite anything important. I tend to hit CTRL-C at this point to avoid problems.
The utility has actually created the first file in the above list, norman_1.fbk, and written 100 bytes to a special
header which identifies it as a gsplit created file.
40
Warning
The command above assumes that ISC_USER and ISC_PASSWORD have been defined. For the sake of this
demonstration, this is acceptable, but in a real system, consider the security implications before defining these
variables.
In addition, the above command line has been split over two lines to allow the pdf generation of this manual
to work. In reality, the command must be typed on a single line.
Note
The spelling errors in 'program' and 'volume' above are as produced by the utility.
Warning
The above command line has been split over two lines to allow the pdf generation of this manual to work. In
reality, the command must be typed on a single line.
If you have a number of split backup files created using gbak itself and not filtered through gsplit, you cannot
use gsplit to stitch them together for a restore as the following example shows :
C:\>gsplit -join norman_1.fbk norman_2.fbk norman_3.fbk |
gbak -c stdin create_norman.fdb
gsplit: expected GSPLIT description record
gsplit: Exiting before completion due to errors
gsplit: progam fails to join multi-volumn back-up files
gbak: ERROR: expected backup description record
gbak: Exiting before completion due to errors
Warning
The above command line has been split over two lines to allow the pdf generation of this manual to work. In
reality, the command must be typed on a single line.
It appears that gsplit and gbak have different header information in the backup files and the two are not compatible.
Note
The spelling errors in 'program' and 'volume' above are as produced by the utility.
41
Chapter 5
changeDBAPassword.sh
createAliasDB.sh
fb_config
changeRunUser.sh
restoreRootRunUser.sh
changeGdsLibraryCompatibleLink.sh
Note
The above list is correct at the time of writing and applies to Firebird 1.5 Super Server installed on a Linux
system. Other flavours of Unix may have different scripts. I am currently unable to discuss those potential
changes as I do not have access to other Unix systems.
42
Caution
Whenever you change the SYSDBA password using the gsec utility, you should also change the startup script
file as well. To ensure a complete update, always use this script when changing the SYSDBA user's password.
If your system is not set up properly, the database creation step may fail but the alias will still be added to the
aliases file. This could leave you subsequently unable to add the alias properly, as the script checks to ensure that
you do not overwrite an existing alias. You will have to manually edit the alias file to remove the broken alias.
To set up new databases, they must be owned by the firebird user, and also owned by the firebird group. The
following shows a new directory being created by the root user to allow Firebird databases to be created.
# cd /u01
# mkdir databases
# chown firebird:firebird databases
#
At this point the directory /u01/databases is available for use as a repository for one or more Firebird
databases. Obviously, in the above example, the /u01 directory already existed.
createAliasDB.sh Parameters
To run the createAliasDP.sh script, use a commandline similar to the following :
# createAliasDB.sh <new_alias> <database_name>
The script takes two parameters on the commandline, both of which are mandatory :
43
fb_config Options
To run the fb_config script, use a commandline similar to the following :
fb_config <option> [ <option> [...]]
The SSchangeRunUser.sh script allows the user and group, under which the Super Server runs, to be
changed. By default, this is now the firebird user and group, however, in previous versions the Firebird server
ran as the root user which is undesirable from a system security point of view and allowed databases to be created
all over the file system. With the new firebird user, restrictions can be placed on where databases can be created.
The script changes the owing user and group of a number of files in the Firebird installation directory, the logfile
and also the startup script /etc/rc.d.init.d/firebird which is used to start and stop the Firebird server.
SSchangeRunUser.sh Parameters
To run the script, use a commandline similar to the following :
SSchangeRunUser.sh <username> <groupname>
The script takes two parameters on the commandline, both of which are optional as you will be prompted if
both are omitted. If you only supply one parameter, it is assumed to be the username and you will be prompted
for the groupname.
45
This script simply restores the old style installation format whereby the Firebird Super Server runs as the root
user and group. This script is simply a wrapper around the SSchangeRunUser.sh script, passing root as the
username and group name.
Note
This script must be run as root.
The following example shows how this script is used to change from embedded servfer to client server use :
# cd /opt/firebird/bin
# ./changeGdsCompatibleLibraryLink.sh
For classic server there are two optional backward compatible client
libraries. These are libfbclient.so and libfbembed.so.
libfbclient.so) enables your client to be multithreaded but must
connect to a database via a server.
libfbembed.so) allows the client to directly open the database file,
but does not support multithreaded access
Your current setting is:
/usr/lib/libgds.so -> /opt/firebird/lib/libfbembed.so
Which option would you like to choose (client|embed|remove)
[client] client
#
The default option is client which will recreate the symlink to the client server library, embed will recreate
the symlink to the embedded server, while remove will remove the symlink altogether.
There are no messages displayed to inform you of the success of the script, however, if you run it again, you
will notice the current setting should be different to that displayed when you previously ran the script.
47
Chapter 6
48
49