PostgreSQL vs MariaDB for Modern CMS
Last October, we rebuilt the database tier for a regional news portal holding 310,000 published stories, 1.9 million revisions, and 140 GB of relational and JSON block data. On a normal Tuesday morning, sixty editors sit in the admin UI with auto-save firing every thirty seconds while public traffic pushes 18,000 origin cache misses an hour. Before committing to a five-year support window, I replayed a captured production trace against PostgreSQL 16.4 and MariaDB 10.11.9 LTS on matched bare-metal boxes: 8 EPYC cores, 32 GB ECC RAM, dual NVMe drives in RAID 1, and Debian 12.
Most database shootouts run Sysbench loops that look nothing like a publishing portal. You can shave milliseconds off first-byte delivery through HTTP/3 and QUIC tuning on origin boxes, yet one unindexed metadata filter or an autovacuum storm during breaking news will still flatten your origin box. Primary key reads are a tie between PostgreSQL 16 and MariaDB 10.11. The split shows up in MVCC write amplification, JSON indexing, built-in search, and plugin SQL dialects.
MVCC Churn: Autovacuum Overhead vs InnoDB Undo Logs
Once caching is wired up right — as covered in edge caching without stale CMS edits — public traffic rarely touches the database for hot URLs. What punishes a CMS database is editorial write churn. One journalist leaving a draft open and editing copy triggers dozens of full-row UPDATE statements against a wide table packing multi-kilobyte HTML, JSON layout trees, slug locks, and timestamps.
PostgreSQL 16 implements MVCC by appending a new tuple version to the heap on every UPDATE and marking the old tuple dead once active snapshots pass it. Heap-Only Tuples (HOT) spare secondary indexes when indexed columns stay unchanged, except Postgres defaults to fillfactor = 100 and packs 8 kB pages wall to wall. With zero page slack, HOT can't place the updated tuple locally, so every auto-save spills onto a fresh page and dirties all six indexes on cms_documents.
During our four-hour morning rush replay on stock PostgreSQL 16 defaults, the cms_documents heap swelled from 4.1 GB to 5.8 GB. When autovacuum woke up at the default 20 percent threshold, background workers saturated NVMe writes and pushed p99 save latency from 14 ms to 188 ms. PostgreSQL 16 improved vacuum pacing over PG 14 and 15 via vacuum_buffer_usage_limit (256 kB default, tunable upward without evicting hot shared buffers), yet hot CMS tables still need per-table overrides on day one:
ALTER TABLE cms_documents SET (
fillfactor = 80,
autovacuum_vacuum_scale_factor = 0.02,
autovacuum_analyze_scale_factor = 0.01,
autovacuum_vacuum_cost_limit = 1000
);
Leaving 20 percent page slack lifted our HOT update ratio in pg_stat_user_tables from 9 percent to 84 percent. Heap size leveled off near 4.85 GB, dead tuples stayed under 45,000, and p99 saves dropped back to 21 ms.
MariaDB 10.11 takes the opposite path through InnoDB's clustered primary key B-tree. Updates mutate rows in place and copy the prior image into rollback segments inside the undo tablespace, leaving secondary indexes untouched when only body text changes. On the same four-hour replay, cms_documents.ibd drifted from 4.3 GB to 4.44 GB with zero vacuum pauses and no per-table tuning.
InnoDB's bill arrives when someone runs a long read snapshot on the writer. Mid-replay, I started a twelve-minute export via mariadb-dump --single-transaction against the primary node. Because InnoDB had to keep old row versions alive for that snapshot, purge threads stalled and History list length in SHOW ENGINE INNODB STATUS passed 118,000. Undo files grew 3.4 GB, and concurrent secondary index scans slowed 35 percent walking long undo chains. Postgres demands fillfactor and vacuum discipline; MariaDB demands banishing slow reports and dumps to a replica.
JSONB Indexing vs MariaDB Virtual Columns
Newsrooms won't wait on schema migrations to ship a sponsored badge or custom embed card. Modern CMS stacks pair relational core columns with a JSON blob holding layout blocks, SEO overrides, and taxonomy flags.
PostgreSQL 16 stores JSONB as decomposed binary and supports GIN indexes over nested paths. Using jsonb_path_ops halves index footprint compared to jsonb_ops while indexing arbitrary containment checks (@>). Here is the EXPLAIN (ANALYZE, BUFFERS) output on our 310,000-row corpus:
CREATE INDEX idx_docs_meta_gin
ON cms_documents USING gin (metadata jsonb_path_ops);
EXPLAIN (ANALYZE, BUFFERS)
SELECT id, slug, title FROM cms_documents
WHERE status = 'published'
AND metadata @> '{"section": "investigations", "paywall": "metered"}'
ORDER BY published_at DESC LIMIT 20;
Limit (actual time=2.141..2.148 rows=20 loops=1)
Buffers: shared hit=118
-> Sort (actual time=2.139..2.143 rows=20 loops=1)
Sort Key: published_at DESC (top-N heapsort, 31kB)
-> Bitmap Heap Scan on cms_documents (actual time=0.612..1.874 rows=1142)
Recheck Cond: (metadata @> '{"paywall":"metered","section":"investigations"}'::jsonb)
Filter: (status = 'published'::text) (Rows Removed: 78)
-> Bitmap Index Scan on idx_docs_meta_gin (actual time=0.491..0.491 rows=1220)
Execution Time: 2.208 ms
Two milliseconds with 118 buffer hits is hard to fault, though GIN isn't free. That index ate 138 MB on disk and raised CPU roughly 18 percent during heavy auto-save bursts as Postgres decomposed JSON keys and merged pending lists.
MariaDB 10.11 treats JSON as a LONGTEXT alias with a CHECK (json_valid(metadata)) constraint. There is no binary JSONB storage and no native inverted index over arbitrary nested paths. Instead, you project known filter keys into virtual generated columns and index them with composite B-trees:
ALTER TABLE cms_documents
ADD COLUMN meta_section VARCHAR(64)
AS (JSON_VALUE(metadata, '$.section')) VIRTUAL,
ADD COLUMN meta_paywall VARCHAR(32)
AS (JSON_VALUE(metadata, '$.paywall')) VIRTUAL,
ADD INDEX idx_docs_status_meta_pub
(status, meta_section, meta_paywall, published_at);
Checking that route via ANALYZE FORMAT=JSON in MariaDB 10.11 showed a backward index scan with zero sort step: access_type: "ref", r_rows: 20, and r_total_time_ms: 0.684. That B-tree took just 21 MB. For predictable routes like section fronts, author feeds, and paywall gates, MariaDB's virtual columns are leaner and faster than Postgres GIN.
MariaDB hits a wall on ad-hoc editorial queries. Ask for every story this year containing a podcast_player block inside a variable-length blocks JSON array, and MariaDB scans 310,000 LONGTEXT blobs row by row in 740 ms. PostgreSQL 16 answers the same nested array containment check via GIN in 5.8 ms.
Full-Text Search Without Another Stateful Daemon
Too many small ops teams spin up OpenSearch or Meilisearch for 300,000 articles, inheriting a sync worker and index drift bugs they didn't need. Built-in database search carries a mid-sized portal for years if you dodge its planner traps.
PostgreSQL 16 offers stored generated tsvector columns, weighted fields (A for headlines, C for body copy), Snowball stemming, and unaccent for international names:
ALTER TABLE cms_documents
ADD COLUMN search_vec tsvector
GENERATED ALWAYS AS (
tsvector_concat(
setweight(to_tsvector('english', coalesce(title, '')), 'A'),
setweight(to_tsvector('english', coalesce(body_plain, '')), 'C')
)
) STORED;
CREATE INDEX idx_docs_search_gin ON cms_documents USING gin (search_vec);
One EXPLAIN ANALYZE trap bites almost everyone: pairing a GIN search match with ORDER BY published_at DESC LIMIT 20 on a broad term like "election." Since GIN doesn't store timestamps in order, Postgres pulls every matching row — 18,000 tuples in our replay — before sorting, jumping runtime from 4.2 ms on narrow phrases to 145 ms. Adding a btree_gin composite index on (published_at, search_vec) or defaulting searches to the past 24 months kept p95 latency under 18 ms.
MariaDB 10.11's InnoDB FULLTEXT index is snappy on exact boolean tokens (4.6 ms in our corpus), yet three limits frustrate newsrooms:
- Default
innodb_ft_min_token_sizeis 3, silently dropping searches for "AI", "EU", "UK", or "Go". Fixing it requires editingmy.cnf, restarting MariaDB, and rebuilding every full-text index. - InnoDB ships without stemming dictionaries. Searching "migrating" misses "migration" unless you bolt on Mroonga or offload search anyway.
- Boolean relevance scoring lacks clean per-column weighting like
setweightandts_rank_cd.
As sites grow into enterprise CMS scalability requirements — multi-lingual stemming, weighted headlines, and typo tolerance via pg_trgm — PostgreSQL buys you years before standing up a dedicated search cluster.
Plugin Ecosystems, SQL Dialects, and Rollout Safety
Benchmarks mean nothing if your plugin stack breaks on launch day. WordPress still powers a huge slice of self-hosted publishing, and despite shims like pg4wp, running WordPress on PostgreSQL in production is reckless. The moment marketing installs a membership or SEO plugin issuing raw INSERT IGNORE, ON DUPLICATE KEY UPDATE, SQL_CALC_FOUND_ROWS, or backtick-quoted SQL via $wpdb, shims fail silently. Ghost draws an even harder line, supporting only MySQL-compatible engines. If your stack is WordPress, Ghost, or legacy PHP code steeped in MySQLisms, run MariaDB 10.11 and sleep at night.
On Directus, Payload CMS, Strapi, Wagtail, Drupal 10, and custom Go or TypeScript portals, PostgreSQL 16 is a first-class target. You also get transactional DDL. Wrapping a plugin upgrade in BEGIN ... COMMIT means a broken migration rolls back cleanly instead of stranding half-applied columns. MariaDB implicitly commits around every ALTER TABLE, making our workflow for blue-green CMS deployments far calmer on Postgres during automated extension upgrades.
Connection Pooling Overhead
MariaDB 10.11 includes a native thread pool that absorbs 400 bursty PHP-FPM workers effortlessly. PostgreSQL 16 still spawns a process per connection; pointing 400 PHP workers straight at Postgres without PgBouncer in transaction pooling mode will thrash RAM during spikes. Bake PgBouncer into your deployment role from day one.
How I Pick Between Them on a New Origin Box
After running both engines under live editorial replay, my call comes down to four checks:
- Pick MariaDB 10.11 LTS if WordPress, Ghost, or MySQL-native plugins drive your site. Don't fight an ecosystem with SQL shims.
- Pick MariaDB 10.11 LTS if routes filter fixed metadata keys where virtual-column B-trees win, and you'd rather skip PgBouncer and per-table vacuum tuning.
- Pick PostgreSQL 16 if you run Payload, Directus, Wagtail, Drupal, or a custom CMS needing ad-hoc JSONB block queries and built-in stemmed search without OpenSearch.
- Pick PostgreSQL 16 if transactional DDL and partial indexes (
WHERE status = 'published') guard your release pipeline — just budget an hour for PgBouncer,fillfactor = 80, and tighter autovacuum scale factors.
Neither engine rescues a theme firing forty uncached N+1 queries per page, and both push 20,000 requests a minute behind a sane cache. Pick the engine whose operational quirks match the stack your editors live in.
Comments
Post a Comment