InterBase command line tutorial

From Support
Jump to: navigation, search

The InterBase command line tools are isql, gfix, gstat, gsec and gbak. IBConsole provides the functionality of all these commands in a graphic way. However, if you are familiar with command line tools, you can usually get jobs done faster with command line tools than IBConsole. Command line tools can also be automated, whereas IBConsole cannot. The InterBase Operations Guide manual is the definitive source for all documentation on using the command line tools. However, with the examples below, you can do must things you need to do.

Connection

Before you set up an environment for command line tools, you need to know where InterBase is installed. To know where InterBase is installed, run InterBase Server Manager from Embarcadero InterBase group in the start menu.

Ib cmd 1.png

Where InterBase is installed is specified by the Root Directory setting in InterBase Server Manager.

Ib cmd 2.png

Now that you know where InterBase is installed, go to a command prompt. To go to a command prompt, press Windows key-R, The Windows key looks like this on your keyboard:

Ib cmd 3.jpg

Windows key-R brings up the Run Dialog:

Ib cmd 4.png

Enter cmd in the run dialog and click OK.

Now, enter the following at the command prompt:

cd C:\Program Files\Embarcadero\InterBasexe3u2\bin<br />
set path=%cd%;%path%<br />
set isc_user=sysdba<br />
set isc_password=masterkey


  Finally, you need to use the CD command to change directory to where your database resides. In this example, we'll change directory to where the employee sample database is installed for InterBase. If you have a version of InterBase prior to XE3, or you have InterBase XE3 and it is not installed under Program Files, you can use the cd command as follows to get the sample  directory:

 

cd ..\examples\database

 

If you have InterBase XE3, you can use the cd command as follows to get to the sample directory:

 

cd %programdata%\embarcadero\interbase\gds_db

 

Here is a screen shot of all that has been done so far from the command prompt:

Ib cmd 5.png


Now that you have your paths set up correctly, using InterBase command line tools is pretty simple.


Using ISQL

Entering:

isql employee.gdb

will connect you to InterBase employee sample database. All isql commands end in a semicolon (;). This is because commands can be multiple lines. If you forget to enter a semicolon, you get a CON>prompt. Here are some example commands you enter when connected to the employee sample database (note that you can copy the text below and paste it into isql to save typing):

 

show tables;
show table country;
select * from country;
commit;
set transaction read committed;
set list on;
select * from country where country='USA';
rollback;
create database 'foo.ib';
create table t1 (
objid int not null primary key,
first_name varchar(10),
last_name varchar(10)
);
insert into t1 values (1, 'John', 'Smith');
delete from t1 where objid=1;
commit;
drop table t1;
drop database;
exit;

Here is a screen shot of what all the these commands executed in isql look like:


  Ib cmd 6.png  

So far, we've completed a local connection to a database via a relative path. Here are some other connection examples.

Connect via a complete path:

isql %cd%\employee.gdb

Connect via TCP/IP using localhost:

isql localhost:%cd%\employee.gdb

Connect via TCP/IP using the machine name:

isql %computername%:\%cd%\employee.gdb

 

Now a screen shot of all these commands:

Ib cmd 7.png

Notice Database in the last example. You can use this same path on any remote computer to connect. In other other words, your isql connection from a remote computer would look like:

isql NGYRN-64:C:\ProgramData\Embarcadero\InterBase\gds_db\examples\database\employee.gdb

 

Using gbak

Gbak is used to backup and restore database. Below are some example you can copy and paste into a command prompt to try. All run fast because the employee database is small. For larger databases, the -se option is much faster.

gbak employee.gdb employee.gbk -v
gbak -se service_mgr %cd%\employee.gdb %cd%\employee.gbk -v
gbak -se localhost:service_mgr %cd%\employee.gdb %cd%\employee.gbk -v
gbak -se %computername%:service_mgr %cd%\employee.gdb %cd%\employee.gbk -v
gbak -c employee.gbk employee.ib -v
gbak -r -se service_mgr %cd%\employee.gbk %cd%\employee.ib -v
gbak -r -se localhost:service_mgr %cd%\employee.gbk %cd%\employee.ib -v
gbak -r -se %computername%:service_mgr %cd%\employee.gbk %cd%\employee.ib -v

Using gfix

Validating a database and mending a database

A common task is to validate a database and then mend it if errors are reported.  Below are examples of validating and mending using relative and absolute paths that you can copy and paste into the command prompt to test. Because your copy of employee.gdb will be unlikely to need repair, these commands will appear to do nothing. Note that after mending a database, you must backup and restore the database using gbak as shown above to repair a database.

gfix -v -f -n employee.gdb
gfix -v -f %-n cd%\employee.gdb
gfix -mend employee.gdb
gfix -mend %cd%\employee.gdb

Ib cmd 8.png

Below are some other gfix commands you can try:

gfix -buffers 50000 employee.gdb
gfix -write direct employee.gdb
gfix -write sync employee.gdb
gfix -write async employee.gdb
gfix -sql_dialect 3 employee.gdb
gfix -sweep employee.gdb
gfix -housekeeping 20000 employee.gdb
gfix -mode read_only employee.gdb
gfix -mode read_write employee.gdb

Ib cmd 9.png

Using gstat

Use Gstat to get statistics about your database. Here are a few examples:

gstat -h employee.gdb

Ib cmd 10.png

gstat employee.gdb -t COUNTRY

Ib cmd 11.png

gstat employee.gdb -r -t COUNTRY

  Ib cmd 12.png

Using gsec

Use Gsec to maintain users in your security database and maintain aliases. Some examples:

gsec -add someuser -pw theirpassword
gsec -display
gsec -delete someuser
gsec -alias_add emp -alias_dbpath %cd%\employee.gdb
gsec -alias_dis
gsec -alias_del emp

Ib cmd 13.png

Finally, look carefully again at the command to add an alias named emp. Here it is again:

gsec -alias_add emp -alias_dbpath %cd%\employee.gdb

With this alias added your system, you no longer need to worry about paths when pointing to your database! Example:

Ib cmd 14.png