---
title: "Closing the gap: PostgreSQL performance in Shopware"
description: "Shopware on PostgreSQL went from 3.6x to 1.13–1.30x of MariaDB. What closed the gap, what did not matter, why writes stay slow and how it was measured."
url: "https://brocksi.net/blog/closing-the-gap-postgresql-performance-in-shopware/"
author: "Björn Meyer"
published: "2026-12-23"
lang: "en"
categories: ["Shopware 6", "Performance", "PHP"]
---

# Closing the gap: PostgreSQL performance in Shopware

Running is not the same as running fast. [Part 1](https://brocksi.net/blog/shopware-on-postgresql-it-runs-should-it/) showed that the Shopware core works on MySQL, MariaDB, PostgreSQL and SQLite from the same code, and [part 2](https://brocksi.net/blog/what-mysql-quietly-does-for-you/) covered everything MySQL forgives without telling you. This part is about speed.

The first time I loaded a realistic catalog into both databases, a product detail page took 290 ms on PostgreSQL and 84 ms on MariaDB. The storefront was 2.6 to 3.6 times slower across the board. That is the kind of number that ends a discussion before it starts.

By the end it was 1.13x to 1.30x. Most of the gap was not “PostgreSQL is slow”. It was a handful of very specific things, and almost none of them were the things I suspected first. If you tune Shopware, or any PHP application on PostgreSQL, this part is for you. If you only care about MySQL, the sections on writes and on why I stopped trusting single benchmark runs still apply to you.

> **Note:** This is research on a proof-of-concept branch. Nothing here is a supported Shopware feature.

## The starting point

The test data is a real-sized catalog, the same on every database: 542 products with 1,298 variants, 503 categories and 8 sales channels. Both databases run in containers with the same limits (4 CPUs, 4 GiB) and the same memory settings, PostgreSQL 18.7 against MariaDB 10.11.16. Every PHP request opens a new database connection, which is what Shopware does by default. The HTTP cache is off, so every request really hits the database.

| Storefront page | MariaDB | PostgreSQL | Ratio |
| --- | --- | --- | --- |
| Home | 97 ms | 254 ms | 2.60x |
| Listing | 61 ms | 200 ms | 3.29x |
| Search | 73 ms | 259 ms | 3.56x |
| Product detail | 84 ms | 290 ms | 3.45x |

My first guess was that my own code was the problem. At that point every statement still went through the translator from part 2, and every id through a conversion layer. Both sound expensive.

## What did not matter

So I measured them first, and they were not the problem.

**The translator** and **the id conversion** together never cost more than 12 % of a request. Removing both would not have closed a gap of 3x.

Then I went through the usual suspects for slow PostgreSQL ports, and each one was a dead end:

- **JSON columns stored as text.** All 220 JSON columns were already jsonb.
- **Missing indexes.** Of 418 foreign keys, not one was missing an index on its column.
- **Slow compatibility functions.** The MySQL imitations the storefront uses from mysql-compat.sql are plain SQL functions that PostgreSQL inlines into the query.
- **More statements.** PostgreSQL ran one statement more per request than MariaDB, not dozens.

That list taught me more than the fixes did. When something is three times slower, you expect one big obvious cause. There was none. The real causes were small, specific and hidden in places a profiler only shows if you look per statement.

## What did matter

### Accent-insensitive search, row by row

In part 2 I wrote about the ci collation: comparisons that ignore case and accents, like MySQL does. On PostgreSQL that is a nondeterministic ICU collation, and it has a price. A LIKE on such a column cannot use an index, and every row is compared through ICU.

The worst case was the main navigation. To load the category tree below the root, Shopware filters categories with category.path LIKE ’%|id|%’. On PostgreSQL that was a sequential scan over about 500 categories, every row through ICU: about 25 ms per call, twice per request. With a plain byte-wise collation (ucs\_basic) the same query takes about 0.3 ms.

A category path contains ids and separators, nothing with accents. So switching that one column to COLLATE ucs\_basic changed nothing for users and removed 50 to 60 ms from every storefront page.

### One `lower()` per word and row

The search does something similar on purpose. To stay case-insensitive without the slow collation, the PostgreSQL dialect compares lower(keyword) with a lowercased search term. That is fast, until the query has about 96 OR branches, because the keyword lookup turns every search word into many typo-tolerant LIKE patterns against the search dictionary. PostgreSQL computed lower() again in every branch, for every dictionary row.

The fix is an old PostgreSQL trick: lowercase each row once in a subquery and add OFFSET 0, which stops the planner from merging the subquery back into the outer query. The dialect got a small method for it, SqlDialect::subqueryFence(), which returns an empty string on the other databases. The statement went from 60 to 90 ms to about 7 ms.

Those two fixes alone cut PostgreSQL’s page times by 39 to 49 %, and the ratio fell from about 3x to below 2x.

### A new connection for every request

PHP usually opens a fresh database connection per request. For MariaDB that is cheap. For PostgreSQL it means a new server process, and that process starts cold: ICU loads its collator on the first ci comparison, and the caches for the schema and query plans start empty. All in all, a new process cost about 27 to 29 ms extra per request, plus connecting, before the request did anything useful. Shopware already supports persistent connections with DATABASE\_PERSISTENT\_CONNECTION=1. Turned on, storefront pages on PostgreSQL got 1.13x to 1.18x faster. MariaDB and MySQL gained nothing measurable from it.

That was the moment I understood that comparing databases with default settings compares defaults, not databases.

### Planning the same query again and again

PostgreSQL plans every statement before running it, and DAL statements are wide. The product detail query has 19 joins. Planning it took about 5 ms when warm and up to 48 ms cold.

Normally a database keeps plans for prepared statements. But the PostgreSQL driver that Doctrine DBAL uses turns server-side prepares off (PGSQL\_ATTR\_DISABLE\_PREPARES), so every statement was planned again: between 64 and 85 plans per request.

So I built a small plan cache in a DBAL middleware: on a persistent connection it sends PREPARE name AS … once per SQL text and EXECUTE name(…) afterwards. It is switched on with DATABASE\_PLAN\_CACHE=1. Planning time on the home page went from 24.9 ms to 6.1 ms per request. Forcing PostgreSQL to use generic plans, one cached plan reused whatever the parameter values are, would cut even more, but I left that off: a generic plan gave the same results on my data, and nobody has shown it is fast on yours.

### An index the search could not use

The search looks up keywords with a leading wildcard (LIKE ‘%shirt%’). A normal btree index cannot help with that, so every lookup scanned the whole keyword table, about seven times per request.

PostgreSQL has an answer MySQL does not have: a trigram index. The pg\_trgm extension splits text into three-letter pieces, and a GIN index over them serves wildcard searches:

```sql
CREATE INDEX "product_search_keyword.idx.pg_keyword_trgm" ON product_search_keyword
USING gin ((lower(keyword) COLLATE ucs_basic) gin_trgm_ops);
```

One lookup went from 8.4 ms to 0.1 to 0.2 ms. Very short search terms still scan, because they have too few trigrams.

## How the gap closed

The project ran in waves, rounds of parallel work that each ended with measured results (part 1 explains the setup). Waves 1 to 3 got Shopware running, so the benchmark on the catalog data starts in wave 4. Waves 8 and 9 were the ORM and read store experiments from part 4. This is the storefront ratio per wave, PostgreSQL time divided by MariaDB time, with the best setup available at that point: persistent connections from the start, plus the plan cache from wave 6 on.

| Wave | Main change | Home | Listing | Search | Detail |
| --- | --- | --- | --- | --- | --- |
| 4 | Starting point, persistent connections | 2.23 | 2.72 | 2.92 | 3.06 |
| 5 | ucs\_basic path, lower() fence | 1.35 | 1.38 | 1.44 | 1.64 |
| 6 | Plan cache | 1.19 | 1.12 | 1.63 | 1.61 |
| 7 | Trigram index, translator cache | 1.13 | 1.14 | 1.46 | 1.44 |
| 10 | Clean paired run, no background load | 1.16 | 1.13 | 1.30 | 1.26 |

Waves 4 to 7 were measured without a paired control, while other work ran on the same machine. So small moves between waves, like search going up in wave 6 or home in wave 10, say little on their own. More on that below.

With a new connection per request, PostgreSQL still ends at 1.63x to 1.85x on home, listing and detail. If you run Shopware on PostgreSQL, persistent connections are not optional.

What is left is close to the engine itself. In a plain read benchmark without Shopware (sysbench, three runs, noisy), PostgreSQL was about 1.25x behind MariaDB. The storefront at 1.13x to 1.30x is in that range. I don’t think there is another 2x hidden in the read path. There are a few percent, and they get expensive.

## Writes stay the weak spot

Reads got close. Writes did not.

The write benchmark syncs 50 products through the admin API, the way an ERP import does. One such request ran 475 UPDATE product statements, on both databases. Most of them do not come from the write itself but from the indexers that run after it: the category tree, variant display groups, the cheapest price, the rating average. One statement per product and per updater.

PostgreSQL needed 188 ms for those updates, MariaDB 117 ms. Part of the reason is how PostgreSQL updates rows: it writes a new version of the row, and with 18 indexes on product almost every update also had to touch the indexes. Leaving free space in the table pages (fillfactor=70), so PostgreSQL can put the new row version on the same page without touching the indexes, helped with that, but barely changed the timing. The real fix is fewer statements, and that helps MySQL just as much: [batch the single-row updates of the product indexer](https://github.com/shopware/shopware/issues/23301) is filed and still open. At the end, a 50-product sync took 1.8x as long on PostgreSQL.

### Parallel writes and deadlocks

It gets worse when several imports run at once. With four parallel sync requests, PostgreSQL first managed a fraction of MariaDB’s throughput. The cause was deadlocks: two requests lock the same product rows in a different order and wait for each other.

Both databases have deadlocks here, 1 to 5 per run on MariaDB, 7 to 22 on PostgreSQL. The difference is what happens next. InnoDB detects a cycle immediately. PostgreSQL only starts looking after deadlock\_timeout, one second by default. So every deadlock stalls at least two connections for a full second. Shopware retries the transaction, so the request still answers with HTTP 200. The error never shows, only the latency. Concurrent syncs that overlap on the same products made deadlocks much more likely: with deduplicated or disjoint product lists, there were none.

Setting deadlock\_timeout to 100 ms gave 3.7 times the throughput, but it is a server setting that an application cannot change. The proper fix is to always lock rows in the same order. The PostgreSQL branch now locks the products of a batch first, sorted by id (SELECT … ORDER BY id FOR UPDATE). Deadlocks went from 31 to 0, and the throughput nearly doubled. [One fixed row order for the indexer updaters](https://github.com/shopware/shopware/issues/23302) is filed for the core, too. If you ran into product deadlocks on MySQL before, my older post on [deadlock-free product indexing](https://brocksi.net/blog/deadlock-free-product-indexing/) shows a workaround on the messenger side.

Even without deadlocks, parallel writes on PostgreSQL ended at 0.34x of MariaDB’s throughput: 3.7 against 10.9 requests per second. The lock itself costs about 40 ms, and requests now wait for each other instead of failing. If your shop lives on big parallel imports, this is the number I would look at first, not the storefront.

## Why I stopped trusting single benchmark runs

All of this ran on one machine: my Apple M4 Pro, with the databases in a Podman VM. For most of the project, other work ran on the same machine at the same time.

Early on I had a rule of thumb: differences below about 10 % are noise. Then I caught myself using numbers that were worse than noise.

**A ratio that compared different results.** Admin search on PostgreSQL looked 1.86x slower. It turned out the two databases returned different products on page 1: 834 of 1,916 product translation rows have no name (NULL), and MariaDB sorts NULL first while PostgreSQL sorts it last. That is the NULL order trap from part 2. The benchmark compared two different pages, not two databases.

**An improvement that was not mine.** In wave 7, with persistent connections, the search and detail ratios dropped from about 1.7x to 1.4x. I almost wrote it down as progress. PostgreSQL had stayed within its normal spread. MariaDB had gotten slower in that run.

**A benchmark that slowed itself down.** When the write benchmark ran between search requests, PostgreSQL search went from 93 ms in the first round to 244 ms in the tenth. The updates left dead rows in the keyword table faster than autovacuum cleaned them up. Measured clean, the ratio was 1.30x. Measured mixed, it was 2.44x.

So for the final wave I measured the measurement itself:

1. **Noise first.** Run the same thing twice and compare it with itself. On this machine, a full storefront request varies by about ±10 to 12 % with nothing changed.
2. **Pairs, alternating.** Ten rounds, A then B, then B then A, so warm-up and background load hit both sides equally.
3. **Confidence intervals.** A 95 % bootstrap interval over the ten pairs. A difference only counts if the interval does not include 1.0.
4. **Same data, clean state.** VACUUM (FULL, ANALYZE) on PostgreSQL and ANALYZE TABLE on MariaDB before each block, and the other workloads on the machine stopped.

Every headline number in this series comes from that block, and most earlier claims held. Some got smaller: the detail page went from 1.40–1.61x to 1.26x. The script and all results are in the research repository, see [the timing reliability doc](https://github.com/BrocksiNet/shopware-db-independent/blob/main/docs/51-timing-reliability.md).

What that means for you: the ratios are solid for this machine. The absolute milliseconds are not, and nobody has repeated this on Linux servers or cloud hardware yet. Treat the numbers as directions, not as a budget.

## Close to production

A benchmark with one database and no cache is not a shop. So in the last wave I built a setup that looks more like one: a PostgreSQL primary with a streaming replica for reads, TLS between PHP and the database, OpenSearch for search, background workers and the HTTP cache on. Everything ran end to end, including an order and the workers.

It ran after six small fixes, from replica and TLS support in the connection setup to a few SQL details. Then I stopped the workers, so they could not skew the numbers, and timed a full customer journey, from home page through search, cart and registration to the order:

- **Cached pages** were as fast as on MariaDB, within 5 %. With the HTTP cache on, the database is not involved.
- **Search** was within 3 %, because OpenSearch does the work.
- **Cart and checkout** were 1.1x to 1.37x slower, with the order step as the slowest.
- **The whole journey** took 1.18x as long.

Then PgBouncer, the connection pooler most PostgreSQL setups run. In transaction mode it hands each transaction to any server connection, so my plan cache breaks: a statement prepared with SQL PREPARE on one connection is missing on the next (prepared statement “w10e\_plan” does not exist). PgBouncer 1.21 and newer can pool protocol-level prepared statements (max\_prepared\_statements), and that worked in my test, but not SQL-level ones, and the PHP driver turns the protocol-level ones off. Without the plan cache and with a new connection to PgBouncer per request, the journey took about 1.55x as long as on MariaDB. A pooler is great for many connections. For Shopware’s per-request latency it costs.

## TL;DR

- PostgreSQL started 2.6x to 3.6x slower than MariaDB on a realistic catalog. It ended at 1.13x to 1.30x with persistent connections and a plan cache.
- The translator, id conversion, JSON types and indexes were not the problem.
- The big causes: accent-insensitive LIKE through ICU, lower() evaluated per OR branch, a cold server process per request, planning wide DAL statements every time, and a missing trigram index for search.
- Writes stay slow: 1.8x for a bulk sync and 0.34x the throughput for parallel syncs. 475 single-row updates per sync and deadlock handling are the reasons, and fixing the first helps MySQL too.
- Measure the noise before you trust a number. Paired runs and confidence intervals caught several wrong claims.
- In a production-like setup, cached pages are as fast as MariaDB and a full customer journey takes 1.18x as long. PgBouncer adds more.

Next up in part 4: the biggest speed win of the project, which had nothing to do with which database you run.
