PostgreSQL Local Usage Guide
Install and connect to PostgreSQL on localhost:5432 for local development with applications like Django, Rails, and Node.
PostgreSQL (commonly referred to as Postgres) is a powerful open-source relational database widely used in stacks like Django, Rails, and NestJS TypeORM. It listens by default on localhost:5432.
Default Connection Information
| Item | Typical Local Value |
|---|---|
| Host | localhost or 127.0.0.1 |
| Port | 5432 |
| User | postgres (created during installation) |
| Password | Set during installation |
Example connection URL:
postgresql://postgres:password@localhost:5432/myappInstallation Methods
macOS (Homebrew):
brew install postgresql@16
brew services start postgresql@16Ubuntu/Debian:
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresqlDocker:
docker run -d --name pg -p 5432:5432 \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=myapp \
postgres:16Windows: Download the installer from postgresql.org or use Docker Desktop.
Common Command-Line Operations
psql -h localhost -U postgres
CREATE DATABASE myapp;
\l # List databases
\q # QuitIntegration with Frameworks
| Framework | Configuration Example |
|---|---|
| Django | DATABASES['default']['HOST'] = 'localhost', PORT = 5432 |
| Laravel | In .env, DB_CONNECTION=pgsql, DB_PORT=5432 |
| Node (pg) | new Client({ host: 'localhost', port: 5432, ... }) |
Graphical Management
- pgAdmin: Web/Desktop client
- DBeaver, TablePlus: General database tools
- Adminer / phpMyAdmin: Adminer also supports PostgreSQL
Frequently Asked Questions
Connection Refused
Ensure the service is running: brew services list or sudo systemctl status postgresql.
role “postgres” does not exist
macOS Homebrew may default the current system user as a superuser; use psql postgres or createuser to create a role.
Confusion with MySQL Port
PostgreSQL uses a fixed port of 5432, while MySQL uses 3306.
Summary
PostgreSQL is a mainstream database choice for modern full-stack projects, allowing local development connections on localhost:5432. It can be installed via Homebrew, system package managers, or Docker.