Using PostgreSQL at IMADAIn DM505, we will be using the relational database system PostgreSQL. This note explains how to connect to the system at IMADA.
dbhost
The PostgreSQL system resides on the machine
This assumes you are already logged into some other IMADA machine
(which itself can be done using ssh from e.g. a machine at home
(
If you are using
The PostgreSQL System
The system is composed of a database server part (the program
The PostgreSQL system has it own set of usernames and passwords, which are unrelated to the usernames and passwords of IMADA accounts. For all participants with an existing IMADA account, an PostgreSQL account has been created, with the same username as their IMADA account, and with a password which has been mailed to them. If you do not yet have an IMADA account, contact staff in order to get one, and then contact the lecturer for PostgreSQL account creation. If you have an account, but are unable to connect, contact the lecturer.
Creating Databases
Your first action should be to create a database. Each database is a
collection (empty at the beginning) of relations. You can create a new
database with the name
If the command Databases can be destroyed again using the command
Again, you may need to set your
Using DatabasesWhen using PostgreSQL, you connect to one database at a time. Your start a connection to a database by
This will put you in interactive mode, which allows you to define relations, insert tuples, and make queries by issuing SQL commands at the prompt.
Note that SQL is a "free format" language, allowing you to write the entire
query on a single line. It is also case insensitive. Hence, you may write
queries like "select name from student where sid = 101;" in
Beside SQL commands,
Alternatively, input and output files can be specified when starting
Setting your PATH variable
If your shell is not able to find the PostgreSQL commands
If your are using
to the file
If your are using
to the file
Documentation
PostgreSQL comes with ample
documentation. See for
instance the
SQL
description and the
refence
section (including the
man
page of When looking up documentation, note that the Postgresql installation at Imada is version 7.3, which is not the newest available. By the way, the links above is to the documentation for version 7.4, because it is better structured than the documentation for version 7.3 (while the two versions hopefully are not very different).
Sample Test DataTo learn SQL, you need to try out in practice some actual SQL commands. Here is a list of easy SQL examples which you may start out with. However, for more interesting queries, you need more data (relation schemas and relation instances). For your convenience, here is a zip-archive containing sample data (from the database textbook Database Management Systems by Ramakrishnan and Gehrke, ISBN 0-07-115110-9 , here adapted to PostgreSQL syntax). The relations constitute a couple of small (non-related) databases, but the grouping into databases, and the meaning of the relations, are somewhat self-explanatory from the relation and attribute names.
In the archive, the file
The details of the The data in the archive cannot be added in arbitrary order, due to the foreign key constraints appearing in the table definitions (try it out and see for yourself).
Maintained by Rolf Fagerberg (rolf@imada.sdu.dk) | |