Learn PostgreSQL

PostgreSQL is a powerful, open-source object-relational database system known for its standards compliance, extensibility, and reliability.

What Is PostgreSQL?

PostgreSQL (often called "Postgres") is a free, open-source relational database management system (RDBMS) that has been in active development for more than 30 years. It stores data in structured tables made of rows and columns, and it uses SQL (Structured Query Language) to create, read, update, and delete that data. Unlike purely relational databases, PostgreSQL is described as object-relational because it supports advanced features such as custom data types, table inheritance, and user-defined functions.

PostgreSQL runs on all major operating systems, including Linux, Windows, and macOS, and it powers applications ranging from small personal projects to massive systems used by companies like Instagram, Spotify, and Reddit.

Why Choose PostgreSQL?

PostgreSQL is popular because it combines the reliability of a mature relational database with modern features that many competitors lack. It strictly follows the SQL standard, supports full ACID (Atomicity, Consistency, Isolation, Durability) compliance, and includes advanced capabilities out of the box.

  • Rich data types: arrays, JSON/JSONB, XML, UUID, geometric types, and more
  • Full ACID compliance for safe, reliable transactions
  • Powerful indexing including B-tree, Hash, GiST, GIN, and BRIN indexes
  • Extensibility through custom functions, operators, and extensions like PostGIS
  • Concurrency handled through MVCC (Multi-Version Concurrency Control)
  • Strong community support and permissive open-source license

PostgreSQL vs MySQL

MySQL and PostgreSQL are both free, open-source relational databases, but they were built with different priorities. MySQL was historically optimized for speed and simplicity in read-heavy web applications, while PostgreSQL was built with strict standards compliance and advanced features as the priority. The table below highlights some key differences.

FeaturePostgreSQLMySQL
SQL Standard ComplianceVery highModerate
Data TypesExtensive (JSONB, arrays, ranges)Standard types, JSON support
Concurrency ModelMVCC with strong isolation levelsMVCC (InnoDB engine)
ExtensibilityCustom types, operators, extensionsLimited plugin support
Best Suited ForComplex queries, analytics, data integritySimple, high-speed read/write workloads
Note: Both databases are excellent choices. Many teams pick PostgreSQL when they need complex queries, strict data integrity, or advanced data types, and pick MySQL for simpler, high-throughput applications.

A First Look at SQL in PostgreSQL

Every interaction with PostgreSQL happens through SQL statements. Below are three simple examples that show how PostgreSQL handles table creation, data retrieval, and built-in functions.

Check the server version

SELECT version();

Create a simple table

CREATE TABLE employees (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    department VARCHAR(50)
);

Query all rows from a table

SELECT * FROM employees
ORDER BY name ASC;
Note: PostgreSQL is case-insensitive for unquoted identifiers and keywords, but it is best practice to write SQL keywords in uppercase (SELECT, FROM, WHERE) to keep your queries readable.

Exercise: PostgreSQL Introduction

What type of database management system is PostgreSQL?

Frequently Asked Questions

Is PostgreSQL better than MySQL?
PostgreSQL is stricter about data correctness and has richer features: JSONB, arrays, window functions and custom types. MySQL is simpler to operate and more widely available on cheap hosting. Neither is universally better.
Is PostgreSQL free?
Yes, entirely. It is open source under a permissive licence with no paid tier, no per-core pricing and no enterprise edition held back. Commercial support is sold separately by third parties.