SetUp PostgreSQL properly from scratch - including CLI, configuration, Workbench-equivalent tools, and VS Code integration.
We’ll cover:
- Install & open PostgreSQL (Command Line)
- Recommended configuration
- Create a schema using GUI (pgAdmin)
- Connect PostgreSQL to VS Code
- Professional setup recommendations
Download:
Official site: 👉 https://www.postgresql.org/download/
During installation:
- Choose default port:
5432 - Set a password for user
postgres - Install pgAdmin when prompted
- Keep locale default unless you need something specific
Postgres CLI tool is called:
psql
Open Command Prompt:
psql -U postgresEnter the password you set.
If command not found, try:
"C:\Program Files\PostgreSQL\15\bin\psql" -U postgrespsql -U postgresIf needed:
/Library/PostgreSQL/15/bin/psql -U postgresIf successful, you'll see:
postgres=#Now you're connected.
Main config file:
-
Windows:
C:\Program Files\PostgreSQL\15\data\postgresql.conf -
macOS/Linux:
/var/lib/postgresql/15/main/postgresql.conf
Open postgresql.conf and adjust:
port = 5432
max_connections = 200
shared_buffers = 1GB
effective_cache_size = 3GBPostgreSQL default is already good, but ensure your database uses:
CREATE DATABASE school
WITH ENCODING 'UTF8';Postgres uses UTF-8 by default (good choice).
After config changes → restart PostgreSQL service.
Postgres equivalent of Workbench:
Open pgAdmin:
- Connect to your server
- Right-click Databases
- Click Create → Database
- Name it
school - Save
In PostgreSQL:
- Database ≠ Schema
- A database can contain multiple schemas
- Default schema =
public
Example:
CREATE SCHEMA app_schema;Create table inside a schema:
CREATE TABLE app_schema.students (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
age INT
);Install:
Install extensions:
- SQLTools
- SQLTools PostgreSQL Driver
- Press
Ctrl + Shift + P - Select:
SQLTools: Add New Connection
- Choose PostgreSQL
- Enter:
| Setting | Value |
|---|---|
| Host | localhost |
| Port | 5432 |
| User | postgres (or dev user) |
| Password | your_password |
| Database | school |
Click Test Connection Then Save
Create:
database.sql
Example:
CREATE DATABASE school;
CREATE SCHEMA app;
CREATE TABLE app.students (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
age INT
);Right-click → Run Query
Never use postgres superuser for development.
Create a developer role:
CREATE ROLE devuser WITH LOGIN PASSWORD 'strongpassword';
CREATE DATABASE school OWNER devuser;
GRANT ALL PRIVILEGES ON DATABASE school TO devuser;Then connect VS Code using devuser.
✔ UTF-8 encoding
✔ Separate dev user
✔ Use schemas for organization
✔ Use SERIAL or GENERATED AS IDENTITY for IDs
✔ Avoid working as superuser
| MySQL | PostgreSQL |
|---|---|
| Schema = Database | Schema inside Database |
| AUTO_INCREMENT | SERIAL / IDENTITY |
| utf8mb4 needed | UTF-8 default |
| More permissive | More strict & standards-compliant |