How to config multiple mysql instances to Elgg?

Hi everyone!

I`d wanto to now how to config an elgg instaltion with multiple mysql instances replication.

 

Thanks.

  • In general it's possible, however keep in mind #1377 and #1349 (they seem to be mostly outdated though). Try using changes from my pull request that fixes connection selection bug and problem with configuration of databases: https://github.com/Elgg/Elgg/pull/410/

  • I would appreciate if you give some feedback how things are going.

  • I did and it works for me. I`m using an AWS RDS instance and a read replica.

    My config file:

    $CONFIG->connection->split = true;

    $db_read = new stdClass();
    $db_read->dbuser = 'dev';
    $db_read->dbpass = 'dev';
    $db_read->dbhost = 'localhost';
    $db_read->dbname = 'database_read';

    $db_write = new stdClass();
    $db_write->dbuser = 'dev';
    $db_write->dbpass = 'dev';
    $db_write->dbhost = 'localhost';
    $db_write->dbname = 'database_write';

    $CONFIG->db = array();

    $CONFIG->db['read'] = $db_read;

    $CONFIG->db['write'] = $db_write;

     

    Also had to change the method setup_db_connection for validade the variable $CONFIG->connection->split to correct a old bug (http://trac.elgg.org/ticket/1349):

    function setup_db_connections() {

         global $CONFIG, $dblink;

         if (!empty($CONFIG->connection->split)) {
              establish_db_link('read');
              establish_db_link('write');
         } else {
              establish_db_link('readwrite');
         }
    }

    Now it work like a charm. :)

  • Nice :-) Just notice that there's core bug in random selection of connection in case of multiple read replicas (if you're going to setup more instances eventually), you just need to replace in function establish_db_link:

    $index = rand(0, sizeof($CONFIG->db[$dblinkname]));

    With:

    $index = rand(0, count($CONFIG->db[$dblinkname])-1);
Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.