-
Jev-Style Decision Models in MySQL with vsql-ai
Decision models such as TypeSafe's Jev, Google's Gemini Decision 1, and OpenAI's Decisions API answer a question about an input with a probability, which makes them useful for classifying rows in a database. Getting a probability score from these models takes one API call per input. The harder part is choosing the cutoff that counts as yes, and knowing that it's right for your data.OpenAI's guide on this topic gives an answer: "Use labeled examples from your application to set thresholds for routing, filtering, or review." That means that to derive a threshold, you need some rows where you already know the right answer. Your application may already store these answers. For example, a support application may record which team resolved each ticket. Before you use a stored answer as a label, check two things: that it answers the same question that you ask the model, and that it is correct.If you don't have such a column, you can label a sample of rows by hand and store each label in a column next to the input. Label at least 100 to 150 rows of each answer (more when an answer is rare). Either way, the labels should be in the same table as the data. The vsql-ai extension can then write a decision model's probabilities there too, so checking a threshold becomes a query.vsql-ai is an extension that runs on VillageSQL, a drop-in replacement for MySQL that adds PostgreSQL-style extensions to MySQL. Its ai_decision() function lets a database call decision APIs directly from SQL. The rest of this post walks through an example of using this function.Asking a decision model from SQLThe example in this post is a support team that wants to send billing tickets to a billing queue and other tickets to a general queue. We wrote 20 short support tickets for it and labeled each one by hand, 10 as billing and 10 as other. That is enough to show the method, but too few to choose a real threshold. The tickets are in a tickets table, with the ticket text in a body column, our label in an is_billing column, and an empty JSON column, answers, for the model's response.Setup takes two statements. First, you store the API key in the MySQL keyring, where vsql-ai 0.0.9 reads it. After that, everything refers to the key by name, so a query does not carry the key itself:SELECT keyring_key_store('gemini_key', 'SECRET', '<your API key>');
Then, you register the model under a model ID, with the provider, the model name, the key's name, and the account that stored the key:SET GLOBAL vsql_ai.models = '{
"decide": {"provider": "google", "model": "gemini-decision-1",
"key_id": "gemini_key", "key_owner": "root@localhost"}
}';
ai_decision(model_id, input, questions) then takes that model ID, the text to judge, and a JSON object of named questions. This post asks one yes/no question, which vsql-ai calls a noul. You can have more than one question in the JSON, though. The model doesn't know anything about your business. It judges each ticket against the instructions and criteria that you write, so their wording shapes every probability:SET @questions = '{
"is_billing": {"type": "noul", "instructions": "Is this message about billing?",
"criteria": {"true": "About charges, invoices, payments or refunds",
"false": "About anything else"}}
}';
This UPDATE asks the model about every ticket and stores each answer in the answers column:UPDATE tickets SET answers = ai_decision('decide', body, @questions);
Each answer is JSON, keyed by question name. For ticket 3 ("Your app logged me out and now my card on file shows an error when I try to upgrade."), Gemini Decision 1 returned this:{"is_billing": {"noul": 0.8528589448473877, "type": "noul", "confidence": 0.8528589448473877}}
The noul value is the probability that the answer is yes.Choosing a threshold from labeled rowsWith the answers stored, one query puts each ticket's text, our label, and Gemini Decision 1's probability side by side:SELECT id, body, is_billing,
ROUND(JSON_VALUE(answers, '$.is_billing.noul' RETURNING DOUBLE), 3) AS p_billing
FROM tickets ORDER BY id;
id
Ticket
is_billing
p_billing
1
I was charged twice for my November invoice. Please refund the duplicate charge today.
1
0.974
2
How do I export my data to CSV?
0
0.01
3
Your app logged me out and now my card on file shows an error when I try to upgrade.
1
0.853
4
Love the new dashboard, great work!
0
0.024
5
Can I get a receipt with our VAT number on it? Not urgent.
1
0.97
6
Production is down since the 2am deploy and every request returns 500.
0
0.012
7
Why did my bill go up this month? Nothing changed on our side.
1
0.978
8
The search box ignores accented characters.
0
0.03
9
Please cancel our subscription at the end of the term.
1
0.771
10
Can you add SSO with Okta?
0
0.026
11
We hit the plan limit on seats. What happens to the extra users?
1
0.415
12
The invoice PDF link in the email returns a 404.
1
0.925
13
How much does the enterprise tier cost compared to what we pay now?
1
0.923
14
Our trial ended and the account is locked. We want to keep testing for a week.
0
0.177
15
Password reset email never arrives.
0
0.025
16
Is there a discount for nonprofits?
1
0.918
17
The mobile app crashes when I open settings.
0
0.031
18
Who do I talk to about moving our account to a different company entity?
0
0.28
19
Our finance team needs last year's statements for the audit.
1
0.406
20
Dark mode makes the charts unreadable.
0
0.026
Most tickets were clear. The middle of the range held the judgment calls. We labeled tickets 11 and 19 as billing, and the model gave them 0.415 and 0.406. We labeled tickets 18 and 14 as other, and the model gave them 0.28 and 0.177.The following query compares several thresholds against the labels:SELECT t.threshold,
SUM(p >= t.threshold AND is_billing) AS true_pos,
SUM(p >= t.threshold AND NOT is_billing) AS false_pos,
SUM(p < t.threshold AND is_billing) AS missed,
ROUND(SUM(p >= t.threshold AND is_billing)
/ NULLIF(SUM(p >= t.threshold), 0), 2) AS prec,
ROUND(SUM(p >= t.threshold AND is_billing) / SUM(is_billing), 2) AS recall
FROM (SELECT is_billing,
JSON_VALUE(answers, '$.is_billing.noul' RETURNING DOUBLE) AS p
FROM tickets) s
CROSS JOIN (SELECT 0.1 AS threshold UNION ALL SELECT 0.3 UNION ALL SELECT 0.5
UNION ALL SELECT 0.7 UNION ALL SELECT 0.9) t
GROUP BY t.threshold ORDER BY t.threshold;
With the result of:threshold true_pos false_pos missed prec recall
0.1 10 2 0 0.83 1.00
0.3 10 0 0 1.00 1.00
0.5 8 0 2 1.00 0.80
0.7 8 0 2 1.00 0.80
0.9 6 0 4 1.00 0.60
prec is precision, the share of tickets at or above the threshold that really are billing, and recall is the share of billing tickets that the threshold catches. The obvious default, 0.5, misses two of the 10 billing tickets. On these rows, 0.3 catches all of them and does not flag any "other" ticket.Treat 0.3 as an example, not a magic number for your own data. We picked it and scored it on the exact same 20 rows. The labels are just our judgment calls, and the four tickets here are borderline enough that someone else might label them differently.The sample is also too small. At 0.3, recall is 10 out of 10, which sounds perfect, except a 10-for-10 result still leaves room for a true miss rate as high as 26% (at 95% confidence). Catching 140 out of 140 drops that bound to about 2%. Meanwhile, the gap between 0.3 and 0.5 is just two tickets, which is well within random noise. With real traffic, split your labeled rows: pick the threshold on one part and check it on the rest. The query doesn't change at any size, so rerun it whenever you label more rows or reword a question.Rows without a probability can also skew the table. A failed call returns NULL with a warning, and an OpenAI refusal doesn't carry a probability. Such a billing row counts as neither caught nor missed, but it still counts in the recall total, so recall reads lower and missed doesn't show why. Find those rows before you run the threshold query, and call the model again for them:SELECT id FROM tickets
WHERE JSON_VALUE(answers, '$.is_billing.noul' RETURNING DOUBLE) IS NULL;
Comparing two models on the same rowsA threshold is linked to the model that produced its probabilities. vsql-ai works with Google's gemini-decision-1, TypeSafe's jev-latest (or a versioned ID such as jev-1.13.0), and OpenAI's gpt-6-luna, and it returns the same JSON from all three, so trying another model is a one-line change to the registry. We ran the same 20 tickets through gpt-6-luna, changing only that line. Its yes/no probabilities were much less spread out: 13 of the 20 answers came back as 0 or 1 (when rounded to three decimal places), so the model was sure, or very nearly sure, about most tickets. It also ranked the borderline tickets differently. It scored ticket 14 (the trial lockout) at 0.81 and ticket 19 (the audit statements) at 0.02, where Gemini Decision 1 gave 0.177 and 0.406.The same threshold query gives this result:threshold true_pos false_pos missed prec recall
0.1 9 1 1 0.90 0.90
0.3 9 1 1 0.90 0.90
0.5 9 1 1 0.90 0.90
0.7 9 1 1 0.90 0.90
0.9 6 0 4 1.00 0.60
The first four rows are the same because no ticket scored between 0.1 and 0.7. At each of those thresholds, gpt-6-luna flags ticket 14, which is not a billing ticket, and misses ticket 19, which is. Raising the threshold to 0.9 drops ticket 14, but it also misses three more billing tickets. A threshold can only trade one kind of mistake for the other within a model's ranking. Before you switch the model, run the same labeled rows through the new model and compare the two tables.Routing on a probabilityOnce you have a threshold, a CASE turns a probability into a routing decision. Instead of forcing a binary yes/no on every ticket—especially when 20 rows aren't enough to fully trust 0.3—you can use two cutoffs to separate clear cases from uncertain ones. Tickets at 0.9 or above go straight to the billing queue, anything between 0.3 and 0.9 goes to a person for review, and the rest go to the general queue:SELECT id, CASE
WHEN JSON_VALUE(answers, '$.is_billing.noul' RETURNING DOUBLE) >= 0.9 THEN 'billing queue'
WHEN JSON_VALUE(answers, '$.is_billing.noul' RETURNING DOUBLE) >= 0.3 THEN 'human review'
ELSE 'general queue'
END AS route
FROM tickets ORDER BY id;
On the 20 tickets, Gemini Decision 1's answers sent six to the billing queue, four (tickets 3, 9, 11, and 19) to human review, and 10 to the general queue.Trying it yourselfai_decision() is new in vsql-ai 0.0.9. vsql-ai uses VillageSQL preview capabilities, which are off by default, so turn them on before you install the extension:SET PERSIST vsql_allow_preview_extensions = ON;
INSTALL EXTENSION vsql_ai;
Each account that calls ai_decision() also needs the VSQL_AI_USER privilege. The README setup steps cover the keyring, the API key, and the model registry, and the Decisions section of the README has the full question and answer reference.
-
MySQL Community 2026: Growing Together
As the end of the year approaches, it is time for a familiar MySQL Community tradition: our Advent Calendar. From today through Dec 24, we will share a new post each day, bringing you practical learning, community stories, and a look back at what we have achieved together. We are opening this year’s calendar with […]
-
DBaaS Beyond the Hyperscalers, Part 1: MySQL Performance
DBaaS Beyond the Hyperscalers, Part 1: MySQL Performance
Research objective
In this series of posts we want to look at the non-hyperscaler cloud providers that offer MySQL and PostgreSQL DBaaS (DataBase as a Service) and answer two questions: which service delivers the most throughput out of the box, and which one gives the best cost efficiency per transaction.
The providers may sell the same shapes, but their performance can be very different. Also, the transaction cost is another factor apart from performance.
The current part covers MySQL performance. Part 2 covers PostgreSQL performance, and Part 3 covers cost efficiency for both. Details of the setup, workloads and metrics are in the Test Setup and Methodology reference.
What we tested
Each provider’s managed MySQL was tested at the same size, a typical startup-level general purpose tier: 4 shared vCPU, 16 GB RAM and 150 to 350 GB of SSD/NVMe storage. The services were benchmarked with Sysbench and HammerDB at three data set sizes (about 16, 32 and 64 GB), using the default configuration each provider applies.
Provider
Plan / Tier
MySQL Version
Scaleway
DB-PRO2-XS
8.0.21
UpCloud
Managed Database – Standard
8.4.11
Vultr
Startup General Purpose Optimised
8.4.11
OVHcloud
Discovery B3-16
8.4.11
Exoscale
Startup-16
8.4.11
Key findings
Exoscale was the fastest in every Sysbench scenario, with peak throughput almost 3.5 times that of the slowest provider (Scaleway).
Vultr, UpCloud and OVHcloud performed close to each other, between the two.
Scaleway was the slowest and had the highest latency. It is the only provider still on MySQL 8.0, which may explain part of the gap.
UpCloud did better in HammerDB than in Sysbench, but its service switched to read-only mode under heavy load, so not all runs completed.
Sysbench throughput
Exoscale leads, Scaleway trails, and the other three are close together.
Graph 1: Sysbench with 10M rows per table [ graph ] [ table ]
Exoscale is the clear leader in TPS. Vultr, UpCloud and OVHcloud are close to each other, and Scaleway showed the lowest performance. Since Scaleway is the only provider running MySQL 8.0 (the others use MySQL 8.4), the older server version may account for at least part of the difference.
The providers keep the same order with partially buffered data (20M rows per table) and in the more I/O-bound scenario (40M rows per table). See the interactive graphs for 20M rows and 40M rows.
Sysbench peak throughput
Exoscale’s peak is almost 3.5 times Scaleway’s.
Graph 2: Sysbench peak output with 10M rows per table [ graph ] [ table ]
P95 latency
Latency follows throughput: the fastest service responds quickest.
Graph 3: P95 latency [ graph ] [ table ]
Exoscale has the lowest latency and Scaleway the highest, with the other providers grouped in the middle. Latency for 20M rows and 40M rows per table shows the same pattern.
The higher latency for Scaleway is likely coming from the bandwidth limitation of 350 Mbps imposed on its compute instances used to run the benchmarks. While some providers put the transfer limit and charge extra cost for out of limit use, nobody else limited the network speed of the client to such a low number. Interesting that the database service had no speed limit, the weak link was the client connection. Even though it affected the throughput, running a client compute outside of the Scaleway network would cost even higher delays. Higher network speeds were available for disproportionally larger and expensive compute shapes compared to the database itself. In other words, the full potential of a startup Scaleway database service could not be fully realized using solutions for startup use alone.
HammerDB (TPC-C)
The ranking is similar to Sysbench, with UpCloud doing better.
Graph 4: HammerDB with 160 warehouses [ graph ] [ table ]
The performance distribution in HammerDB is similar to Sysbench, but UpCloud performs better here. Interactive graphs: 320 warehouses and 640 warehouses.
A note on reliability
All benchmarks ran three times to reduce noise from neighboring tenants on shared vCPUs. UpCloud’s managed MySQL did not always handle the elevated load: it kept switching the server into read-only mode, which disrupted testing, so not all of its runs produced results.
Next: PostgreSQL performance
Part 2 runs the managed PostgreSQL services of the same providers through HammerDB. Part 3 compares what each service costs per hour and how many transactions $1 buys on each one, for both databases.
The post DBaaS Beyond the Hyperscalers, Part 1: MySQL Performance appeared first on Percona.
-
DISA Releases Oracle MySQL 9.x STIG for MySQL Enterprise Edition 9.7 LTS
The Defense Information Systems Agency (DISA) has approved and released the Oracle MySQL 9.x Security Technical Implementation Guide (STIG), Version 1, Release 1, supporting MySQL Enterprise Edition 9.7 LTS. Published on November 30, 2026, the guide is available from the DoD Cyber Exchange and is effective immediately upon release. As an author of the MySQL […]
-
Getting Started with Percona PXC Operator
As part of many conversations I had during Percona Live I was asked why we didn’t use the Percona Operator for MySQL based on Percona XtraDB Cluster. We are currently running hundreds of PXC clusters across many Kubernetes environments all deployed with our own in-house operator. As part of the evaluation I needed to set up a repeatable environment with S3 compatible storage that could run locally so I’ve documented my setup in the hope it will help others.
I’ve tried not to dig too deeply into the operations of PXC cluster as I felt it would add too much complexity to the article and really needs more in-depth explanations than I could give here. There are lots of good articles around explaining the concepts introduced here so I would recommend further research if you are interested.
Parts of this article are the same as the getting started with PostgreSQL, this isn’t laziness it’s my way of keeping things simple. I try and create the same development process for most environments, so the setup should be the same.
Full disclaimer: I’ve used this setup on an Arm-based MacBook. I’m assuming it will work on Linux pretty much the same but for Windows I have no idea. I’ve not touched Windows in a long time but it should work the same.
Installing kind is pretty simple and will depend on your host O/S - full details are here.
The scripts used below can be found on GitHub in the directory Percona-Operator-PXC
shell
Copy
Copied!
git clone https://github.com/statefulops/mysql-scripts.git
cd mysql-scripts/Percona-Operator-PXC
Deploy a base cluster with an object store
The first step is to deploy a multi-node Kind cluster with a way of simulating an S3 compatible object store (in this example using RustFS). Using something like RustFS ensures we avoid any cloud costs when testing backups and restores.
The quick and dangerous way is to run a script from GitHub
shell
Copy
Copied!
curl -fsSL https://raw.githubusercontent.com/statefulops/kind-scripts/main/s3/create-cluster.sh | bash -s -- v1.37.0 percona-pxc
The safer way is to download the script, check it’s not doing anything harmful and then execute it yourself
shell
Copy
Copied!
curl -fsSL https://raw.githubusercontent.com/statefulops/kind-scripts/main/s3/create-cluster.sh -o create-cluster.sh
less create-cluster.sh
chmod +x create-cluster.sh
./create-cluster.sh v1.37.0 percona-pxc
This will deploy a control-plane node and 3 workers with zone labels, and a container running RustFS, using Kubernetes 1.37. I tend to always use zone labels even locally as it simulates multiple zone deployments.
shell
Copy
Copied!
kubectl get nodes -L topology.kubernetes.io/zone
text
Copy
Copied!
NAME STATUS ROLES AGE VERSION ZONE
percona-pxc-control-plane Ready control-plane 3m39s v1.37.0
percona-pxc-worker Ready 3m25s v1.37.0 AZ-A
percona-pxc-worker2 Ready 3m25s v1.37.0 AZ-B
percona-pxc-worker3 Ready 3m25s v1.37.0 AZ-C
shell
Copy
Copied!
kubectl get po -n rustfs
text
Copy
Copied!
NAME READY STATUS RESTARTS AGE
rustfs-574c7b89d7-5dl4d 1/1 Running 0 4m1s
A nodeport is set automatically so the RustFS UI will be available on http://localhost:9001. The user is set to myadminuser and the script sets a random value for the secret password in a Kubernetes secret. To get the password run
shell
Copy
Copied!
kubectl get secret rustfs-admin-credentials -n rustfs -o jsonpath='{.data.secret-key}' | base64 -d
UI on http://localhost:9001
Standard AWS CLI commands work as well - make sure you run the make_bucket command as it is needed later.
shell
Copy
Copied!
export AWS_ACCESS_KEY_ID=myadminuser
export AWS_SECRET_ACCESS_KEY=$(kubectl get secret rustfs-admin-credentials -n rustfs -o jsonpath='{.data.secret-key}' | base64 -d)
export AWS_DEFAULT_REGION=us-east-1
aws --endpoint-url http://localhost:9000 s3 mb s3://my-kind-bucket
text
Copy
Copied!
make_bucket: my-kind-bucket
shell
Copy
Copied!
aws --endpoint-url http://localhost:9000 s3 ls
text
Copy
Copied!
2026-10-12 12:14:49 my-kind-bucket
Install the Percona PXC Operator 1.20.1
Add the Percona Helm repo:
shell
Copy
Copied!
helm repo add percona https://percona.github.io/percona-helm-charts/
helm repo update
Safety check — only ever run this against a local kind cluster: I might have learnt this lesson the hard way :)
shell
Copy
Copied!
CURRENT_CONTEXT=$(kubectl config current-context)
case "$CURRENT_CONTEXT" in
*kind*) echo "OK: using kind context '$CURRENT_CONTEXT'" ;;
*) echo "ABORT: context '$CURRENT_CONTEXT' is not a kind cluster"; exit 1 ;;
esac
shell
Copy
Copied!
kubectl create namespace pxc-operator
helm install pxc-operator percona/pxc-operator --version 1.20.1 --namespace pxc-operator
kubectl config set-context --current --namespace=pxc-operator
Deploy the cluster
This is a simple deployment that will deploy a 3 node PXC cluster with 3 HAProxy nodes.
shell
Copy
Copied!
kubectl apply -f cr.yaml
Check status:
shell
Copy
Copied!
kubectl get perconaxtradbcluster
While initializing:
text
Copy
Copied!
NAME ENDPOINT STATUS PXC PROXYSQL HAPROXY AGE
cluster1 cluster1-haproxy.pxc-operator initializing 1 3 3m16s
Once ready:
text
Copy
Copied!
NAME ENDPOINT STATUS PXC PROXYSQL HAPROXY AGE
cluster1 cluster1-haproxy.pxc-operator ready 3 3 5m23s
This will take some time to install based on internet speeds etc
Eventually you should get a running cluster
shell
Copy
Copied!
kubectl get po
NAME READY STATUS RESTARTS AGE
cluster1-haproxy-0 2/2 Running 0 12m
cluster1-haproxy-1 2/2 Running 0 10m
cluster1-haproxy-2 2/2 Running 0 10m
cluster1-pxc-0 3/3 Running 0 12m
cluster1-pxc-1 3/3 Running 0 10m
cluster1-pxc-2 3/3 Running 0 9m14s
pxc-operator-64d6bd6f58-dn6mw 1/1 Running 0 14m
Connect to the cluster via the CLI
Get the root password from the new Kubernetes secret:
bash
Copy
Copied!
kubectl get secret cluster1-secrets --template='{{.data.root | base64decode}}{{"\n"}}'
Launch a client pod and connect to the command line:
bash
Copy
Copied!
kubectl run -i --rm --tty percona-client --image=percona/percona-xtradb-cluster:8.4 --restart=Never -- bash -il
Inside the client pod:
bash
Copy
Copied!
mysql -u root -p -h cluster1-haproxy
sql
Copy
Copied!
mysql> select @@hostname;
+----------------+
| @@hostname |
+----------------+
| cluster1-pxc-0 |
+----------------+
1 row in set (0.00 sec)
mysql>
The connection to the MySQL instance from cluster1-haproxy is via several hops.
cluster1-haproxy is a Kubernetes service that points to the 3 HAProxy nodes.
The HAProxy nodes route the connection to one of the active MySQL nodes in the cluster.
So as long as your client connection is well behaved and performs retries correctly your connection should remain connected to the cluster during a node failure.
From the client pod started above check what MySQL node you are connected to.
sql
Copy
Copied!
mysql> select @@hostname;
+----------------+
| @@hostname |
+----------------+
| cluster1-pxc-0 |
+----------------+
1 row in set (0.00 sec)
In a separate terminal terminate the node you are connected to.
shell
Copy
Copied!
kubectl delete po cluster1-pxc-0
While the pod is terminating in the original terminal re-try the select.
sql
Copy
Copied!
mysql> select @@hostname;
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
Connection id: 3163
Current database: *** NONE ***
+----------------+
| @@hostname |
+----------------+
| cluster1-pxc-2 |
+----------------+
1 row in set (0.01 sec)
mysql>
So the mysql client noticed the connection had broken, re-established it and this time HAProxy sent the connection to cluster1-pxc-2 which was still active.
Backup to RustFS
Before running the backup run a MySQL client again and create a table with some data
sql
Copy
Copied!
create schema test;
use test;
CREATE TABLE phonebook(phone VARCHAR(32) PRIMARY KEY, firstname VARCHAR(32), lastname VARCHAR(32), address VARCHAR(64));
INSERT INTO phonebook(phone, firstname, lastname, address) VALUES('+1 123 456 7890', 'John', 'Doe', 'North America');
SELECT * FROM phonebook;
sql
Copy
Copied!
mysql> SELECT * FROM phonebook;
+-----------------+-----------+----------+---------------+
| phone | firstname | lastname | address |
+-----------------+-----------+----------+---------------+
| +1 123 456 7890 | John | Doe | North America |
+-----------------+-----------+----------+---------------+
1 row in set (0.00 sec)
Create the backup S3 secret from the RustFS admin credentials:
Either a quick one-liner:
bash
Copy
Copied!
kubectl create secret generic my-cluster-name-backup-s3 --from-literal=AWS_ACCESS_KEY_ID="$(kubectl get secret rustfs-admin-credentials -n rustfs -o jsonpath='{.data.access-key}' | base64 -d)" --from-literal=AWS_SECRET_ACCESS_KEY="$(kubectl get secret rustfs-admin-credentials -n rustfs -o jsonpath='{.data.secret-key}' | base64 -d)" --dry-run=client -o yaml | kubectl apply -f -
or get the base64-encoded values:
bash
Copy
Copied!
kubectl get secret rustfs-admin-credentials -n rustfs -o jsonpath='{.data.access-key}'
kubectl get secret rustfs-admin-credentials -n rustfs -o jsonpath='{.data.secret-key}'
Add the values above to the data: section of backup-secret-s3.yaml and apply it
bash
Copy
Copied!
kubectl apply -f backup-secret-s3.yaml
Run a backup:
bash
Copy
Copied!
kubectl apply -f backup.yaml
Find the backup pod and check its logs:
bash
Copy
Copied!
kubectl get po | grep xb-backup1
kubectl logs xb-backup1-bnrwj
shell
Copy
Copied!
2026-11-14 09:08:38.992 INFO: SST script finished with exit code: 0
2026-11-14 09:08:39.096 INFO: Exiting main loop with code OK
2026-11-14 09:08:39.096 INFO: Garbd returns 0
+ GARBD_EXIT_CODE=0
+ case ${GARBD_EXIT_CODE} in
+ log INFO 'Backup was finished successfully'
+ exit 0
2026-11-14 09:08:39 [INFO] Backup was finished successfully
Verify the backup landed in S3:
bash
Copy
Copied!
export AWS_ACCESS_KEY_ID=myadminuser
export AWS_SECRET_ACCESS_KEY=$(kubectl get secret rustfs-admin-credentials -n rustfs -o jsonpath='{.data.secret-key}' | base64 -d)
export AWS_DEFAULT_REGION=us-east-1
aws --endpoint-url http://localhost:9000 s3 ls my-kind-bucket/
shell
Copy
Copied!
PRE cluster1-2026-11-14-09:07:52-full.sst_info/
PRE cluster1-2026-11-14-09:07:52-full/
2026-11-14 09:08:38 26667 cluster1-2026-11-14-09:07:52-full.md5
2026-11-14 09:08:23 128 cluster1-2026-11-14-09:07:52-full.sst_info.md5
Restore
Before doing the restore remove the table created earlier to check the restore worked.
sql
Copy
Copied!
use test;
drop table phonebook;
Disable any binlog processing before running a restore.
shell
Copy
Copied!
kubectl patch pxc cluster1 \
--type merge \
-p '{"spec":{"backup":{"pitr":{"enabled":false}}}}'
In this case you should see the following message as it wasn’t enabled
shell
Copy
Copied!
perconaxtradbcluster.pxc.percona.com/cluster1 patched (no change)
Trigger a restore and watch the pods get recreated
shell
Copy
Copied!
cat apiVersion: "pxc.percona.com/v1"
kind: "PerconaXtraDBClusterRestore"
metadata:
name: "restore1"
spec:
pxcCluster: "cluster1"
backupName: "backup1"
EOF
Once the restore has been completed check the table is back.
sql
Copy
Copied!
mysql> SELECT * FROM phonebook;
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
Connection id: 1117
Current database: test
+-----------------+-----------+----------+---------------+
| phone | firstname | lastname | address |
+-----------------+-----------+----------+---------------+
| +1 123 456 7890 | John | Doe | North America |
+-----------------+-----------+----------+---------------+
1 row in set (0.03 sec)
mysql>
Enabling binlog syncing
Realistically you are going to want to back up the Binary Logs (binlogs) to minimise data loss.
Apply the updated cr which will enable the binlog syncing.
bash
Copy
Copied!
kubectl apply -f cr-binlogs.yaml
Verify pods:
shell
Copy
Copied!
kubectl get po
shell
Copy
Copied!
NAME READY STATUS RESTARTS AGE
cluster1-haproxy-0 2/2 Running 0 17m
cluster1-haproxy-1 2/2 Running 0 16m
cluster1-haproxy-2 2/2 Running 0 16m
cluster1-pitr-7dc984dcd9-rs7xn 1/1 Running 0 47s
cluster1-pxc-0 3/3 Running 0 17m
cluster1-pxc-1 3/3 Running 0 16m
cluster1-pxc-2 3/3 Running 0 15m
To get some binlogs being created start the sysbench container
shell
Copy
Copied!
kubectl apply -f sysbench.yaml
Once it has been running for a few minutes you should now be able to see binlogs being backed-up into the S3 bucket.
shell
Copy
Copied!
aws --endpoint-url http://localhost:9000 s3 ls my-kind-bucket/
shell
Copy
Copied!
PRE cluster1-2026-11-14-16:40:02-full.sst_info/
PRE cluster1-2026-11-14-16:40:02-full/
2026-11-14 17:05:50 19973933 binlog_1794675888_000025_40ab6621c720a080c20710905ef86632
2026-11-14 17:05:50 43 binlog_1794675888_000025_40ab6621c720a080c20710905ef86632-gtid-set
2026-11-14 16:40:29 26815 cluster1-2026-11-14-16:40:02-full.md5
2026-11-14 16:40:15 128 cluster1-2026-11-14-16:40:02-full.sst_info.md5
2026-11-14 17:05:50 346 gtid-binlog-cache.json
2026-11-14 17:05:50 43 last-binlog-set-d41f08dc-e04a-11f1-b333-4b79bd8eb077
Cluster Operation Overview
This section was originally earlier on but I moved it later to avoid hitting some of the more complex bits early on. While this article is focused on Percona XtraDB Cluster (PXC) the basic principles are the same for Galera cluster, MariaDB Galera Cluster and PXC. They all go back to the same work done by Codership Oy back in the 2000s. I’m going to avoid commenting on the current state of the product and the purchase of Codership by MariaDB but focus on Percona’s PXC as it’s a stable supported version.
PXC adds the two following extra components to the running mysqld instance to form the cluster:
The Group Communication System (GCS), this provides a private network between the nodes to manage cluster membership, order transactions globally and provide failure detection.
The wsrep API provides write-set replication as a plugin to MySQL
These together allow the cluster to run a near full master-master replication allowing well behaved clients to write to any of the nodes simultaneously, in the right environment. Please note both caveats, a well-behaved client and the right environment.
Dropping an existing poorly written application into PXC and expecting it to solve all of the problems you have isn’t going to work. The application needs to understand that it might get deadlocked and to try again and if it reads from another node it may not see the data it has just written. The reason for this is briefly explained below.
PXC nodes need to be able to talk to each other quickly to maintain state. In reality keeping the nodes in the same cloud region is probably a best practice. Nodes spread across availability zones in AWS seems to be a sweet spot. Spreading them around the globe will probably not work, yes I’ve seen it done but you start to stretch the laws of physics and end up with a very unstable environment. A more fault tolerant solution is needed for this use case.
The process of modifying data within the MySQL instance is now more complex than with a single node as it needs to be coordinated across all the nodes. The simplified steps are:
A transaction is completed on a local node and the client issues a commit, at this point the client has to wait before getting a response back
wsrep creates a write-set containing all the modifications in the commit. This is now broadcast to all the other nodes
Certification of the write-set is now carried out on all the nodes ensuring it can be applied everywhere.
If there is no conflict the write-set is certified, the original transaction is allowed to commit successfully, and the other nodes add the write-set to their applier queues to be applied.
If there is a conflict and the write-set can’t be applied to all nodes the transaction gets rolled back and it’s not applied. This means the original client transaction fails and needs to be retried.
For the client a detail in step 4 is important, while the update is made on the original node it could still be on the applier queue on one of the other nodes meaning there is a small window when the data is different. The client needs to be aware of this and ensure if it needs to read its own writes it always connects to the same node (or uses wsrep_sync_wait). If the applier queue gets too large the cluster will pause updates until it is processed.
Updates can be performed as long as the cluster has quorum. More than 50% of the nodes have to be available and online to achieve quorum. This is why clusters are normally 3 nodes (or at least an odd number of nodes) as it allows for one node to be down and the cluster will continue to operate.
Recovery Modes IST vs SST
When nodes fail the cluster will recover the failed nodes using two different approaches.
IST (Incremental State Transfer), this is used when the node has been down for a short period and the missing write-sets exist in a donor node’s gcache. Once the failed (joiner) node is restarted it will connect to a donor node and apply the missing write-sets before joining the node into the cluster.
SST (State Snapshot Transfer), if the missing write-sets are not available, or it’s a new node, an SST will be triggered. This essentially takes a full backup from a donor node and rebuilds the node from this backup. This can obviously take some time to complete with a large dataset. The donor will stay available but will have the extra load of the backup running.
To see the two options first of all check the cluster is healthy and the sysbench load is running.
sql
Copy
Copied!
show status like 'wsrep_cluster%';
sql
Copy
Copied!
+----------------------------+--------------------------------------+
| Variable_name | Value |
+----------------------------+--------------------------------------+
| wsrep_cluster_weight | 30 |
| wsrep_cluster_capabilities | |
| wsrep_cluster_conf_id | 3 |
| wsrep_cluster_size | 3 |
| wsrep_cluster_state_uuid | ec51ce68-e0d6-11f1-808a-03de7cc64daa |
| wsrep_cluster_status | Primary |
+----------------------------+--------------------------------------+
6 rows in set (0.00 sec)
Cluster status should be Primary and cluster size should be 3.
Sysbench should be pottering along generating load
shell
Copy
Copied!
kubectl logs sysbench-8dd57985c-hbcv7
text
Copy
Copied!
[ 570s ] thds: 4 tps: 20.90 qps: 418.00 (r/w/o: 292.60/45.60/79.80) lat (ms,95%): 7.43 err/s: 0.00 reconn/s: 0.00
[ 570s ] queue length: 0, concurrency: 0
[ 580s ] thds: 4 tps: 18.50 qps: 370.00 (r/w/o: 259.00/41.90/69.10) lat (ms,95%): 9.22 err/s: 0.00 reconn/s: 0.00
[ 580s ] queue length: 0, concurrency: 0
First to trigger an IST just delete one of the pods.
shell
Copy
Copied!
kubectl delete po cluster1-pxc-2
Once the pod has recovered review the MySQL logs to see what method was chosen.
shell
Copy
Copied!
kubectl logs cluster1-pxc-2 -c logs | cut -d "\"" -f4
shell
Copy
Copied!
2026-11-15T09:49:34.020065Z 2 [Note] [MY-000000] [Galera] Check if state gap can be serviced using IST\n
2026-11-15T09:49:34.020077Z 2 [Note] [MY-000000] [Galera] ####### IST uuid:ec51ce68-e0d6-11f1-808a-03de7cc64daa f: 14710, l: 14998, STRv: 3\n
2026-11-15T09:49:34.020121Z 2 [Note] [MY-000000] [Galera] IST receiver addr using ssl://10.244.1.7:4568\n
2026-11-15T09:49:34.020138Z 2 [Note] [MY-000000] [Galera] IST receiver using ssl\n
2026-11-15T09:49:34.020233Z 2 [Note] [MY-000000] [Galera] Prepared IST receiver for 14710-14998, listening at: ssl://10.244.1.7:4568\n
2026-11-15T09:49:34.021071Z 0 [Note] [MY-000000] [Galera] Member 1.0 (cluster1-pxc-2) requested state transfer from 'cluster1-pxc-1,'. Selected 0.0 (cluster1-pxc-1)(SYNCED) as donor.\n
2026-11-15T09:49:34.021089Z 0 [Note] [MY-000000] [Galera] Shifting PRIMARY -> JOINER (TO: 15027)\n
2026-11-15T09:49:34.021116Z 2 [Note] [MY-000000] [Galera] Requesting state transfer: success, donor: 0\n
2026-11-15T09:49:34.304854Z 0 [Note] [MY-000000] [WSREP-SST] joiner: => Rate:[ 487 B/s] Avg:[ 487 B/s] Elapsed:0:00:00 Bytes: 244 B \n
2026-11-15T09:49:34.820780Z 0 [Note] [MY-000000] [WSREP-SST] xtrabackup_ist received from donor: Running IST\n
2026-11-15T09:49:34.820809Z 0 [Note] [MY-000000] [WSREP-SST] Running post-processing...........\n
2026-11-15T09:49:34.823184Z 0 [Note] [MY-000000] [WSREP-SST] Skipping mysql_upgrade (ist)\n
2026-11-15T09:49:34.823310Z 0 [Note] [MY-000000] [WSREP-SST] ...........post-processing done\n
2026-11-15T09:49:34.824151Z 0 [Note] [MY-000000] [WSREP-SST] Galera co-ords from recovery: ec51ce68-e0d6-11f1-808a-03de7cc64daa:14709\n
To ensure we trigger an SST this time we will first schedule the underlying PVC for deletion, as the PVC is in use the --wait=false ensures the command completes, the PVC is not deleted yet but will be when the pod releases it.
shell
Copy
Copied!
kubectl delete pvc datadir-cluster1-pxc-2 --wait=false
Then delete the pod again.
shell
Copy
Copied!
kubectl delete po cluster1-pxc-2
This time the logs will show an IST wasn’t possible and a full SST was triggered from another node.
shell
Copy
Copied!
2026-11-15T10:07:29.878548Z 2 [Note] [MY-000000] [WSREP] Prepared SST request: xtrabackup-v2|10.244.1.10:4444/xtrabackup_sst//1\n
2026-11-15T10:07:29.878586Z 2 [Note] [MY-000000] [Galera] Check if state gap can be serviced using IST\n
2026-11-15T10:07:29.878595Z 2 [Note] [MY-000000] [Galera] Local UUID: 00000000-0000-0000-0000-000000000000 != Group UUID: ec51ce68-e0d6-11f1-808a-03de7cc64daa\n
2026-11-15T10:07:29.878599Z 2 [Note] [MY-000000] [Galera] ####### IST uuid:00000000-0000-0000-0000-000000000000 f: 0, l: 35746, STRv: 3\n
2026-11-15T10:07:29.878672Z 2 [Note] [MY-000000] [Galera] IST receiver addr using ssl://10.244.1.10:4568\n
2026-11-15T10:07:29.878693Z 2 [Note] [MY-000000] [Galera] IST receiver using ssl\n
2026-11-15T10:07:29.878780Z 2 [Note] [MY-000000] [Galera] Prepared IST receiver for 0-35746, listening at: ssl://10.244.1.10:4568\n
2026-11-15T10:07:29.879207Z 0 [Note] [MY-000000] [Galera] Member 1.0 (cluster1-pxc-2) requested state transfer from 'cluster1-pxc-1,'. Selected 0.0 (cluster1-pxc-1)(SYNCED) as donor.\n
2026-11-15T10:07:29.879288Z 0 [Note] [MY-000000] [Galera] Shifting PRIMARY -> JOINER (TO: 35805)\n
2026-11-15T10:07:29.879332Z 2 [Note] [MY-000000] [Galera] Requesting state transfer: success, donor: 0\n
2026-11-15T10:07:29.879380Z 2 [Note] [MY-000000] [Galera] Resetting GCache seqno map due to different histories.\n
2026-11-15T10:07:29.879422Z 2 [Note] [MY-000000] [Galera] GCache history reset: 00000000-0000-0000-0000-000000000000:0 -> ec51ce68-e0d6-11f1-808a-03de7cc64daa:35746\n
2026-11-15T10:07:30.173225Z 0 [Note] [MY-000000] [WSREP-SST] joiner: => Rate:[ 325 B/s] Avg:[ 325 B/s] Elapsed:0:00:00 Bytes: 166 B \n
2026-11-15T10:07:30.715773Z 0 [Note] [MY-000000] [WSREP-SST] Using PXB option --lock-ddl=REDUCED for SST\n
2026-11-15T10:07:30.734386Z 0 [Note] [MY-000000] [WSREP-SST] Proceeding with SST.........\n
2026-11-15T10:07:30.745528Z 0 [Note] [MY-000000] [WSREP-SST] ............Waiting for SST streaming to complete!\n
2026-11-15T10:07:45.945092Z 0 [Note] [MY-000000] [WSREP-SST] joiner: => Rate:[0.00 B/s] Avg:[0.00 B/s] Elapsed:0:00:10 Bytes: 0.00 B \r joiner: => Rate:[12.4MiB/s] Avg:[12.4MiB/s] Elapsed:0:00:15 Bytes: 188MiB \n
2026-11-15T10:07:45.949894Z 0 [Note] [MY-000000] [WSREP-SST] Decompressing the backup at /var/lib/mysql//sst-xb-tmpdir\n
2026-11-15T10:07:45.950708Z 0 [Note] [MY-000000] [Galera] 0.0 (cluster1-pxc-1): State transfer to 1.0 (cluster1-pxc-2) complete.\n
2026-11-15T10:07:45.951436Z 0 [Note] [MY-000000] [Galera] Member 0.0 (cluster1-pxc-1) synced with group.\n
2026-11-15T10:07:46.080311Z 0 [Note] [MY-000000] [WSREP-SST] Preparing the backup at /var/lib/mysql//sst-xb-tmpdir\n
2026-11-15T10:07:49.343928Z 0 [Note] [MY-000000] [WSREP-SST] Moving the backup to /var/lib/mysql/\n
2026-11-15T10:07:49.456464Z 0 [Note] [MY-000000] [WSREP-SST] Running post-processing...........\n
2026-11-15T10:07:49.458896Z 0 [Note] [MY-000000] [WSREP-SST] Skipping mysql_upgrade (sst): local version (8.4.8) == donor version (8.4.8)\n
2026-11-15T10:07:49.482932Z 0 [Note] [MY-000000] [WSREP-SST] Waiting for server instance to start..... This may take some time\n
Once the pod is back, wsrep_cluster_size should return to 3.
Tidy up
Drop the kind cluster
shell
Copy
Copied!
kind delete cluster --name percona-pxc
|