PostgreSQL Overview
PostgreSQL originated from UC Berkeley's POSTGRES project in 1986. It is a powerful open-source relational database management system known for its stability, flexibility, rich feature set, and strong community support.
Key characteristics:
- Open source and free
- Highly extensible
- Powerful SQL capabilities
- Data integrity
- Security
- Multi-Version Concurrency Control (MVCC)
- Client/Server architecture: Clients connect over the network to the server; each connection is handled by an independent process, providing better isolation.
- MVCC: Maintains multiple versions of data so reads and writes do not block each other; each transaction sees a consistent data snapshot, avoiding read/write conflicts.
- Query processing: Parse → Optimize → Execute. The query processor parses SQL, the optimizer selects the best execution plan, and the execution engine runs the query and returns results.
- Storage engine: A unified storage engine supporting transactions, foreign keys, and row-level locking, plus advanced features like tablespaces and partitioned tables.
- Extensibility: Custom data types, operators, functions, and index methods; functionality can be enhanced via extension plugins.
- Strict ACID compliance: Guarantees atomicity, consistency, isolation, and durability.
- Rich data types: JSON/JSONB, arrays, range types, geometric types, and more.
- Community-driven: An active developer community with continuous innovation under the PostgreSQL License.
- Reliability and stability: Years of development and testing, strong community support, widely used in mission-critical systems.
- Advanced features: Complex queries, foreign keys, triggers, views, window functions, and more.
- Extensibility: A rich plugin ecosystem including PostGIS, TimescaleDB, and Citus.
- Community ecosystem: Active open-source community with abundant documentation and resources.
PostgreSQL is a full-stack database that can serve many roles: OLTP, OLAP, stream processing, geospatial data, time-series data, and more.
Architecture and Principles
Design Philosophy
PostgreSQL vs MySQL Comparison
| Feature | PostgreSQL | MySQL | |---|---|---| | Architecture | Multi-process; each connection is an independent process | Multi-threaded; many threads within a single process | | Data types | Rich: JSON/JSONB, arrays, range types, geometric types | Basic: integers, floats, strings; limited advanced types | | JSON support | Strong: JSONB binary storage with GIN indexes, efficient queries | Basic JSON type with limited features and weaker indexing | | Geospatial | PostGIS extension with 300+ spatial functions | Basic spatial types with 20+ spatial functions | | Transactions | Strict ACID, default REPEATABLE READ | InnoDB ACID, default REPEATABLE READ but implemented differently | | Use cases | Complex analytics, high consistency, geospatial apps | Simple queries, high concurrency, web applications |