EECS 484 Projects | postgres-local-setup
Local PostgreSQL Setup Guide
This guide covers installing, starting, and using PostgreSQL on your own computer.
1. Install PostgreSQL
Download a current supported release from the official PostgreSQL downloads page. On Windows, use the official page's EDB installer. The Windows installer includes the PostgreSQL server, command-line tools, pgAdmin, and StackBuilder.
During installation:
- Install the PostgreSQL Server and Command Line Tools.
- Set a password for the initial administrative role and store it securely.
- Keep the default port
5432unless another local service already uses it. - Remember the installation directory if the installer does not add
psqlandcreatedbto yourPATH.
On macOS or Linux, use the package manager or installer documented for your operating system.
2. Verify the client and server
Open a new terminal after installation and check that the client is available:
psql --version
createdb --version
Then connect to the default administrative database. Replace postgres with the role name you created if necessary:
psql -U postgres -h localhost -p 5432 -d postgres
Inside psql, run:
SELECT version();
\conninfo
\q
If the client cannot connect, the PostgreSQL service is probably stopped, the port is different, or the role/password is incorrect.
3. Create a dedicated project database
Use a separate database for each project. Do not use a production database or a database containing unrelated personal data.
createdb -U postgres -h localhost -p 5432 eecs484_p4
Connect to it:
psql -U postgres -h localhost -p 5432 -d eecs484_p4
If your local role is your operating-system username, you can omit -U postgres. PostgreSQL's createdb utility creates a database owned by the role used for the connection.
4. Load the Dell DVD Store dataset
Download the Dell DVD Store data ZIP from the project page and extract it on your computer. The archive contains a dvd_store_data directory with the data files and PostgreSQL scripts.
Open a terminal in the extracted dvd_store_data directory. This working directory matters because the scripts use relative paths such as ./data/....
On Windows PowerShell, for example:
Expand-Archive .\dvd_store_data.zip -DestinationPath .
Set-Location .\dvd_store_data
On macOS or Linux:
unzip dvd_store_data.zip
cd dvd_store_data
Load the tables and data into the local project database:
psql -v ON_ERROR_STOP=1 -U postgres -h localhost -p 5432 -d eecs484_p4 -f setup_db.sql
The setup script recreates the DVD Store tables, loads the CSV files, and disables bitmap scans for the exercises. After loading, refresh the planner statistics:
psql -v ON_ERROR_STOP=1 -U postgres -h localhost -p 5432 -d eecs484_p4 -c "ANALYZE;"
To inspect the loaded tables and indexes, connect to the database and run:
psql -U postgres -h localhost -p 5432 -d eecs484_p4
\dt
\d+ customers
\d+ orders
\q
Use the database created by setup_db.sql as your baseline. Create additional indexes only when an exercise instructs you to do so.
5. Run SQL files
From the directory containing a project SQL file, run it with -f:
psql -v ON_ERROR_STOP=1 -U postgres -h localhost -p 5432 -d eecs484_p4 -f setup.sql
Use -v ON_ERROR_STOP=1 so that a script stops at its first error. To run a query file and save the output for your analysis:
psql -v ON_ERROR_STOP=1 -U postgres -h localhost -p 5432 -d eecs484_p4 -f queries.sql -o query-output.txt
Inside psql, useful commands include:
\dt
\d+ table_name
\di+
\timing on
\x auto
6. Capture query plans
To inspect a read-only query plan, run:
EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
SELECT ...;
EXPLAIN ANALYZE executes the statement. Use it only for read-only queries unless the statement is deliberately wrapped in a transaction that you roll back. For writes, first inspect the plan with plain EXPLAIN, or use a transaction:
BEGIN;
EXPLAIN (ANALYZE, BUFFERS) UPDATE ...;
ROLLBACK;
For repeatable comparisons, record the query, index definitions, PostgreSQL version, table sizes, and whether the database was freshly loaded. Planner choices can change with statistics, cache state, data size, and hardware.
7. Refresh statistics
After loading or substantially changing data, refresh planner statistics:
ANALYZE;
During routine setup, avoid VACUUM FULL and global server-setting changes. These operations can change storage layout and affect other databases on the same computer.
Common problems
psql or createdb is not recognized
Open a new terminal first. If the command is still unavailable, add the PostgreSQL bin directory to your user PATH, or invoke the executable by its full path. On Windows, the directory is commonly under C:\Program Files\PostgreSQL\<major>\bin.
Connection refused
Confirm that the PostgreSQL service is running, that the port is correct, and that you are using -h localhost. On Windows, check the PostgreSQL service in Services. On macOS or Linux, use the service controls provided by your installation method.
Password authentication failed
Check the role name and password. Keep the password out of shell commands and SQL files; let psql prompt for it.
Port 5432 is already in use
Either stop the unrelated local service or choose another port during installation and use that port consistently with -p. Do not disable a service you do not recognize.
8. Remove the project database
When you no longer need the database, remove only the project database:
dropdb -U postgres -h localhost -p 5432 eecs484_p4
Never run dropdb against a database unless you have verified its exact name and no longer need its contents.