# PostgreSQL — The Most Advanced Open Source Relational Database > PostgreSQL is the most powerful open-source relational database system. It combines SQL compliance, extensibility, and reliability with advanced features like JSONB, full-text search, vector embeddings (pgvector), and PostGIS — making it the database of choice for modern applications. ## Install Save in your project root: # PostgreSQL — The Most Advanced Open Source Relational Database ## Quick Use ```bash # Install PostgreSQL # macOS brew install postgresql@16 && brew services start postgresql@16 # Linux sudo apt install postgresql sudo systemctl start postgresql # Docker docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=secret postgres:16-alpine # Connect psql -U postgres # CREATE DATABASE myapp; # \c myapp ``` ## Introduction PostgreSQL (often called Postgres) is the most advanced and feature-rich open-source relational database. With over 35 years of active development, it has earned a reputation for reliability, data integrity, and correctness. It handles workloads ranging from single-machine applications to internet-facing systems with millions of users. With over 21,000 GitHub stars (on its mirror) and powering companies like Apple, Instagram, Spotify, Twitch, and the US Federal Government, PostgreSQL is the fastest-growing database and the default choice for new applications. Supabase, Neon, and other modern platforms are built entirely on PostgreSQL. ## What PostgreSQL Does PostgreSQL stores and manages structured data using SQL. Beyond standard relational features, it provides JSONB for document storage, full-text search, geospatial data (PostGIS), time-series, vector embeddings (pgvector for AI), and hundreds of extensions. Its MVCC (Multi-Version Concurrency Control) provides high concurrency without read locks. ## Architecture Overview ``` [Client Applications] psql, pgAdmin, application ORMs | [PostgreSQL Server] Process-per-connection model | +-------+-------+-------+ | | | | [Query [Storage [WAL] Planner] Engine] Write-Ahead Cost-based MVCC Logging for optimizer HEAP crash recovery TOAST replication | [Extensions] +------+------+------+------+ | | | | | [pgvector] [PostGIS] [pg_cron] [pg_stat] AI vectors Geospatial Scheduled Monitoring data jobs [Replication] Streaming replication Logical replication Read replicas ``` ## Self-Hosting & Configuration ```sql -- Modern PostgreSQL usage -- JSONB for document-style storage CREATE TABLE products ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, metadata JSONB DEFAULT '{}', embedding vector(1536), -- pgvector for AI created_at TIMESTAMPTZ DEFAULT NOW() ); CREATE INDEX idx_metadata ON products USING GIN (metadata); CREATE INDEX idx_embedding ON products USING ivfflat (embedding vector_cosine_ops); -- Query JSONB fields SELECT * FROM products WHERE metadata @> '{"category": "electronics"}' AND metadata->>'price' > '100'; -- Full-text search SELECT * FROM products WHERE to_tsvector('english', name || ' ' || metadata->>'description') @@ to_tsquery('english', 'wireless & headphones'); -- Vector similarity search (AI/RAG) SELECT id, name, 1 - (embedding <=> $1) AS similarity FROM products ORDER BY embedding <=> $1 LIMIT 10; -- Window functions SELECT name, SUM(amount) OVER (PARTITION BY category ORDER BY date) AS running_total, RANK() OVER (PARTITION BY category ORDER BY amount DESC) AS rank FROM sales; ``` ```ini # postgresql.conf — key tuning parameters max_connections = 200 shared_buffers = 4GB # 25% of RAM effective_cache_size = 12GB # 75% of RAM work_mem = 64MB maintenance_work_mem = 1GB wal_buffers = 64MB random_page_cost = 1.1 # for SSDs ``` ## Key Features - **ACID Compliant** — full transactional integrity with MVCC - **JSONB** — native JSON storage with indexing and query operators - **Full-Text Search** — built-in search with ranking and stemming - **pgvector** — vector similarity search for AI/RAG applications - **PostGIS** — advanced geospatial data processing - **Extensions** — hundreds of extensions for any use case - **Replication** — streaming and logical replication for HA - **Partitioning** — declarative table partitioning for large datasets ## Comparison with Similar Tools | Feature | PostgreSQL | MySQL | SQLite | MongoDB | SQL Server | |---|---|---|---|---|---| | Type | Relational | Relational | Embedded | Document | Relational | | SQL Compliance | Excellent | Good | Good | No (MQL) | Excellent | | JSON Support | JSONB (indexed) | JSON (basic) | JSON (basic) | Native (BSON) | JSON | | Extensions | 100s available | Limited | Limited | N/A | CLR | | Vector Search | pgvector | No | No | Atlas Search | No | | Geospatial | PostGIS | Basic | No | GeoJSON | Spatial | | License | PostgreSQL (BSD-like) | GPL | Public Domain | SSPL | Commercial | | Best For | General purpose, AI | Web apps, WordPress | Embedded, mobile | Documents | Enterprise | ## FAQ **Q: PostgreSQL vs MySQL — which should I choose?** A: PostgreSQL for complex queries, JSONB, geospatial, vector search, and data integrity. MySQL for simple web applications and when WordPress/MySQL ecosystem tools are needed. PostgreSQL is the better default for new projects. **Q: How do I use PostgreSQL for AI/RAG?** A: Install the pgvector extension, store embeddings as vector columns, create an IVFFlat or HNSW index, and query with cosine distance (<=>). This gives you vector search without a separate vector database. **Q: How do I scale PostgreSQL?** A: Vertical: tune shared_buffers and work_mem. Read replicas: streaming replication. Partitioning: declarative range/list partitioning. Connection pooling: PgBouncer. Horizontal: Citus extension for distributed PostgreSQL. **Q: Is PostgreSQL free for commercial use?** A: Yes, completely. The PostgreSQL License is a permissive BSD-like license with no restrictions on commercial use, modification, or distribution. ## Sources - GitHub Mirror: https://github.com/postgres/postgres - Documentation: https://www.postgresql.org/docs - Website: https://www.postgresql.org - Community-developed since 1986 - License: PostgreSQL License (BSD-like) --- Source: https://tokrepo.com/en/workflows/f913e7f4-3712-11f1-9bc6-00163e2b0d79 Author: AI Open Source