Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ redirects:
guides/plugins/plugins/api/customer-specific-pricing.html: guides/plugins/plugins/integrations/commercial/customer-specific-pricing.html
guides/plugins/plugins/api/multi-inventory.html: guides/plugins/plugins/integrations/commercial/multi-inventory.html
plugins/plugins/api/index.html: concepts/api/index.html
guides/hosting/infrastructure/database-cluster.html: guides/hosting/infrastructure/database.html
resources/guidelines/code/cart-process.html: guides/plugins/plugins/architecture/cart-process.html
resources/guidelines/code/context-rules-rule-systems.html: guides/plugins/plugins/architecture/context-rules-rule-systems.html
resources/guidelines/code/dependency-injection-dependency-handling.html: guides/plugins/plugins/architecture/dependency-injection-dependency-handling.html
Expand All @@ -179,4 +180,4 @@ redirects:
resources/references/core-reference/dal-reference/index.html: guides/development/troubleshooting/dal-reference/index.html
resources/references/core-reference/flow-reference.html: guides/development/troubleshooting/flow-reference.html
resources/references/core-reference/rules-reference.html: guides/development/troubleshooting/rules-reference.html
guides/hosting/installation-updates/extension-managment.html: guides/hosting/installation-updates/extension-management.html
guides/hosting/installation-updates/extension-managment.html: guides/hosting/installation-updates/extension-management.html
Empty file modified .github/scripts/check-redirects.sh
100644 → 100755
Empty file.
56 changes: 0 additions & 56 deletions guides/hosting/infrastructure/database-cluster.md

This file was deleted.

76 changes: 76 additions & 0 deletions guides/hosting/infrastructure/database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
nav:
title: Database
Comment thread
mitelg marked this conversation as resolved.
position: 20

---

# Database

This guide explains how to operate Shopware with a reliable database setup.
It covers cluster-based scaling for read traffic and connection handling for long-running PHP worker environments.

## Cluster Setup

::: info
We recommend the usage of [ProxySQL](https://proxysql.com/) as a proxy for the database cluster instead of configuring the application to connect to different database servers directly.
ProxySQL allows you to manage the database cluster more efficiently and provides additional features like query caching, connection pooling, load balancing, and failover.
:::

To scale Shopware even further, we recommend using a database cluster.
A database cluster consists of multiple read-only servers managed by a single primary instance.

Shopware already splits read and write SQL queries by default.
When a write [`INSERT`/`UPDATE`/`DELETE`/...](https://github.com/shopware/shopware/blob/v6.4.11.1/src/Core/Profiling/Doctrine/DebugStack.php#L48) query is executed, the query is delegated to the primary server, and the current connection uses only the primary node for subsequent calls.

Check warning on line 24 in guides/hosting/infrastructure/database.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/hosting/infrastructure/database.md#L24

The verb ‘write’ does not usually follow articles like ‘a’. Check that ‘write’ is spelled correctly; using ‘write’ as a noun may be non-standard. (A_INFINITIVE[1]) Suggestions: `a White`, `a trite`, `a white`, `a writ` URL: https://languagetool.org/insights/post/verbs-as-nouns/ Rule: https://community.languagetool.org/rule/show/A_INFINITIVE?lang=en-US&subId=1 Category: GRAMMAR
Raw output
guides/hosting/infrastructure/database.md:24:5: The verb ‘write’ does not usually follow articles like ‘a’. Check that ‘write’ is spelled correctly; using ‘write’ as a noun may be non-standard. (A_INFINITIVE[1])
 Suggestions: `a White`, `a trite`, `a white`, `a writ`
 URL: https://languagetool.org/insights/post/verbs-as-nouns/ 
 Rule: https://community.languagetool.org/rule/show/A_INFINITIVE?lang=en-US&subId=1
 Category: GRAMMAR
This is ensured by the `executeStatement` method in the [DebugStack decoration](https://github.com/shopware/shopware/blob/v6.4.11.1/src/Core/Profiling/Doctrine/DebugStack.php#L48).
That way, Shopware can ensure read-write consistency for records within the same request.
However, it doesn't take into account that read-only child nodes might not be in sync with the primary node.
This is left to the database replication process.

### Preparing Shopware

We suggest following the steps below to make the splitting the most effective.

#### Using the optimal MySQL configuration

By default, Shopware does not set specific MySQL configurations that make sure the database is optimized for Shopware usage.
These variables are set in cluster mode only on the read-only server.
To make sure that Shopware works flawlessly, these configurations must be configured directly on the MySQL server so these variables are set on any server.

Check warning on line 38 in guides/hosting/infrastructure/database.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/hosting/infrastructure/database.md#L38

Use a comma before ‘so’ if it connects two independent clauses (unless they are closely connected and short). (COMMA_COMPOUND_SENTENCE_2[1]) Suggestions: `, so` URL: https://languagetool.org/insights/post/comma-before-and/ Rule: https://community.languagetool.org/rule/show/COMMA_COMPOUND_SENTENCE_2?lang=en-US&subId=1 Category: PUNCTUATION
Raw output
guides/hosting/infrastructure/database.md:38:113: Use a comma before ‘so’ if it connects two independent clauses (unless they are closely connected and short). (COMMA_COMPOUND_SENTENCE_2[1])
 Suggestions: `, so`
 URL: https://languagetool.org/insights/post/comma-before-and/ 
 Rule: https://community.languagetool.org/rule/show/COMMA_COMPOUND_SENTENCE_2?lang=en-US&subId=1
 Category: PUNCTUATION

The following options should be set:

- Make sure that `group_concat_max_len` is by default higher or equal to `320000`
- Make sure that `sql_mode` doesn't contain `ONLY_FULL_GROUP_BY`

After this change, you can set also `SQL_SET_DEFAULT_SESSION_VARIABLES=0` in the `.env` file so Shopware does not check for those variables at runtime.

Check warning on line 45 in guides/hosting/infrastructure/database.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/hosting/infrastructure/database.md#L45

Use a comma before ‘so’ if it connects two independent clauses (unless they are closely connected and short). (COMMA_COMPOUND_SENTENCE_2[3]) Suggestions: `, so` URL: https://languagetool.org/insights/post/types-of-sentences/#compound-sentence Rule: https://community.languagetool.org/rule/show/COMMA_COMPOUND_SENTENCE_2?lang=en-US&subId=3 Category: PUNCTUATION
Raw output
guides/hosting/infrastructure/database.md:45:92: Use a comma before ‘so’ if it connects two independent clauses (unless they are closely connected and short). (COMMA_COMPOUND_SENTENCE_2[3])
 Suggestions: `, so`
 URL: https://languagetool.org/insights/post/types-of-sentences/#compound-sentence 
 Rule: https://community.languagetool.org/rule/show/COMMA_COMPOUND_SENTENCE_2?lang=en-US&subId=3
 Category: PUNCTUATION

### Configure the database cluster

To use the MySQL cluster, you have to configure the following in the `.env` file:

- `DATABASE_URL` is the connection string for the MySQL primary.
- `DATABASE_REPLICA_x_URL` (e.g `DATABASE_REPLICA_0_URL`, `DATABASE_REPLICA_1_URL`) - is the connection string for the MySQL read-only server.

## Setup for long-running environments

When running Shopware in long-lived PHP worker environments such as FrankenPHP worker mode, database connections can stay open long enough to exceed MySQL's `wait_timeout`.
This can lead to `MySQL server has gone away` errors on later requests.

Shopware does not install a reconnect package by default, but you can enable this behavior yourself with [`facile-it/doctrine-mysql-come-back`](https://github.com/facile-it/doctrine-mysql-come-back):

```bash
composer require facile-it/doctrine-mysql-come-back
```

Configure the wrapper class on `DATABASE_URL` with `Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connection`:

```dotenv
DATABASE_URL="mysql://username:password@localhost:3306/dbname?wrapperClass=?wrapperClass=Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connection&driverOptions[x_reconnect_attempts]=3"
```

If you are using Shopware with read replicas, use `Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connections\PrimaryReadReplicaConnection` instead:

```dotenv
DATABASE_URL="mysql://username:password@localhost:3306/dbname?wrapperClass=Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connections\PrimaryReadReplicaConnection&driverOptions[x_reconnect_attempts]=3"
DATABASE_REPLICA_0_URL="mysql://username:password@replica:3306/dbname"
```
Loading
Loading