• Welcome to Simple Machines Community Forum. Please login or sign up.
January 25, 2022, 03:17:04 PM

News:

Wondering if this will always be free?  See why free is better.


Converting from mysql to postgresql

Started by shawnb61, October 31, 2020, 02:05:56 AM

Previous topic - Next topic

shawnb61

October 31, 2020, 02:05:56 AM Last Edit: December 20, 2021, 07:38:09 PM by shawnb61
I have successfully created a copy of a forum from mysql into pg.  This required a couple of utilities, linked below.

These utilities work for SMF2.1 only.

Prepwork:
  - Install a vanilla version of PG & get it fully working.  Truncate all tables.
  - Your source mysql SMF DB must be UTF8.
  - Your source mysql SMF DB must include ONLY vanilla tables & columns. Source & target tables & columns must match perfectly.
  - If needed, create a copy & delete all extraneous rows & columns and do the mysqldump from there.

Overall Process - for use on Windows:
 (1) Use the following command to do the export:
    mysqldump -u{user} -p{pass} --no-create-db --no-create-info --hex-blob --skip-add-locks --skip-comments --skip-set-charset --compact --skip-quote-names --complete-insert {dbname} > {myfile.sql}
 (2) Run the pg_converter.php utility, reading the mysqldump just created & creating a new .sql file
 (3) Specify the $infile, $outfile & $path when prompted
 (4) Open a command window
 (5) Issue the following in the Windows command window (otherwise it assumes import is in Windows 1252, not utf8...):
    SET PGCLIENTENCODING=utf-8
 (6) Log on to psql, connect to your new empty vanilla pg DB
 (7) Load file with: \i mynewfile.sql
 (8 ) After load, you must fix all the SEQUENCE #s...
 (9) Run repair_settings.php to correct paths
 (10) Copy over your attachments, avatars, custom avatars & smileys
 (11) Clear your cache

Utilities used:
pg_converter.php: https://github.com/sbulen/sjrbTools/blob/master/pg_converter.php
pg_convert_seqs.php - fixes all the sequence #s: https://github.com/sbulen/sjrbTools/blob/master/pg_convert_seqs.php

Limitations:
Some JSON fields will get busted.  You will need to fix these by hand.  This utility does some simple translations of quotes to the pg format & since it is operating on the whole mysql export file, it treats text & code the same.  This does break some JSON fields. 

I hope this helps,

NOTE:  This has only been tested with ipv4 data.  It has also only been tested with mysql v5.7 & pg v10.  Also, only 2.1 RC3. 
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

shawnb61

I recently used these utilities to convert a mid-sized MySQL 8.0 DB (200K posts) to pg v14.1.  SMF 2.1 RC4.

It did break some JSON, which I repaired by hand.  A note about the JSON limitation was added above.

Note that due to the different quote requirements between SMF2.0 & SMF2.1, this approach only works for SMF2.1.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

albertlast

how is the ip converting handle by this process?

shawnb61

Mysqldump is told to do it as hex. The utility parses the hex & translates it.

Only tested with ipv4 thus far.



Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Advertisement: