Articles
Technical writing and lab investigations
An archive of articles and hands-on labs by Krzysztof Książek: backups and recovery, replication and high availability, and sharding. The labs are environments I built and ran myself; they aren't customer engagements.
The lab code and recorded runs are public: database-labs on GitHub.
Start with a topic
-
Performance and locking
How slow queries, lock waits and saturated servers were investigated in real audits, and what a diagnostic report looks like.
- A MySQL server that spent half its time waiting for locks
- A CPU-saturated MySQL server: full scans, long procedures and idle transactions
- Why a Galera cluster was slower than staging for an online shop
- Sample MySQL diagnostic report (illustrative)
-
Recovery and failover
Backups proven by restoring them, point-in-time recovery, and what happens to traffic when a source or replica dies.
- MySQL – test your backup by restoring it as a replica
- MySQL backup lab, part 7 – point-in-time recovery to a timestamp and a GTID
- MySQL async replication HA, part 2 – the source dies
- A Galera cluster that became unstable when it was stretched to a second data centre
-
Architecture and scaling
Choosing a topology, the cost of distance between sites, when to shard, and a replicated ClickHouse cluster under failure.
- MySQL Architecture – What to use? MySQL replication or Galera Cluster?
- Galera Cluster – Understanding the network latency impact
- MySQL Architecture – Sharding – Why shard MySQL database?
- ClickHouse HA on a Mac, part 1: two replicas, three Keepers and HAProxy
All articles
- MySQL Lab
MySQL 8.0 to 8.4, part 2 – what the upgrade checker catches, and what it can't see
I built a MySQL 8.0 server with problems the 8.4 manual warns about, ran MySQL Shell's upgrade checker, then upgraded anyway. It caught the DOUBLE AUTO_INCREMENT column and both removed config lines, missed QUALIFY and TABLESAMPLE, and a removed variable in my.cnf stopped the server only after the data dictionary was already upgraded.
- MySQL Lab
MySQL 8.0 to 8.4, part 1 – what waiting costs on RDS and Aurora
I wrote a little script that takes the AWS support calendar and turns it into a bill. On a fictitious fleet of six provisioned instances it comes to 48,768 USD of Extended Support over the next 12 months, and three Aurora MySQL v2 instances are 41,760 USD of that.
- ClickHouse Lab
ClickHouse HA on a Mac, part 4: MEMORY_LIMIT_EXCEEDED on a query that needs 8 MiB
My first attempt at this lab on a Mac failed with code 241 on a GROUP BY that peaks at 8 MiB. The query wasn't the problem: ClickHouse compares the whole process's resident memory with its cap, and on this Mac that memory kept growing in places the server doesn't track.
- ClickHouse Lab
ClickHouse HA on a Mac, part 3: insert_quorum, the no-loss proof, and taking it to production
With two replicas, insert_quorum = 2 turns a dead replica into a five-second timeout and an UNKNOWN_STATUS_OF_INSERT, and retrying the identical block was safe. After three Mac runs of breaking things, every acknowledged batch was on both replicas. Then: what I'd change before any of this went near production, a troubleshooting table, and the numbers from all three runs.
- ClickHouse Lab
ClickHouse HA on a Mac, part 2: when nodes die
I killed a ClickHouse replica under load, then the Keeper leader, then the Keeper majority. The dead replica cost about three seconds. The lost majority made every insert hang for 143 seconds while selects and the HAProxy health check carried on as if nothing had happened.
- ClickHouse Lab
ClickHouse HA on a Mac, part 1: two replicas, three Keepers and HAProxy
I built a replicated ClickHouse cluster on my Mac with one command, so I could break it on purpose in the next parts. This is the build, the healthy state, and how to read the load generator.
- MySQL Lab
MySQL async replication HA, part 3 – replicas die, and the reads you sent them
Losing a replica nobody reads from was invisible to the application. Once I routed SELECTs to the replicas through a ProxySQL rule, losing both made those reads fail while writes carried on, and the setting that sounds like the fallback, mysql-monitor_writer_is_also_reader, didn't bring them back on ProxySQL 2.7.3.
- MySQL Lab
MySQL async replication HA, part 2 – the source dies
I killed the MySQL source under sysbench load. Orchestrator promoted a replica and a hook pointed ProxySQL at it: two seconds at zero tps and four errors, one per connection. Getting there took two hook bugs, and both are the kind any incident script can have.
- MySQL Lab
MySQL async replication HA, part 1 – a source, two replicas, ProxySQL and Orchestrator
I built a MySQL source with two replicas on Docker, put ProxySQL in front as the only address the app knows, and let Orchestrator handle failover through a ProxySQL hook. This is the build, the healthy state, and how to read the sysbench line I'll use to measure every failure.
- MySQL Lab
MySQL backup lab, part 9 – the harness that records evidence
Twelve scenarios that record their own evidence to JSONL, a failure policy that stops rather than continues, a generated run report, and offline tests that check the lab's own documentation against its roles.
- MySQL Lab
MySQL backup lab, part 8 – restore into a new cluster and attach it as a replica
Restore the backup into a separate cluster, attach it as a replica of the live source, let it catch up, and compare every row. The scenario that settles recoverability — walked through as code.
- MySQL Lab
MySQL backup lab, part 7 – point-in-time recovery to a timestamp and a GTID
Timestamp recovery landed inside a forty-second window between two markers. GTID recovery brought back 200,000 deleted rows. An impossible target failed cleanly.
- MySQL Lab
MySQL backup lab, part 6 – restoring in place, and what it costs
An in-place restore stops the cluster, replaces the data directory and rebuilds the replica. A canary proves it replaced state rather than merging into it — and shows what that trade throws away.
- MySQL Lab
MySQL backup lab, part 5 – scheduled backups and retention
Backups that run with nobody watching, and the half nobody tests: that keep: N deletes the oldest backups and their data, measured against the objects left in the bucket.
- MySQL Lab
MySQL backup lab, part 4 – running backups: full, from the replica, incremental
What the operator does when a backup becomes a Kubernetes object, how sourcePod moves the work off the primary, what an incremental actually contains, and how to confirm the bytes reached object storage.
- MySQL Lab
MySQL backup lab, part 3 – data, and proof the lab is worth testing
Half a gigabyte of sysbench with exact known dimensions, an ANALYZE TABLE nobody expects, and a verify playbook that asserts the cluster state instead of printing numbers for a human to glance at.
- MySQL Lab
MySQL backup lab, part 2 – deploying MySQL by hand
The Percona operator, in-cluster MinIO, and a PerconaServerMySQL custom resource read field by field — including the flags that say out loud this topology is unsafe, and the backup block everything later depends on.
- MySQL Lab
MySQL backup lab, part 1 – the kind cluster underneath it
Three Kubernetes nodes as Docker containers, Ansible used as a task runner against localhost, and a kubeconfig that cannot reach anything but the lab. Part 1 of a nine-part walkthrough of a MySQL backup verification lab.
- MySQL Lab
MySQL – test your backup by restoring it as a replica
A green MySQL backup job is not recoverability. Restore the backup as a replica, then walk through all twelve lab scenarios (full, incremental, scheduled, PITR and by-hand kubectl) with measured evidence.
- MySQL Lab
MySQL – a replication lab with failover, backups, and scale-out on Kubernetes
A source–replica MySQL cluster on a laptop: GTID replication managed by the Percona Operator, Orchestrator failover, XtraBackup to MinIO, a restore that proves itself with a canary table, and scale-out from two members to three.
- ClickHouse Lab
ClickHouse – a replicated cluster on your laptop with kind and Ansible
A two-replica ClickHouse cluster, a three-node Keeper ensemble, a million NYC taxi trips, and Prometheus alerts that page Slack – all of it on a single Docker host, built and torn down with one command.
- MySQL
MySQL – How to encrypt backups?
Data has to be protected, this is quite clear. We protect the data by implementing firewalls, defining user privileges, roles, setting up an encryption of the data at rest and in transit. What is important to keep in mind is that the backups also have to be protected.
- MySQL
MySQL – How to backup the database?
In one of the previous blog posts we have discussed what are the types of backup that you can use with MySQL. We have taken a look at the different backup methods. What we haven’t done is to show how to backup MySQL. This blog will focus solely on the backup process.
- MySQL
MySQL Architecture – Sharding – How to approach sharding?
In the previous blog post we have started to look at the sharding in MySQL. We have discussed why someone may want to pursue sharding and when it’s a good time for that. In this blog post we will talk about different approaches to sharding.
- MySQL
MySQL – What are backup solutions for MySQL?
Most of you are probably aware of the simple fact that the database backups are quite useful. If it happens that someone forgets a WHERE clause in an UPDATE query, backups may be the way to recover your business.
- MySQL
MySQL Architecture – Sharding – Why shard MySQL database?
Why and when to shard MySQL: write load or data size that one cluster cannot handle, after scaling up and adding replicas stop helping.
- Galera
Galera – Limitations of Galera Cluster compared to standalone MySQL
Galera is a quite useful piece of technology that allows us to build highly available database clusters. This is one of the reasons why I hear questions about it a lot in my MySQL consulting work.
- Galera
How to deploy a two-node Galera cluster?
Galera cluster, be it MariaDB Cluster, Percona XtraDB Cluster or Galera Cluster from Codership uses quorum calculations to make sure the data consistency is safe in case of a split-brain and that the majority of the nodes will continue to operate while nodes that are in the minority will stop executing changes.
- MySQL
MySQL – How to rename a database?
A common MySQL question is: how to rename a database? MySQL has no RENAME DATABASE statement, so here is how to move the tables with RENAME TABLE.
- Vitess
Vitess – How to use vtexplain tool in Vitess?
Vitess attempts to be as transparent for the user as possible. As you may imagine, for a platform that supports sharding, this is not the easiest thing to do. There are quite a few factors you should consider when planning the execution of the queries.
- Vitess
Vitess – Sharding example using Sysbench-TPCC schema
In previous blog posts we have looked at how to migrate TPCC-like schema that has been created using SysBench. Now, we have it in our Vitess cluster and we would like to take it a next step further and see how it can be sharded.
- MySQL
How to create a database in MySQL?
This is another short blog where we try to answer questions commonly asked (at least per Google) by MySQL users. Today we will take a look at the following question: how to create a database in MySQL? What is a database in MySQL?
- Vitess
Vitess – How to migrate into Vitess? External vttablet
In the previous blog in our Vitess series we have explained how to migrate your data into Vitess cluster using logical backup and then keep it in sync for the period of testing using asynchronous replication. Let’s try something similar but a bit different this time.
- MySQL
MySQL – How to change the root password?
One of the most common questions according to Google is how to change the root password in MySQL. This blog is an attempt to answer this question.
- Vitess
Vitess – How to migrate into Vitess? Replication
In the previous couple of blogs we have been looking at the basic scaling options in Vitess. We have added replicas, sharded our data, created custom shards and many more.
- Galera
Galera – How To Avoid SST?
State transfer – SST or IST Let’s start by discussing what SST is and why we may want to avoid it if possible? We are not going into details regarding different types of state transfer methods in Galera.
- MySQL
MySQL – How to configure clone plugin for SSL?
As we have mentioned in one of our previous blog posts, clone plugin is a nice addition to MySQL as it allows users to easily provision nodes with data while not even leaving MySQL CLI. In the previous blog we have explained how to provision a new node to join the MySQL replication cluster.
- MySQL
MySQL – How to install and use clone plugin?
For ages MySQL was lacking an ability to provision new instances with data, at least for the community builds. Well, technically there always was mysqldump but let’s forget about using it on any kind of scale. It’s too slow to be used in most of the real world scenarios.
- Galera
Galera – How to calculate the quorum?
Galera serves traffic only while more than half of the votes are reachable: worked examples for two to five nodes, node weights, the arbitrator and two data centres.
- Galera
Galera – How to add a Galera node to the cluster?
Galera Cluster is a very useful flavour of MySQL with its strengths in High Availability and easiness of provisioning new nodes and keeping the existing nodes in sync. We have a couple of blog posts covering different features of the Galera cluster.
- Galera
MySQL Architecture – What to use? MySQL replication or Galera Cluster?
Asynchronous replication or Galera Cluster, compared across one, two and three data centres: failover, split-brain risk and the cost of network latency.
- MySQL
How to create a user in MySQL?
One of the most commonly asked, MySQL-related questions according to Google, is: “How to create a user?” We would like to answer this question in this short blog post. So, how to do it?
- Vitess
Vitess – How to upgrade Vitess Cluster?
Quite recently we have seen the release of a new Vitess version (v12.0.0) and this may lead to some questions – how to upgrade your Vitess installation when you use the Kubernetes and Vitess operator? In this blog post we would like to show the upgrade process of a simple Vitess cluster.
- MySQL
MySQL Architecture – When to use MySQL replication?
MySQL replication is easy to run and works over long distances, but it has no automated failover, no quorum and no read-after-write guarantee.
- Galera
Galera Cluster – Understanding the network latency impact
As we have discussed in one of our previous blog posts, Galera is sensitive to network latency. This also comes up often in my MySQL consulting work. We have thought that it might be interesting to take a look at this in more detail and show you what kind of impact it has.
- Vitess
Vitess – Merging the shards
In the last blog we have split one shard into several smaller ones, to accommodate a significant increase of load on one of the accounts. In this blog we are going to pretend that this condition no longer exists and we want to bring the cluster back to its original shape.
- Vitess
Vitess – Sharding the shard
In the last blog we ended up with three shards for our newsbtest keyspace. This is great but let’s assume that we quickly have noticed that our problem has not disappeared. One of the shards is generating the majority of the load and it impacts the whole application. How can we deal with such issue?
- Galera
Galera Cluster – what is it?
MySQL comes in different shapes and sizes. Asynchronous replication, semisynchronous replication, NDB Cluster, Galera Cluster, InnoDB Cluster. We are not even mentioning MariaDB as a separate entity. One of the common questions I hear when delivering MySQL consulting is: what should I use? What are the differences between X and Y?
- Vitess
Vitess – Shard the keyspace
Let’s say that we are running out of the write capacity in my primary database. In more simple words, our application executes such a number of writes per second that the database is not able to deal with them.
- Vitess
Vitess – New keyspace and xtrabackup
Last time we ended up with scaling the ‘sbtest’ keyspace up and down. We have also discussed how we can monitor the state of the replication between primary vttablet and replicas. Let’s continue by adding another keyspace to the mix.
- Vitess
Vitess – Scaling keyspace up and down
We left our cluster while sysbench was loading the data into the Vitess. This process may take a bit of time, let’s start this blog by discussing what we can do to monitor the status of the process.
- Vitess
Vitess – deploying a cluster
Step-by-step guide to deploying a Vitess cluster on a clean Kubernetes environment.
- Vitess
Intro to Vitess
Database landscape changed quite rapidly in the last couple of years. In the past the typical setup that we have seen was the database cluster. It could have been a standard, asynchronous replication-based cluster. It could have been a more cluster-aware solution like Galera.