Google

Getting Started With Lago
Installation

I've sucessfully installed lago on Linux, FreeBSD, SCO OpenServer and Solaris. On all platforms, I've had to compile it from source. I've gotten it to compile on OpenBSD and NetBSD, but never got it to run correctly. Lago is available from the Lago home page. For NetBSD and OpenBSD you need the version that comes with it's own pthreads implementation.

Lago will not successfully compile with gcc 2.96 or 3.0. You'll have to use gcc 2.95.

If your distribution does not come with gcc 2.95, you can download it from the GNU ftp site and compile it. I usually give the gcc configure script the --prefix=/usr/local/gnu-2.95 parameter so that gcc will be installed under /usr/local/gcc-2.95. Then, when building lago, I add /usr/local/gcc-2.95 to the beginning of my PATH environment variable so that it will be used during the build.

To build and install lago, you should create a lago user, assign it a password then build and install the software as that user. I usually give the lago configure script the --prefix=/usr/local/lago parameter so that Lago will be installed under /usr/local/lago. I then add /usr/local/lago/bin to my PATH environment variable and /usr/local/lago/lib to my LD_LIBRARY_PATH environment variable.

On some platforms lago requires a modification to compile. If compilation fails with an error in scktcman.xx, change line 146 of lago/conn/scktcman.cxx from

fd = accept(listener, (struct sockaddr *)&addr, &size);

to

fd = accept(listener, (struct sockaddr *)&addr, (socklen_t *)&size);

On some platforms lago requires a different modification. The files lago/querydef/qd_expr.h, lago/executor/exc_expr.cxx and lago/querydef/qd_dump.cxx refer to variables named "not". Some compilers don't like this. If you get an errors in those files, change the variable to __not wherever it appears.

Once the software is installed, run the following command.

/usr/local/lago/bin/lago --bootstrap

This command creates a SYS database with a special administrative user named lago and prompts you for a password for that user.

Starting the Database at Boot Time

You can use the following scrip to start/stop the database at boot/shutdown time.

#!/bin/sh

case "$1" in
        start)
                /usr/local/lago/bin/lago > /dev/null &
                ;;
        stop)
                kill `ps -efa | grep lago | grep -v grep | awk '{print $2}'`
                ;;
        *)
                echo $"Usage: $0 {start|stop}"
                exit 1
esac

exit 0

Install this script and run it with the "start" option to start up the database. Running it with the "stop" option shuts the database down. To access a database, it must be running.

Creating a Database

To use lago, you should create a database separate from the special SYS database. To do this, log into the SYS database as the lago user.

lsql -u lago -d SYS -p

To create a database named testdb, run the following query.

CREATE DATABASE testdb FILE '/usr/local/lago/data/testdb.lgo' SIZE 20;

To create a user named testuser, run the following command. The command will prompt you for a password and Reader/Writer/Administrator permissions. Make the user a Writer.

\U testuser

You can log out of the SYS database with the \q command. The new user should have access to the new database you created.

This should be enough to get you started. To set up more complex configurations, consult the Lago online documentation.

Accessing a Database

Accessing a Lago database using the lsql client tool is simple. For example, to access a database called testdb on the local machine as the testuser user, use the following command. You will be prompted for a password.

lsql -u testuser -d testdb -p

Once you're connected to the database, the lsql client prompts you to enter a query. Queries may be split across multiple lines. To run a query, end it with a semicolon. To exit, type \q.

A sample lsql session follows.

[user@localhost user]$ lsql -u testuser -d testdb -p
LSQL version 0.5.2, Copyright 1999, 2000 by Emanuele Fornara
LSQL comes with ABSOLUTELY NO WARRANTY; type '\l' for details and '\?' for help
password: 
testdb> create table testtable (
     2> col1 char(40),
     3> col2 integer 
     4> );
testdb> select * from tables;
+-----------+--------------------------------+-----------+-----------+
| TABLE_ID  |              NAME              | FIRSTPAGE | LASTPAGE  |
+-----------+--------------------------------+-----------+-----------+
|          1|TABLES                          |          1|          1|
|          2|COLUMNS                         |          2|          2|
|          3|testtable                       |          3|          3|
+-----------+--------------------------------+-----------+-----------+
3 rows returned
testdb> select * from columns where table_id=3;
+-----------+-----------+--------------------------------+-----------+-----------+-----------+-----------+
| TABLE_ID  | COLUMN_ID |              NAME              |   TYPE    |TPRECISION |  TSCALE   |   FLAGS   |
+-----------+-----------+--------------------------------+-----------+-----------+-----------+-----------+
|          3|          1|col1                            |         14|         40|          0|          1|
|          3|          2|col2                            |         10|          0|          0|          1|
+-----------+-----------+--------------------------------+-----------+-----------+-----------+-----------+
2 rows returned
testdb> insert into testtable (col1,col2) values ('hello',50);
testdb> insert into testtable (col1,col2) values ('hi',60);
testdb> insert into testtable (col1,col2) values ('bye',70);
testdb> select * from testtable;
+----------------------------------------+-----------+
|                  col1                  |   col2    |
+----------------------------------------+-----------+
|hello                                   |         50|
|hi                                      |         60|
|bye                                     |         70|
+----------------------------------------+-----------+
3 rows returned
testdb> update testtable set col2=0 where col1='hi';
testdb> select * from testtable;
+----------------------------------------+-----------+
|                  col1                  |   col2    |
+----------------------------------------+-----------+
|hello                                   |         50|
|hi                                      |          0|
|bye                                     |         70|
+----------------------------------------+-----------+
3 rows returned
testdb> delete from testtable where col2=50;
testdb> select * from testtable;
+----------------------------------------+-----------+
|                  col1                  |   col2    |
+----------------------------------------+-----------+
|hi                                      |          0|
|bye                                     |         70|
+----------------------------------------+-----------+
2 rows returned
testdb> drop table testtable;
testdb> \q
Accessing a Database With SQL Relay

Accessing Lago from SQL Relay requires an instance entry in your sqlrelay.conf file for the database that you want to access. Here is an example sqlrelay.conf which defines an SQL Relay instance called lagotest. This instance connects to the testdb database on the local machine as the user testuser with password testpassword.

<!DOCTYPE instances SYSTEM "sqlrelay.dtd">
<instances>

        <instance id="lagotest" port="9000" socket="/tmp/lagotest.socket" dbase="lago" connections="3" maxconnections="5" maxqueuelength="0" growby="1" ttl="60" endofsession="commit" sessiontimeout="600" runasuser="nobody" runasgroup="nobody" cursors="5" authtier="listener" handoff="pass">
                <users>
                        <user user="lagotest" password="lagotest"/>
                </users>
                <connections>
                        <connection connectionid="lagotest" string="user=testuser;password=testpassword;db=testdb" metric="1"/>
                </connections>
        </instance>

</instances>

If you want to connect to a database on a remote machine, say on testhost, you would need to add host=testhost; to the string attribute of the connection tag.

Now you can start up this instance with the following command.

sqlr-start -id lagotest

To connect to the instance and run queries, use the following command.

sqlrsh -id lagotest

The following command shuts down the SQL Relay instance.

sqlr-stop lagotest