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
2. Create a User & Database
3. 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
🧠 Using MCP DB Server to working with DB
Last updated