| What to do? | How to do? |
|---|---|
| Log into the machine that was provided for assignment 0. | ssh <user-name>@<machine-name> |
| Download the file hw2-script.tar.gz into your account. Please cut and paste the COMPLETE command (the URL has been broken across two separate lines). | wget http://www.cs.cmu.edu/~natassa/courses/15-415/ |
Unpack the archive into the directory of your choice. This directory will be referred to as HWDIR henceforth.
The archive should expand into a number of files, including loadData.sql. This is the file that contains
the SQL statements that will create the sample database you are to use to test your queries.
| tar -xzvf hw2-script.tar.gz |
Set the environment variable PGDATA to point to the directory
in which you wish to store your data.
| mkdir $HOME/data; export PGDATA=$HOME/data
|
| Prepare the data directory for use by the PostgreSQL server. | initdb $PGDATA
|
Start an instance of PostgreSQL on a port that no one else is using. For this
purpose try using the last 4 or 5 digits of your student ID number as a port number. Remember,
port numbers have to be between 4000 and 16000. If you find that you are unable to start the
PostgreSQL server on that port just try another one until you can.
If everything is okay you should see something like:
LOG: checkpoint record is at 0/807ACC
| pg_ctl start -o '-i -p <yourportnum>' |
| Create a new database called "hw1", that you can use for this assignment. | createdb -p <yourportnum> hw1
|
Connect to your database using the psql client. Please make sure you
change your current working directory to HWDIR (i.e., the directory containing the file loadData.sql)
| cd <HWDIR>; psql -p <yourportnum> hw1
|
You will receive a welcome message from PostgreSQL ...
Welcome to psql 7.3.3, the PostgreSQL interactive terminal.
... followed by a shell-style prompt hw1=#
| |
| Load the sample data for this assignment. | hw1=# \i loadData.sql |
psql\i filename.sql into the psql prompt instructs psql to load the file "filename.sql" and
execute all of the SQL commands listed in that file. We recommend that you prepare your queries in a .sql file,
to save you the trouble of retyping them. (Anyway, you will need to create an .sql file for your final
submission.) You can use your favorite text editor (e.g., vi, emacs, pico, etc.) to edit this file.psql prompt and you forget to close a paranthesis or
add a terminating semicolon, there is still hope. When this happens psql will change its prompt to let
you know that it is still waiting for a right-parenthesis or semicolon.
authors (author_id INTEGER, author_name VARCHAR (50), author_affiliation VARCHAR (100)) papers (paper_id INTEGER, paper_title VARCHAR (100), category VARCHAR (30)) writes (author_id INTEGER, paper_id INTEGER)The
authors table assigns a unique identifier to each author in the database and stores his name, affiliation.papers table assigns a unique identifier to each paper in the database and stores its title and category (category refers
to the general technical area to which the paper belongs, e.g., "Databases", "Machine Learning", etc.)writes table stores authorship information by associating the author_id of an author with the paper_id
of the papers that he has authored (or co-authored.)
pages (page_id INTEGER, url VARCHAR (300)) sites (site_id INTEGER, name VARCHAR (100)) words (word_id INTEGER, word VARCHAR (30)) belongs (page_id INTEGER, site_id INTEGER) contains (page_id INTEGER, word_id INTEGER, position INTEGER) links (links_id INTEGER, linked_id INTEGER)The
pages table assigns a unique identifier to each Web page in the database and stores its complete URL.sites table assigns a unique identifier to each Web site in the database and stores its name.words table assigns a unique identifier to each word that occurs in the database (i.e., in any of the Web pages),
and stores the complete word as a string.belongs table associates the identifier of a Web page with the identifier of the Web site to which it belongs.contains table associates the identifier of a Web page with the identifiers of each word that it contains, along with the
position in the page where the word occurs (1st word at position 1, 2nd word at position 2 and so on).linkstable stores hyperlink information. The links_id field refers to the id of the Web page which links to the Web
page with id linked_id. For example, a tuple of the form (1003, 429) in the links table says that
the Web page with id 1003 links to the Web page with id 429./afs/cs/academic/class/15415-s06-users/<youruserid>/hw2/shashank@cs.cmu.edu.