A comparison of mariadb and postgresql based on chat data.
I wrote a chat bot in Golang that saves messages.
These tests were run with 161 million chat messages saved.
The sql table looks as follows (output from mariadb):
CREATE TABLE IF NOT EXISTS messages(
id SERIAL,
VARCHAR(255),
streamer user VARCHAR(255),
message LONGTEXT,NOT NULL DEFAULT current_timestamp()
intime DATETIME =InnoDB ) ENGINE
The mariadb SERIAL type is a BIG UNSIGNED INT with auto increment and index.
The hardware used:
Database versions (from SELECT VERSION();
):
The data was initially transfered from mariadb to postgres with pgloader.
Query:
SELECT COUNT(*) FROM messages;
Output (same for both): 161572889
Time taken:
mariadb | postgresql |
---|---|
29.731 sec | 13.196 sec |
Query:
SELECT COUNT(*), DATE(intime) FROM messages GROUP BY DATE(intime);
Time taken:
mariadb | postgresql |
---|---|
61.378 sec | 14.194 sec |
This benchmark showed mariadb only using one core at once with 100% usage. Postgres used 3 cores at once with 60-100% usage with each core.
Query:
//mariadb:
SELECT COUNT(*) FROM messages WHERE intime >= DATE_SUB(NOW(), INTERVAL 1 DAY);
//postgres:
SELECT COUNT(*) FROM messages WHERE intime >= NOW() - INTERVAL '1 DAY';
The output was 0 for both systems, which was OK.
Time taken:
mariadb | postgresql |
---|---|
33.871 sec | 13.458 sec |
Backup and restore commands for each system:
cmd/db | mariadb | postgres |
---|---|---|
backup | mysqldump | pg_dump |
restore | mysql | psql |
Both database systems support the use of non-blocking backups. This means that you can create a complete and consistent snapshot of your database during ongoing operation without any downtime or waiting inserts.
Source:
The times taken:
type | mariadb | postgres |
---|---|---|
dump | 2m36.195s | 2m8.843s |
restore | 18m57.465s | 7m21.162s |
Commands used:
mariadb-dump --databases chat > mariadb.sql
mysql chat < mariadb.sql
pg_dump chat > postgres.sql
psql -d chat -f postgres.sql
The mariadb.sql file was 14GB in size, the postgres.sql file was 12GB in size.
Old test with 45 million database rows years prior:
type | mariadb | postgres |
---|---|---|
backup | 1:11min | 1:04min |
restore | 10:02min | 2:10min |