Moodle 2.5 - DB Migrate from PostgreSQL to MySQL

Moodle 2.5 - DB Migrate from PostgreSQL to MySQL

by Patrick Chen -
Number of replies: 2

Hello, 

We've been running an instance of Moodle 2.5 (build 20130621) on a Windows Server2008R2 (w/ PHP 5.5.0) connected to a PostgreSQL 9.2.3 database for a few years. We'd like to both upgrade to Moodle 3.0 and move the db to MySQL 5.6.21

On Moodle 2.5 I ran the *experimental* "Database Migration" tool and according to that script, it successfully completed the copying/migrating of files from the current connected PostgreSQL database to the MySQL db I set up. I then edited the config.php to reflect the MySQL db connection details

$CFG->dbtype    = 'mysqli';

$CFG->dblibrary = 'native';

$CFG->dbhost    = '12.34.56.78';

$CFG->dbname    = 'moodletest';

$CFG->dbuser    = 'moodletest_user';

$CFG->dbpass    = 'Apassword';

$CFG->prefix    = 'mdl_';

$CFG->dboptions = array (

  'dbpersist' => 0,

  'dbsocket' => '',

);

------

After changing the config.php settings, loading the Moodle instance takes me to the Installation prompt; following through with that overwrites the migrated MySQL database with a fresh Moodle installation db. 

I'm not sure if I'm missing a step, or what exactly is index.php checking for when it decides to send me to the Installation process. Fortunately I'm trying this on a development instance; also, changing the config.php connection details back to the PostgreSQL db is seamless, everything comes back to normal. Or is it possible that PostgreSQL->MySQL won't work with the 2.5 transfer script? Should I first upgrade from 2.5 to 3.0 with current PostgreSQL db, and THEN try migrating to MySQL db? 


Any insight into this would be greatly appreciated, thank you!

Average of ratings: -
In reply to Patrick Chen

Re: Moodle 2.5 - DB Migrate from PostgreSQL to MySQL

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Read:
- "Migrate moodle databases from MySQL to PostgreSQL" https://moodle.org/mod/forum/discuss.php?d=329176

- "How to migrate moodle databases from PostgreSQL to MySQL ?" https://moodle.org/mod/forum/discuss.php?d=316712

- "Very simple data transfer (mysqli to postgresql)" https://moodle.org/mod/forum/discuss.php?d=216695

and more, https://moodle.org/mod/forum/search.php?id=5&subject=mysql+postgresql ...
In reply to Patrick Chen

Re: Moodle 2.5 - DB Migrate from PostgreSQL to MySQL

by Patrick Chen -

I figured out the solution to my first question: I forgot to set the prefix while running the Database Migration tool, that's why the migrated database was not accepted - the prefixes on config.php did not match the migrated database. I've now successfully migrated a near empty devlopment Moodle site's database from postgresql to mysql with the migrate.php script.

However, I've run into a different problem with migrating our production Moodle site's database that's much bigger. Now, the migrate.php script fails at the same place everytime trying to migrate the production database from postgresql to mysql. The error in PHP is

[25-Mar-2016 13:13:30 America/Los_Angeles] Potential coding error - active database transaction detected when disposing database:
* line 126 of \lib\dtl\database_importer.php: call to moodle_database->start_delegated_transaction()
* line 79 of \lib\dtl\database_mover.php: call to database_importer->begin_database_import()
* line 145 of \lib\dtl\database_exporter.php: call to database_mover->begin_database_export()
* line 85 of \admin\tool\dbtransfer\locallib.php: call to database_exporter->export_database()
* line 187 of \admin\tool\dbtransfer\cli\migrate.php: call to tool_dbtransfer_transfer_database()

The migration is smooth all the way up to the 'user' table, and fails there everytime. On the mysql database, preceding tables are all there. The 'user' table has about 450 entries on the postgresql production database, and on the incomplete/failed mysql destination database there are about 390 entries. In the Command Line where I run migrate.php, the error displayed is 

Copying table timezone
Done
Copying table user
!!! Error writing to database !!!

I've also tried Maintenace Mode and also Stopping the site completely in IIS


Any insight is appreciated, thank you.