1.4. Accessing a Database

Once you have created a database, you can access it by:

You probably want to start up ltsql to try the examples in this tutorial. It can be activated for the mydb database by typing the command:

$ ltsql mydb

If you do not supply the database name then it will default to your user account name. You already discovered this scheme in the previous section using createdb.

In ltsql, you will be greeted with the following message:

ltsql (13.3-22.2)
Type "help" for help.

mydb=>

The last line could also be:

mydb=#

That would mean you are a database superuser, which is most likely the case if you installed the LightDB instance yourself. Being a superuser means that you are not subject to access controls. For the purposes of this tutorial that is not important.

If you encounter problems starting ltsql then go back to the previous section. The diagnostics of createdb and ltsql are similar, and if the former worked the latter should work as well.

The last line printed out by ltsql is the prompt, and it indicates that ltsql is listening to you and that you can type SQL queries into a work space maintained by ltsql. Try out these commands:

mydb=> SELECT version();
                                         version
-------------------------------------------------------------------​-----------------------
 LightDB 13.3-22.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit
(1 row)

mydb=> SELECT current_date;
    date
------------
 2016-01-07
(1 row)

mydb=> SELECT 2 + 2;
 ?column?
----------
        4
(1 row)

The ltsql program has a number of internal commands that are not SQL commands. They begin with the backslash character, \. For example, you can get help on the syntax of various LightDB SQL commands by typing:

mydb=> \h

To get out of ltsql, type:

mydb=> \q

and ltsql will quit and return you to your command shell. (For more internal commands, type \? at the ltsql prompt.) The full capabilities of ltsql are documented in ltsql. In this tutorial we will not use these features explicitly, but you can use them yourself when it is helpful.