Using Database Aliases
In the examples above, we have been using the full path to the database file.This has the disadvantage that all clients need to know exactly where the database is to be found, or may cause problems when the database has to be moved.To alleviate these problems, database aliases can be used.
Once Firebird has been installed, a file named databases.conf
(Firebird 3.0 and higher) or aliases.conf
(Firebird 2.5 and earlier) can be found in the main installation folder.By adding an entry to this folder, the full path to the database can be simplified to an alias.This makes connecting easier, and allows the database to be moved around as necessary without having to change all clients to allow them to connect to the database at the new location.
To create an alias for the database currently known as /databases/firebird/MY_EMPLOYEE.FDB
on the cosmos Linux server, we need to add the following to the databases.conf
file on the cosmos server.By default, this will be in the folder /opt/firebird
.On Linux, this file is owned by the root user and so, must be updated by the root user.On Windows, you need to be either an administrator, a power user or SYSTEM to change the file.
my_employee = /databases/firebird/MY_EMPLOYEE.FDB
There should be no quotes around the path to the database file.
Regardless of the current location of the database file, or if it has its physical filename renamed, etc., all local users can refer to the database simply as my_employee.Remote users will refer to this database as cosmos:my_employee.The following example shows an isql
session connecting locally to the database using the alias rather than a full path:
$ /opt/firebird/bin/isql my_employee Database: test, User: sysdba SQL>
Alternatively, a remote connection would be made as follows, specifying the server name and database alias together:
$ isql cosmos:my_employee Database: cosmos:my_employee SQL>
Because the alias is defined on the server where the database resides, the remote client needs to supply the server name and alias (as defined on that server) to connect.
Using the CONNECT
command in an existing isql
session is equally simple using aliases:
SQL> CONNECT 'cosmos:my_employee'; Database: cosmos:my_employee SQL>
Caution
|
Do not think that aliases hide the full path to the actual database file from your users.Any user is still able to query this information from within the database: SQL> select MON$DATABASE_NAME from mon$database; MON$DATABASE_NAME ================================= /data/databases/firebird/test.fdb SQL> select RDB$GET_CONTEXT('SYSTEM', 'DB_NAME') from RDB$DATABASE; RDB$GET_CONTEXT ================================= /data/databases/firebird/test.fdb |