• I’m trying to move some sites from a single-host setup to something more robust, but HyperDB isn’t handling database failover as I’d expect. I don’t know if I’m misconfiguring something, or if I have unrealistic expectations…

    Here’s (most of) my db-config.php, in the site root, alongside wp-config.php and friends:

    // Returns wpdb-style array for use with add_database() copying settings from wp-config
    function wshdb_get_template_db($host, $readpref = 1, $writepref = 1) {
            $db_tmpl = array(
                    'host' => $host,
                    'server' => '',  // only here to suppress a PHP error
                    'dataset' => 'global',
                    'lag_threshold' => NULL,
                    'user' => DB_USER,
                    'password' => DB_PASSWORD,
                    'name' => DB_NAME,
                    'timeout' => 0.2,
                    'read' => $readpref,
                    'write' => $writepref
            );
            return $db_tmpl;
    }
    
    // Populate the wpdb array based on where we're running
    $tmp_dbhost = explode(".", strtolower(gethostname()));
    $host = $tmp_dbhost[0];
    switch($host) {
            // WP4 stage
            case 'webserver1':
            case 'webserver2':
                    $wpdb->add_database(wshdb_get_template_db('masterdb'));
                    $wpdb->add_database(wshdb_get_template_db('slavedb', 1, 0));
                    break;
    
            // a bunch of other cases omitted
    
            default:
                    $wpdb->add_database(wshdb_get_template_db('localhost'));
                    break;
    }

    My intent with the above is that read queries will be more-or-less split between the two servers, with writes only going to the masterdb. And that part seems to work alright.

    But when I power down the masterdb server, the site just stops responding. What I’d expect to happen, is that the site should still be visible, but no new posts/pages/etc. can be created.

    Do I have unrealistic expectations? If so, any suggestions on workarounds that will get me some portion of what I want?

    https://www.ads-software.com/plugins/hyperdb/

Viewing 1 replies (of 1 total)
  • Thread Starter David E. Smith

    (@desmith)

    This has been sorta-resolved. The theme actually was doing some INSERTs where I didn’t expect. Obviously, this will fail, as there’s no server configured to accept writes.

    It’s resolved in the sense that I know what’s causing the problem, not in that I’ve solved the problem, but it’s out of the scope of this plugin. ??

Viewing 1 replies (of 1 total)
  • The topic ‘HyperDB not failing over as I expect’ is closed to new replies.