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

ItemTypical Local Value
Hostlocalhost or 127.0.0.1
Port5432
Userpostgres (created during installation)
PasswordSet during installation

Example connection URL:

postgresql://postgres:password@localhost:5432/myapp

Installation Methods

macOS (Homebrew):

brew install postgresql@16
brew services start postgresql@16

Ubuntu/Debian:

sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql

Docker:

docker run -d --name pg -p 5432:5432 \
  -e POSTGRES_PASSWORD=secret \
  -e POSTGRES_DB=myapp \
  postgres:16

Windows: 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          # Quit

Integration with Frameworks

FrameworkConfiguration Example
DjangoDATABASES['default']['HOST'] = 'localhost', PORT = 5432
LaravelIn .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.

访客计数:------ Best viewed in Netscape Navigator · 800×600 © LocalHost Run