This guide shows how to load the Northwind dataset into PostgreSQL on macOS.
The flow is simple:
- Install PostgreSQL
- Run PostgreSQL
- Load
northwind.sql - Verify the load
This setup assumes you are running commands from the root of this repository.
Check whether PostgreSQL is already installed:
psql --versionIf it is not installed, install it with Homebrew:
brew install postgresqlConfirm the install:
psql --versionIf brew is not available, install Homebrew first and then rerun the command above.
Start PostgreSQL with Homebrew services:
brew services start postgresqlCheck that it is running:
brew services listYou can also test the connection:
psql postgresIf the connection opens, PostgreSQL is running correctly.
Exit psql with:
\qThe Northwind SQL file is expected at:
pillar2_analytical_sql/00_datasets/northwind.sqlYou can load the schema and data in two different ways:
- Method 1 runs inside the
psqlshell and usesCREATE DATABASEplus\i - Method 2 runs from your terminal, outside
psql
First open a PostgreSQL session:
psql postgresYou should now see the psql prompt.
Create the database:
CREATE DATABASE northwind;Connect to it:
\c northwindThen load the file from inside psql:
\i pillar2_analytical_sql/00_datasets/northwind.sqlThis method is interactive because you are already inside psql when you execute the file.
Do not open psql first.
Run this command directly in your terminal:
createdb northwind
psql -d northwind -f pillar2_analytical_sql/00_datasets/northwind.sqlIf the database already exists, createdb northwind may return an error. That is fine as long as the northwind database is already available.
You can confirm that with:
psql -lqtOr, if you already created the database earlier, you can run only:
psql -d northwind -f pillar2_analytical_sql/00_datasets/northwind.sqlThis method is non-interactive because the SQL file is executed directly from the shell.
If the file loads successfully, PostgreSQL will print a series of statements as they execute.
Connect to the database:
psql -d northwindRun a few quick checks:
\dt
SELECT COUNT(*) FROM customers;
SELECT COUNT(*) FROM orders;
SELECT COUNT(*) FROM order_details;What to verify:
\dtshould list the Northwind tablescustomers,orders, andorder_detailsshould all return row counts- No table-not-found errors should appear
Exit psql when you are done:
\qIf something does not work, these are the most common causes:
psql: command not found: PostgreSQL is not installed or not on your shell pathbrew: command not found: Homebrew is not installeddatabase "northwind" does not exist: create it first withcreatedb northwindnorthwind.sql: No such file or directory: check that the SQL file is saved inpillar2_analytical_sql/00_datasets- connection errors: make sure PostgreSQL is running with
brew services start postgresql