2 1.4. Accessing a Database #
4 Once you have created a database, you can access it by:
5 * Running the PostgreSQL interactive terminal program, called psql,
6 which allows you to interactively enter, edit, and execute SQL
8 * Using an existing graphical frontend tool like pgAdmin or an office
9 suite with ODBC or JDBC support to create and manipulate a
10 database. These possibilities are not covered in this tutorial.
11 * Writing a custom application, using one of the several available
12 language bindings. These possibilities are discussed further in
15 You probably want to start up psql to try the examples in this
16 tutorial. It can be activated for the mydb database by typing the
20 If you do not supply the database name then it will default to your
21 user account name. You already discovered this scheme in the previous
22 section using createdb.
24 In psql, you will be greeted with the following message:
30 The last line could also be:
33 That would mean you are a database superuser, which is most likely the
34 case if you installed the PostgreSQL instance yourself. Being a
35 superuser means that you are not subject to access controls. For the
36 purposes of this tutorial that is not important.
38 If you encounter problems starting psql then go back to the previous
39 section. The diagnostics of createdb and psql are similar, and if the
40 former worked the latter should work as well.
42 The last line printed out by psql is the prompt, and it indicates that
43 psql is listening to you and that you can type SQL queries into a work
44 space maintained by psql. Try out these commands:
45 mydb=> SELECT version();
47 -------------------------------------------------------------------------------
49 PostgreSQL 18.0 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2
53 mydb=> SELECT current_date;
65 The psql program has a number of internal commands that are not SQL
66 commands. They begin with the backslash character, “\”. For example,
67 you can get help on the syntax of various PostgreSQL SQL commands by
71 To get out of psql, type:
74 and psql will quit and return you to your command shell. (For more
75 internal commands, type \? at the psql prompt.) The full capabilities
76 of psql are documented in psql. In this tutorial we will not use these
77 features explicitly, but you can use them yourself when it is helpful.