Setup Local DB
π Goal
Install PostgreSQL locally
Connect it to VS Code
Run SQL queries and manage your database
π§ Prerequisites
VS Code installed
Basic Terminal or Command Prompt knowledge
π₯οΈ On macOS
1. Install PostgreSQL via Homebrew
brew install postgresql
brew services start postgresql2. Create a User & Database
psql postgres
-- Inside the prompt:
CREATE USER myuser WITH PASSWORD 'mypassword';
CREATE DATABASE mydb OWNER myuser;
\q3. Install VS Code PostgreSQL Extension
Open VS Code and install:
π PostgreSQL by Microsoft
Or from terminal:
4. Connect to PostgreSQL in VS Code
Open Command Palette (Cmd+Shift+P)
Run PostgreSQL: New Connection
Fill in:
Host: localhost
Port: 5432
Username: myuser
Password: mypassword
Database: mydb
π₯οΈ On Windows
1. Install PostgreSQL
Download from: https://www.postgresql.org/download/windows/
During installation:
Set password for postgres superuser
Default port: 5432
2. Add PostgreSQL to System PATH
So you can use psql in CMD/PowerShell:
Add: C:\Program Files\PostgreSQL\15\bin (adjust based on version)
3. Create a New Database
Open pgAdmin or PowerShell:
4. Install VS Code PostgreSQL Extension
Same as macOS:
Open VS Code β Extensions β Search PostgreSQL by Microsoft β Install
5. Connect from VS Code
Use Ctrl+Shift+P β PostgreSQL: New Connection
βοΈ Run SQL Files in VS Code
Create a new file: init.sql
Write SQL statements (e.g., CREATE TABLE, INSERT INTO)
Right-click in the editor β Execute Query
β
Optional: Load Your .sql File
From terminal or command prompt:
π¦ Recommended Tools
Tool
Use
pgAdmin
GUI for PostgreSQL
DBeaver
Cross-platform DB GUI
Postico (Mac)
Native PostgreSQL GUI
psql
Command-line PostgreSQL tool
π‘Create Employee DB like schema below:

πCreate employee_db
πInside the psql prompt, run:
πCreate Table (SQL schema):
πInsert DB:
π§ Using MCP DB Server to working with DB
Last updated