Accessing a Database

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

You might want to start up psql, to try out the examples in this manual. It can be activated for the dbname database by typing the command:
psql dbname
You will see the following message:
Welcome to psql, the PostgreSQL interactive terminal.

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

dbname=>

This prompt indicates that the terminal monitor is listening to you and that you can type SQL queries into a workspace maintained by the terminal monitor. The psql program responds to escape codes that begin with the backslash character, "\". For example, you can get help on the syntax of various PostgreSQL SQL commands by typing:
dbname=> \h
Once you have finished entering your queries into the workspace, you can pass the contents of the workspace to the PostgreSQL server by typing:
dbname=> \g
This tells the server to process the query. If you terminate your query with a semicolon, the backslash-g is not necessary. psql will automatically process semicolon terminated queries. To read queries from a file, instead of entering them interactively, type:
dbname=> \i filename
To get out of psql and return to Linux, type
dbname=> \q
and psql will quit and return you to your command shell.

Other things to note: