There are several ways to access the database besides through the PostgreSQL terminal monitor program. A few of these are:

Native frontend tool

Using an existing tool like pgaccess or ApplixWare (via ODBC) will enable you to create and manipulate databases.

Languages with support for a PostgreSQL interface

Perl, tcl, are great examples of languages that provide convenient and powerful GUI toolkits which aid in the construction of custom applications. Pgaccess is an example of a tk/tcl written application that provides these functionalities.

Large Object Interface

This interface supports PostgreSQL and provides file oriented access to user data that has been declared to be a large type.

libpq library

This is the C application programming interface (API) to PostgreSQL. This allows you to submit queries in SQL or PostgreSQL form through the C language and send the resulting output straight into your program.

libpq++ library

This is the C++ application programming interface (API) to PostgreSQL. It has two main processes, the Database Class and the Large Object Class. These classes allow users to manipulate databases and large objects within the database.

Examples in this book use psql to execute queries. To enter into a psql session, use the command:

   psql databasename 

Using our Book Town Company example, we will start psql and use the booktown database:

   psql booktown

This message should appear:

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help on internal slash commands
       \g or terminate with semicolon to execute query
       \q to quit


This message shows that you are now in psql and you are in the booktown database. You can now use SQL commands to query tables in this database. The psql program supplies escape codes which begin with a backslash (\). These codes display information about objects in a database and syntax for PostgreSQL commands. Here are a list of some possible commands that can be used with psql:


This may be the most common command that you will use. It lists all of the SQL/PostgreSQL commands that are supported. If you forget a command syntax, then you can use the \h command name. For instance, this prints the syntax for the INSERT command:

   \h insert

Command:     INSERT
Description: Inserts new rows into a table
INSERT INTO table [ ( column [, ...] ) ]
    { DEFAULT VALUES | VALUES ( expression [, ...] ) 
    | SELECT query }

\d {t|i|s|v}

If no parameters are specified after the \d, the default will list all of the tables in this database, the type of object it is, and the owners of the tables. If you specify 't' it lists tables, 'i' lists indices/indexes, 's' lists sequences, and 'v' lists views.

\d {a|f|o}

Again, if no parameters are specified, then the \d will default to listing tables. If an 'a' is specified, then it lists aggregates, 'f' lists functions, and 'o' lists operators. These lists can be long at times, so you can scroll down to the next screen by using the space bar, or scroll down one row using the return/enter key, and quit by typing the letter 'q.'


This lists all database names, owners, and encoding information.

\d T

This lists possible data types, their description, and range.

\i filename

This reads and executes queries from the file specified. If this file is not in this directory, you can specify the exact path of this file.


This terminates SQL commands, but you can also use the semi-colon (;) in place of this.


This quits the psql session and returns you to the Unix command shell.


This displays a complete list of possible internal slash commands and their descriptions.

Help us make a better book, leave feedback. (