The Third Lab
Install and Learn PostgreSQL (I)
(I) Install PostgreSQL on Your Own Machine
Choose your operating system in "Binary packages".
Install the Version 9.2.13 ( The PostgreSQL version on CS Server is 9.2.13).
Leave Port as 5432 .
Remember the password created during the installation.
Install "Database Drivers".
JDBC for Java Programming.
ODBC and OLE DB for C, C++, C# Programming.
Install "Web Development".
Leave Apache Port as 8080 .
(II) Open PostgreSQL on Your Own Machine
(a) Open SQL Shell program.
(b) Open a Terminal (Terminal on Mac and Linux, CMD on Windows).
(b1) Firstly, go to PostgreSQL bin folder, for example, "\...\PostgreSQL\9.2\bin"
(b2) Secondly, type psql -U [username] to enter shell in terminal.
Either follow (I) & (II), if you are using your own machine.
Or follow (III), if you plan to use the server in CS department.
(III) Use PostgreSQL on CS460 Server
(a) For the Linux and Mac users using BU network:
Open Terminal .
Type SSH [username]@cs460.bu.edu to log on the database server.
(b) For the Linux and Mac users outside the BU network:
Open Terminal .
Type SSH [username]@csa2.bu.edu and log on the csa2 server first.
Then type SSH [username]@cs460.bu.edu and log on to the database server.
(c) For the Windows users using BU network:
Open PuTTY .
Use [username]@cs460.bu.edu to log on the database server.
(d) For the Windows users outside the BU network:
Open PuTTY .
Use [username]@csa2.bu.edu to log on the csa2 server first.
Then type SSH [username]@cs460.bu.edu and log on to the database server.
(IV) Import Data to PostgreSQL
(a) The file name should be hubway_2011_07_through_2013_11.zip
(b) Unzip the compressed data file.
(c) There are two datasets in the zip file: hubway_stations.csv and hubway_trips.csv
(a) Read the header (first line) of data file.
(b) Design the schema of the table.(Data Types)
(c) Enter database shell
(d) Create a table in database
(e) Copy data from the data file to the table created
(f) Verify data in the table
(V) Import Stations as an Example
CREATE TABLE stations (
id integer,
terminal char(6),
station varchar(120),
municipal varchar(20),
lat decimal(8,6),
lng decimal(8,6),
status varchar(20)
);
\copy stations from '[path]/hubway_stations.csv' CSV HEADER;
[path] is the path where the file hubway_stations.csv is stored, for example ~/Downloads
(VI) Exercise: Import Trips