localhost:5432
Port 5432 is PostgreSQL. If MySQL is everywhere, Postgres is the choice for developers who want more features — JSON support, full-text search, and better standards compliance. Rails, Django, and most startups run on Postgres.
Connect to PostgreSQL
psql Command Line
# Connect as postgres user
psql -U postgres
# Connect to specific database
psql -h localhost -p 5432 -U myuser -d mydb
# List databases
\l
# List tables
\dt
Connection Strings
# Standard format
postgresql://user:password@localhost:5432/dbname
# Node.js (pg)
const pool = new Pool({
host: 'localhost',
port: 5432,
user: 'postgres',
password: 'password',
database: 'mydb'
});
# Python (psycopg2)
conn = psycopg2.connect(
host='localhost',
port=5432,
user='postgres',
password='password',
dbname='mydb'
)
# Django settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': 'localhost',
'PORT': '5432',
'NAME': 'mydb',
'USER': 'postgres',
'PASSWORD': 'password',
}
}
Check if PostgreSQL is Running
# Linux
sudo systemctl status postgresql
# Mac (Homebrew)
brew services list | grep postgresql
# Check port
pg_isready -h localhost -p 5432
Common Errors
| Error | Solution |
| Connection refused | PostgreSQL not running or wrong port |
| FATAL: role does not exist | Create user: createuser myuser |
| FATAL: database does not exist | Create db: createdb mydb |
| Peer authentication failed | Edit pg_hba.conf, change to md5 auth |
PostgreSQL vs MySQL
| Feature | PostgreSQL (5432) | MySQL (3306) |
| JSON support | Native JSONB | Basic JSON |
| Full-text search | Built-in | Requires config |
| Standards | SQL compliant | Some deviations |
| Popular with | Rails, Django | WordPress, PHP |
Related Ports
| Port | Database |
| 3306 | MySQL |
| 27017 | MongoDB |
| 6379 | Redis |