/go/mariadb2postgre takes a SQL dump made by mariadb-dump and rewrites it with a series of text substitutions, so that PostgreSQL can load it with psql. It: It is a quick text conversion, not a full migration tool. It changes the file in place, without making a backup, and it also changes some values inside the data rows. Read What it does not handle before you rely on the result. Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.
Quick start
# 1. Dump the database
mariadb-dump mydb > mydb.sql
# 2. Keep the original, convert a copy
cp mydb.sql mydb-pg.sql
/go/mariadb2postgre mydb-pg.sql
# 3. Load the copy into PostgreSQL (create the database first)
sudo su - postgres -c "psql -d mydb -f /tmp/mydb-pg.sql"
Options
This command has no options. It takes only the file path.
| Argument | Required | Default | Notes |
|---|---|---|---|
<file> |
Yes | — | The SQL dump to convert. It is overwritten. |
Examples
# Convert a copy of a dump
cp shop.sql shop-pg.sql
/go/mariadb2postgre shop-pg.sql
Before:
CREATE TABLE `Orders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY `idx_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
After:
CREATE TABLE Orders (
id integer NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name character varying(100) DEFAULT NULL,
created TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00');
The PRIMARY KEY line and the KEY line were removed. The identity column carries the primary key instead, and the idx_name index is gone.
# After loading, reset each identity sequence to the highest existing id
# (replace Orders and id with your table and column)
sudo su - postgres -c "psql -d shop -c \"SELECT setval(pg_get_serial_sequence('orders','id'), (SELECT MAX(id) FROM Orders));\""
Output
The command prints nothing on success. It only writes the line below to /var/log/go/mariadb2postgre.log, so you can see when it ran and on which file.
[Nov 20 10:15:42]# mariadb2postgre mydb-pg.sql
Check the result by opening the converted file, or by loading it and reading the psql errors.
Security
[!WARNING]
The original file is overwritten and there is no undo. Copy the dump first, as in Quick start.
[!WARNING]
The substitutions run on the whole file, including the data rows, not only on the table definitions. Some values are changed or lose characters. See Changes to your data.
See the full reference at /go/mariadb2postgre and the GoAdmio command index.
GoAdmio is free and open source, with no license fees and no account limits. Read the GoAdmio docs, or see why it is a free cPanel alternative at goadmio.com.
