Migration from MySQL and PostgreSQL: Difference between revisions
No edit summary |
Wikiservice (talk | contribs) (Refresh MemCP documentation: accuracy, operational guidance, performance profile and maintained API reference) |
||
| Line 1: | Line 1: | ||
<!-- Copyright (C) 2026 Carl-Philip Haensch --> | |||
<!-- SPDX-License-Identifier: GPL-3.0-or-later --> | |||
<span id="migration-from-mysql-and-postgresql"></span> | |||
= Migration from MySQL and PostgreSQL = | |||
Migration is a compatibility and operations project, not only a data copy. MemCP can import through live MySQL/PostgreSQL connections or supported dump formats, while applications connect through the MySQL protocol or the HTTP SQL endpoints. It does not expose a PostgreSQL wire-protocol server and does not claim complete syntax, metadata, type, or administration compatibility with either source system. | |||
or | |||
Keep the source database authoritative until schema translation, row counts, constraints, representative queries, writes, timezone behavior, and restart recovery have been validated. Measure import duration and application latency with successful results, retain a rollback path, and separately design ongoing change capture when the source continues receiving writes during a staged migration. | |||
[[File:Ports.svg|thumb|none|640px|MemCP client and import connection paths]] | |||
<span id="live-import"></span> | |||
== Live import == | |||
<syntaxhighlight lang="scheme">; MySQL: host/port nil use 127.0.0.1:3306 | |||
(mysql_import nil nil "import_user" "secret" "source_db" "target_db") | |||
; PostgreSQL: database, source schema, target database | |||
(psql_import nil nil "postgres" "secret" "source_db" "public" "target_db")</syntaxhighlight> | |||
Optional trailing arguments select or rename individual tables. Use a least-privilege read-only source account and protect credentials from shell and process listings. | |||
<span id="dumps"></span> | |||
== Dumps == | |||
<code>load_sql</code> reads MySQL SQL; <code>load_psql</code> reads PostgreSQL SQL and supported pg_dump/archive inputs. A compressed input must be decompressed (<code>zcat</code>/<code>xzcat</code>), not passed through the <code>gzip</code>/<code>xz</code> compression functions. | |||
<syntaxhighlight lang="bash">gzip -dk dump.sql.gz | |||
# Then in the MemCP console: | |||
# (load_sql "target_db" (stream "dump.sql"))</syntaxhighlight> | |||
For large or live migrations, prefer the importer functions above rather than assuming every vendor-specific dump statement is accepted. | |||
<span id="application-connection"></span> | |||
== Application connection == | |||
<syntaxhighlight lang="php">$db = new PDO( | |||
'mysql:host=127.0.0.1;port=3307;dbname=target_db', | |||
'root', | |||
'strong-password' | |||
); | |||
echo $db->query("SELECT 'it works'")->fetchColumn();</syntaxhighlight> | |||
PostgreSQL SQL syntax is available over <code>/psql/<database></code>; MemCP does not expose a PostgreSQL wire-protocol port. | |||
<span id="validation-checklist"></span> | |||
== Validation checklist == | |||
* compare schemas, types, defaults, indexes, constraints, triggers, and views; | |||
* compare counts and checksums per table; | |||
* replay representative reads and writes against both systems; | |||
* verify AUTO_INCREMENT and timezone behavior; | |||
* restart MemCP and repeat checks; | |||
* measure import duration, query latency, errors, and CDC lag if live replication is used; | |||
* retain a tested rollback path until cutover gates pass. | |||
Revision as of 11:59, 28 August 2026
Migration from MySQL and PostgreSQL
Migration is a compatibility and operations project, not only a data copy. MemCP can import through live MySQL/PostgreSQL connections or supported dump formats, while applications connect through the MySQL protocol or the HTTP SQL endpoints. It does not expose a PostgreSQL wire-protocol server and does not claim complete syntax, metadata, type, or administration compatibility with either source system.
Keep the source database authoritative until schema translation, row counts, constraints, representative queries, writes, timezone behavior, and restart recovery have been validated. Measure import duration and application latency with successful results, retain a rollback path, and separately design ongoing change capture when the source continues receiving writes during a staged migration.
Live import
<syntaxhighlight lang="scheme">; MySQL: host/port nil use 127.0.0.1:3306 (mysql_import nil nil "import_user" "secret" "source_db" "target_db")
- PostgreSQL
- database, source schema, target database
(psql_import nil nil "postgres" "secret" "source_db" "public" "target_db")</syntaxhighlight> Optional trailing arguments select or rename individual tables. Use a least-privilege read-only source account and protect credentials from shell and process listings.
Dumps
load_sql reads MySQL SQL; load_psql reads PostgreSQL SQL and supported pg_dump/archive inputs. A compressed input must be decompressed (zcat/xzcat), not passed through the gzip/xz compression functions.
<syntaxhighlight lang="bash">gzip -dk dump.sql.gz
- Then in the MemCP console:
- (load_sql "target_db" (stream "dump.sql"))</syntaxhighlight>
For large or live migrations, prefer the importer functions above rather than assuming every vendor-specific dump statement is accepted.
Application connection
<syntaxhighlight lang="php">$db = new PDO(
'mysql:host=127.0.0.1;port=3307;dbname=target_db', 'root', 'strong-password'
);
echo $db->query("SELECT 'it works'")->fetchColumn();</syntaxhighlight>
PostgreSQL SQL syntax is available over /psql/<database>; MemCP does not expose a PostgreSQL wire-protocol port.
Validation checklist
- compare schemas, types, defaults, indexes, constraints, triggers, and views;
- compare counts and checksums per table;
- replay representative reads and writes against both systems;
- verify AUTO_INCREMENT and timezone behavior;
- restart MemCP and repeat checks;
- measure import duration, query latency, errors, and CDC lag if live replication is used;
- retain a tested rollback path until cutover gates pass.