MyBB Community Forums

Full Version: MyBB 1.8.30 -- Migrating from MariaDB/MySQL to PostgreSQL - a WIP community guide
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Mods, if this is inappropriate please direct me otherwise. 

On the MyBB Discord I've been discussing the migration in the title, and I've found a number of things that are weird. I'm looking to make documentation about doing it anyways, so I wanted to discuss both methods I've tried, and also source from people smarter than me how to fix issues here:

Methods that didn't work

Merge System. See this thread: https://community.mybb.com/thread-236487-lastpost.html

python/ruby mysql2postgresql. Didn't get off the ground due to not being updated in years. 

mysqldump --compatible=postgresql

Why do this?

A bunch of reasons:

MariaDB/MySQL has made a serious number of crufty errors that were not smart:

See UTF8/UTF8MB4 debacle, which continues to break things

InnoDB is unreliable in crash recovery. MyISAM is obsolete, Aria is mehhhhhh. 

Out of the box, a requirement to dump a db to get a backup 

Galera is not stock with MariaDB but a separate addon, otherwise you have standard master/slave replication.

Lots of other annoying things. That's enough for me, at least to consider postgres, take a small performance hit, lose native fulltext search, etc. 

What has worked (partially)?

pgloader3, suggested by Euan worked partially. The general method to get a partial working forum is:

pgloader --cast 'type tinyint to smallint drop typemod' mysql://user:password@localhost/mybb pgsql://user:password@localhost/mybb

That cast is needed to prevent an erroneous tinyint - > bool type which will break everything. 

You'll need to update the database driver, make sure that the utf8mb4 strings in config.php are instead utf8, and probably tweak other stuff

What is still not working, for us?

1. Plugins with single quotes in messages and such I can't figure out how to escape properly. \' makes an error. I'm familiar with admining postgres, but not with development of it so this simple issue is still being researched in my spare time. 

2. Optimize Databases, Convert UTF8, and numerous other things are broken. 

3. Cache reload is broken. I don't know why, the error is that this query is improper, and I can tell it is:

"select count() as count from mybb_datacache where = '' limit 1" It's not a table thing AFAICT? I'm still looking into it. 

I've still got a lot to review and test. 

Approaches?

1. I could use some help coming up with other cast rules for mybb -- I'm not 100% sure what type conversions could be causing other internal issues? 

2. I'm coming up with tables that can be dropped and recreated that only hold transient data, e.g. data that is mostly written to and then read but that can be truncated without issues. Thus far, my list includes:

mybb_adminlog
mybb_adminsessions
mybb_datacache
mybb_debuglogs
mybb_mailerrors
mybb_maillogs
mybb_mailqueue
mybb_moderatorlog
mybb_questionsessions
mybb_searchlog
mybb_sessions
mybb_spamlog
mybb_tasklog

Obviously purge your mail queue, lock down your site, backup logs etc. But AFAICT, these all contain nonessential data that can be essentially done without losing posts or PMs or anything. 

I'm looking for help in documenting this and making it better, if you guys care enough to help that would be grand! Eventual goal is a postgres migration guide!
Ok, so Postgres I forgot has an option to just drop schema. If you want to do this from a default install, something like this will work:

pg_dump -U dbuser -d dbname -s -t mybb_adminlog -t mybb_adminsessions -t mybb_datacache -t mybb_debuglogs -t mybb_mailerrors -t mybb_maillogs -t mybb_mailqueue -t mybb_moderatorlog -t mybb_questionsessions -t mybb_searchlog -t mybb_sessions -t mybb_spamlog -t mybb_tasklog > generic_mybb_templates

So I did that, and I'm still looking into major differences in the setup to find a way to do a direct pg_loader to a functional db -- but using tables like these as a backup if needed. 

Hopefully a concrete update on this soon.
Ok, so I discovered a major thing. You need to have all schema for Postgres be public. It's a quirk.

I fixed that. From here, there's still plenty broken. But it's actually working.