Skip to content

This is the multi-page printable view of this section.

Return to the regular view of this page

Tutorials

Hands-on, step-by-step labs from building Mimus 19.0.1 to running multi-protocol, encrypted and active-active workloads.

Start here when trying Mimus for the first time. Each tutorial walks through one runnable lab from start to finish and verifies the result with standard client tools.

  1. Build and start Mimus — Compile the PostgreSQL 19.0 kernel and pg_mysql from source, initialize PGDATA, and inspect mimus_required_features.
  2. Shared table across MySQL and PostgreSQL — Write rows on TCP 3306 with mysql and read them back on TCP 5432 with psql.
  3. Encrypt your first table with PG TDE — Register a keyring provider, create a USING tde_heap table, and verify relation encryption.
  4. Two-node active-active lab with pgEdge — Pair two writable nodes with Spock 5.0.15 and merge concurrent delta_apply balance updates.

1 - Build and start Mimus

Compile Mimus 19.0.1 and pg_mysql from the public Git trees, initialize a data directory, and verify native PostgreSQL connectivity.

Prerequisites

You need a Linux host (Debian 13, Ubuntu 24.04/26.04, or Rocky Linux 9/10) with standard PostgreSQL build dependencies: a C11 compiler (gcc or clang), meson / ninja or GNU make, bison, flex, libreadline-dev, zlib1g-dev, libssl-dev, libicu-dev, libxml2-dev, and pkg-config.

Compile the kernel and pg_mysql

Clone the public pgsty/mimus kernel repository and the companion pgsty/pg_mysql extension repository, check out the verified 19.0.1-r4 revisions, and install under /usr/mimus-19:

git clone https://github.com/pgsty/mimus.git
cd mimus && git checkout 0d8a551aa121

./configure --prefix=/usr/mimus-19 --with-ssl=openssl --with-icu --with-libxml
make -j"$(nproc)"
sudo make install
cd ..

git clone https://github.com/pgsty/pg_mysql.git
cd pg_mysql && git checkout 1e631f9802c5
make -j"$(nproc)" PG_CONFIG=/usr/mimus-19/bin/pg_config
sudo make PG_CONFIG=/usr/mimus-19/bin/pg_config install
Additional extensions

To add pg_tde, spock or Babelfish onto the same /usr/mimus-19 prefix, build each extension against /usr/mimus-19/bin/pg_config using the matched source trees listed in Kernel Patch Manifest.

Initialize and verify the instance

Create a fresh data directory, start the server on port 5432, and inspect the version and cluster feature state:

export PATH="/usr/mimus-19/bin:$PATH"
initdb -D /var/lib/mimus/data --auth-local=peer --auth-host=scram-sha-256 --encoding=UTF8
pg_ctl -D /var/lib/mimus/data -l /var/lib/mimus/logfile start

psql -X -d postgres -c "SELECT current_database(), current_user, version();"
psql -X -d postgres -c "SHOW mimus_required_features;"

On a freshly initialized cluster before any optional compatibility or encryption feature is activated, mimus_required_features returns an empty string, meaning the directory remains a plain PostgreSQL 19.0 data directory.

Next, continue to Shared table across MySQL and PostgreSQL to enable the MySQL wire listener on this instance.

2 - Shared table across MySQL and PostgreSQL

Enable the MySQL listener on port 3306, write rows from a MySQL client, and query the same table from psql on port 5432.

Preload pg_mysql

Starting from the instance created in Build and start Mimus, preload pg_mysql, enable the MySQL wire listener on port 3306, set a login password, and create the SQL extension inside postgres:

psql -X -d postgres <<'SQL'
ALTER SYSTEM SET shared_preload_libraries = 'pg_mysql';
ALTER SYSTEM SET mysql.listener_on = on;
ALTER SYSTEM SET mysql.port = 3306;
ALTER SYSTEM SET mysql.database = 'postgres';
ALTER ROLE postgres WITH PASSWORD 'ChangeMe_Lab_2026!';
SQL

pg_ctl -D /var/lib/mimus/data restart
psql -X -d postgres -c "CREATE EXTENSION pg_mysql;"

Ensure pg_hba.conf permits local TCP logins (scram-sha-256 or md5) from 127.0.0.1/32.

Create and populate a table from MySQL

Connect with the standard mysql command-line client on TCP 3306, create a logical MySQL database app, and insert two rows:

mysql -h 127.0.0.1 -P 3306 -u postgres -p'ChangeMe_Lab_2026!' <<'SQL'
CREATE DATABASE app;
USE app;
CREATE TABLE notes (
    id   INT PRIMARY KEY AUTO_INCREMENT,
    body VARCHAR(40) NOT NULL
);
INSERT INTO notes (body) VALUES ('written over 3306'), ('shared MVCC row');
SELECT DATABASE(), @@version, @@version_comment;
SQL

Each logical MySQL database maps to a PostgreSQL schema inside mysql.database (postgres by default).

Query the same physical table from PostgreSQL

Now read and join those exact committed rows over native PostgreSQL on port 5432:

psql -X -h 127.0.0.1 -p 5432 -U postgres -d postgres \
  -c "SELECT id, body FROM app.notes ORDER BY id;"
 id |       body
----+-------------------
  1 | written over 3306
  2 | shared MVCC row
(2 rows)

Both sessions share one buffer pool, one WAL stream, and one physical relation (app.notes). For driver details, TLS setup and SQL dialect rules, see the MySQL manual.

3 - Encrypt your first table with PG TDE

Configure a keyring provider, create an encrypted table using tde_heap, and verify transparent page encryption and startup protection.

Configure preloading and a local keyring

On an instance with pg_tde installed under /usr/mimus-19, add pg_tde to shared_preload_libraries, restart PostgreSQL, and register a local keyring file for your lab database:

sudo install -d -m 0700 -o postgres -g postgres /var/lib/mimus-keys

psql -X -d postgres -c "ALTER SYSTEM SET shared_preload_libraries = 'pg_tde';"
pg_ctl -D /var/lib/mimus/data restart

Now enable the extension and bind a principal key in postgres:

CREATE EXTENSION pg_tde WITH SCHEMA public;

SELECT pg_tde_add_database_key_provider_file(
    'lab_provider', '/var/lib/mimus-keys/lab.per');
SELECT pg_tde_create_key_using_database_key_provider(
    'lab_key', 'lab_provider');
SELECT pg_tde_set_key_using_database_key_provider(
    'lab_key', 'lab_provider');
Production key management

File providers are intended for local testing and development. Production deployments should store principal keys in HashiCorp Vault or a KMIP server; see Keys and WAL encryption.

Create and verify an encrypted table

Create a table with USING tde_heap plus an index and out-of-line text, then confirm encryption status:

CREATE TABLE public.ledger (
    id      integer PRIMARY KEY,
    memo    text NOT NULL,
    balance bigint NOT NULL
) USING tde_heap;

INSERT INTO public.ledger VALUES (1, repeat('confidential-', 200), 50000);
SELECT pg_tde_is_encrypted('public.ledger'::regclass);

pg_tde_is_encrypted returns t. Primary heap pages, the primary-key B-tree index, and the TOAST table are all encrypted on disk while remaining transparent to SQL, MySQL (pg_mysql), and TDS (Babelfish) queries.

Check the cluster startup guard

Inspect the cluster’s recorded feature lock:

SHOW mimus_required_features;
-- Returns: tde

Once tde is recorded in mimus_required_features, Mimus refuses to start or replay WAL against this data directory if pg_tde is omitted from shared_preload_libraries, preventing accidental startup without storage decryption hooks. For backup and offline page verification, continue to the PG TDE manual.

4 - Two-node active-active lab with pgEdge

Start two local Mimus nodes with Spock 5.0.15, establish bidirectional replication, and verify delta_apply conflict merging.

Initialize two writable nodes

With Spock 5.0.15 installed under /usr/mimus-19, initialize two local instances on ports 5541 (node_a) and 5542 (node_b) with logical WAL and commit timestamps enabled:

for p in 5541 5542; do
  initdb -D "/tmp/mimus-${p}" --auth-local=trust --auth-host=trust
  cat >> "/tmp/mimus-${p}/postgresql.conf" <<EOF
port = ${p}
wal_level = logical
track_commit_timestamp = on
output_plugin_libraries = 'pgoutput,spock_output'
max_worker_processes = 16
max_replication_slots = 10
max_wal_senders = 10
shared_preload_libraries = 'spock'
spock.conflict_resolution = 'last_update_wins'
spock.save_resolutions = on
spock.enable_ddl_replication = off
EOF
  pg_ctl -D "/tmp/mimus-${p}" -l "/tmp/mimus-${p}.log" start
  createdb -p "${p}" lab
done

Create nodes, tables, and bidirectional subscriptions

Create the same table with delta_apply enabled on both nodes, register each Spock node, and wire up subscriptions in both directions:

-- Run on port 5541 (node_a)
CREATE EXTENSION spock;
SELECT spock.node_create('node_a', 'host=127.0.0.1 port=5541 dbname=lab');

CREATE TABLE public.accounts (
    id      integer PRIMARY KEY,
    balance integer NOT NULL
);
ALTER TABLE public.accounts ALTER COLUMN balance
    SET (log_old_value = true, delta_apply_function = spock.delta_apply);
INSERT INTO public.accounts VALUES (1, 100);
SELECT spock.repset_add_table('default', 'public.accounts');
-- Run on port 5542 (node_b)
CREATE EXTENSION spock;
SELECT spock.node_create('node_b', 'host=127.0.0.1 port=5542 dbname=lab');

CREATE TABLE public.accounts (
    id      integer PRIMARY KEY,
    balance integer NOT NULL
);
ALTER TABLE public.accounts ALTER COLUMN balance
    SET (log_old_value = true, delta_apply_function = spock.delta_apply);
SELECT spock.repset_add_table('default', 'public.accounts');

SELECT spock.sub_create(
    'sub_from_a', 'host=127.0.0.1 port=5541 dbname=lab',
    replication_sets := ARRAY['default'],
    synchronize_structure := false,
    synchronize_data := true, forward_origins := '{}'
);
SELECT spock.sub_wait_for_sync('sub_from_a');

Then add the reverse subscription on node_a (5541) with synchronize_data := false:

SELECT spock.sub_create(
    'sub_from_b', 'host=127.0.0.1 port=5542 dbname=lab',
    replication_sets := ARRAY['default'],
    synchronize_structure := false,
    synchronize_data := false, forward_origins := '{}'
);
SELECT spock.sub_wait_for_sync('sub_from_b');

Verify concurrent delta updates

Apply independent balance adjustments on each node (+30 on node_a, -15 on node_b) and verify that both converge to 115:

psql -X -p 5541 -d lab -c "UPDATE public.accounts SET balance = balance + 30 WHERE id = 1;"
psql -X -p 5542 -d lab -c "UPDATE public.accounts SET balance = balance - 15 WHERE id = 1;"
sleep 1
psql -X -p 5541 -d lab -c "SELECT 'node_a' AS node, id, balance FROM public.accounts;"
psql -X -p 5542 -d lab -c "SELECT 'node_b' AS node, id, balance FROM public.accounts;"

For production conflict arbitration, monitoring, and standby failover rules, consult the pgEdge manual.