Connecting to the Sever
PostgreSQL like most modern DBMS uses a client/server model. The server manages the databases while the client provides an interface between the user and the database. The server is typically run as a daemon which is always running on the server system.
To use the DBMS, you must connect the client to the server. With PostgreSQL, you use the psql command
psql -h serverhost -U username dbname
where
serverhost- is the name or address of the system running the PostgreSQL server.
username- is your database username (note this can be different from the host system username).
dbname- the name of the database to which you are connecting. You can only connect to one database at a time.
Common Commands
The command-line provided by the PostgreSQL client application is not only used to enter SQL commands, but also various DBMS commands. In PostgreSQL these commands between with a backslash (\).
\q- Quit the
psql client.
\?- Get help on the DBMS commands.
\h- Get help on the SQL commands. To get help on a specific command append the command after
\h. For example, to get help on the SQL SELECT command, use \h select.
\dt- View a list of tables in the database.
\d table- Describe the attributes of the given table. (i.e.
\d grade)