DEV Community

Alex Spinov
Alex Spinov

Posted on

PostgreSQL Has a Free Relational Database — JSON, Full-Text Search, and Extensions

PostgreSQL is the most advanced open-source database. Native JSON support, full-text search, LISTEN/NOTIFY, row-level security, and 100+ extensions.

Why PostgreSQL Wins

MySQL: good for simple queries. MongoDB: good for documents. PostgreSQL: does BOTH, plus things neither can.

What You Get for Free

JSON support (replace MongoDB):

CREATE TABLE products (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  metadata JSONB DEFAULT '{}'
);

INSERT INTO products (name, metadata) VALUES
  ('Keyboard', '{"color": "black", "wireless": true, "keys": 104}');

-- Query JSON fields
SELECT * FROM products WHERE metadata->>'color' = 'black';
SELECT * FROM products WHERE metadata @> '{"wireless": true}';

-- Index JSON for fast queries
CREATE INDEX idx_metadata ON products USING GIN (metadata);
Enter fullscreen mode Exit fullscreen mode

Full-text search (replace Elasticsearch for simple cases):

SELECT * FROM articles
WHERE to_tsvector('english', title || ' ' || body)
   @@ to_tsquery('english', 'database & performance');
Enter fullscreen mode Exit fullscreen mode

LISTEN/NOTIFY (real-time events):

LISTEN new_orders;
NOTIFY new_orders, '{"order_id": 123}';
Enter fullscreen mode Exit fullscreen mode

Common Table Expressions (CTEs):

WITH RECURSIVE category_tree AS (
  SELECT id, name, parent_id, 0 as depth
  FROM categories WHERE parent_id IS NULL
  UNION ALL
  SELECT c.id, c.name, c.parent_id, ct.depth + 1
  FROM categories c JOIN category_tree ct ON c.parent_id = ct.id
)
SELECT * FROM category_tree;
Enter fullscreen mode Exit fullscreen mode

Row-level security:

ALTER TABLE documents ENABLE ROW LEVEL SECURITY;
CREATE POLICY user_documents ON documents
  FOR ALL USING (owner_id = current_setting('app.user_id')::int);
Enter fullscreen mode Exit fullscreen mode

Extensions (The Killer Feature)

  • PostGIS — geographic queries (nearest restaurant, area within polygon)
  • pgvector — vector similarity search (AI embeddings)
  • pg_cron — scheduled jobs inside the database
  • TimescaleDB — time-series at scale
  • Citus — distributed PostgreSQL for horizontal scaling

Quick Start

docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:16
Enter fullscreen mode Exit fullscreen mode

If you're choosing a database for a new project — PostgreSQL is the default answer in 2026.


Need web scraping or data extraction? Check out my tools on Apify — get structured data from any website in minutes.

Custom solution? Email spinov001@gmail.com — quote in 2 hours.

Top comments (0)