Getting Started

PostgreSQL Introduction

Learn PostgreSQL — the world's most advanced open-source relational database.

What is PostgreSQL?

PostgreSQL (often called "Postgres") is a powerful, open-source object-relational database system. It has over 35 years of active development and a strong reputation for reliability, feature robustness, and performance.

Why PostgreSQL?

  • Standards compliant: Follows SQL standards closely
  • ACID compliant: Guaranteed data consistency
  • Extensible: Custom data types, functions, operators
  • JSON support: First-class JSONB for document storage
  • Full-text search: Built-in text search capabilities
  • Geospatial: PostGIS extension for location data
  • Free and open source: No licensing costs

PostgreSQL vs MySQL

Both are excellent. PostgreSQL is preferred for:

  • Complex queries and analytics
  • JSON/document storage alongside relational data
  • Strict standards compliance
  • Complex data types and custom extensions

Getting Started

bash
# macOS
brew install postgresql@16
brew services start postgresql@16

# Connect
psql -U postgres

Example

sql
-- Connect to PostgreSQL
-- psql -U postgres -d mydb

-- Basic psql commands
-- \l          list databases
-- \c mydb     connect to database
-- \dt         list tables
-- \d users    describe table
-- \q          quit

-- Create a database
CREATE DATABASE myapp;

-- Connect to it
\c myapp

-- PostgreSQL version
SELECT version();

-- Current date and time
SELECT NOW();
SELECT CURRENT_TIMESTAMP;
SELECT CURRENT_DATE;

Want to run this code interactively?

Try in Compiler