A comprehensive guide to setting up the Contoso database with sample data for analysis and testing.
Before you begin, ensure you have:
- PostgreSQL installed on your system
- Git installed (to clone the repository)
- At least 2GB of free disk space
- 7-Zip or similar tool to extract
.7zarchives
-
Locate your PostgreSQL bin directory
- Default location:
C:\Program Files\PostgreSQL\<version>\bin
- Default location:
-
Add to PATH
- Right-click on This PC or My Computer β Properties
- Click Advanced system settings β Environment Variables
- Under System variables, find and select Path β Click Edit
- Click New and add your PostgreSQL bin path
- Click OK on all windows to save
-
Verify installation
psql --version
-
Add to PATH (if installed via Homebrew)
echo 'export PATH="/Library/PostgreSQL/18/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
-
For Postgres.app users
echo 'export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
-
Verify installation
psql --version
git clone https://github.com/muhssamy/Contoso-Analytics.git
cd Contoso-Analytics-
Download the dataset
Download the CSV files from the official release:
https://github.com/sql-bi/Contoso-Data-Generator-V2-Data/releases/download/ready-to-use-data/csv-10m.7z -
Extract the archive
Extract the
.7zfile using 7-Zip or your preferred extraction tool -
Move CSV files to the project
β οΈ Important: Copy only the.csvfiles (not the folder) into your project'scsv-10mdirectoryyour-project/ βββ csv-10m/ βββ customers.csv βββ products.csv βββ sales.csv βββ contoso_load.sql βββ ... (other CSV files)
Run the following command to create a new database:
psql -U postgres -c "CREATE DATABASE contoso;"You'll be prompted for your PostgreSQL password.
Execute the SQL script to import all CSV data into the database:
psql -U postgres -d contoso -f csv-10m/contoso_load.sqlThis process may take several minutes depending on your system specifications and the size of the dataset.
After loading, verify your setup:
-- Connect to the database
psql -U postgres -d contoso
-- Check tables
\dt
-- Check row counts
SELECT
schemaname,
tablename,
n_live_tup as row_count
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC;Your Contoso database is now ready! You can:
- Run analytical queries
- Build dashboards and reports
- Practice SQL skills
- Test ETL pipelines
Issue: psql command not found
- Solution: Ensure PostgreSQL bin directory is properly added to PATH and restart your terminal
Issue: Permission denied when creating database
- Solution: Make sure you're using a PostgreSQL superuser account (default:
postgres)
Issue: CSV files not loading
- Solution: Verify that CSV files are directly in the
csv-10mfolder, not in a subfolder
Happy Querying! π