Not a developer? Go to MovableType.com

Documentation

DatabaseRoles

This is documentation about a configuration directive, which can be placed within Movable Type’s core configuration file, mt-config.cgi, to customize the behavior of the system.

This optional configuration setting allows you to specify a file that defines additional database servers that can be used to distribute load for database requests. This would require you to configure multiple database servers, one as a ‘master’ and additional ‘slave’ servers that replicate the data from the master database server. The additional slave database servers can be used for handling read-only requests (SELECT queries).

To configure MT to use additional servers, you start by specifying the ‘DatabaseRoles’ configuration setting.

Default

none

Values

The value for the setting is a file name for a YAML-formatted text file.

All config settings/directives where you specify a path or a path+filename are specified relative to the location of the config file itself (like a CSS file in that regard; where all url() references in a stylesheet file are relative to the location of the stylesheet file).

A full path can also be used of course.

Example

mt-config.cgi

Database mtdb
DBUser melody
DBPassword nelson
DatabaseRoles path/relative/to/mt-config-file/DBRoles.yaml

DBRoles.yaml

global:
    user: default-readonly-username
    slaves:
        - host: read-only-slave1.example.com
          user: user-for-slave1
        - host: read-only-slave2.example.com
        - host: read-only-slave3.example.com

The ‘global’ heading identifies the ‘global’ role, which is the primary role for Movable Type database connections. MT currently only supports a single master database, but will be offering support for multiple master databases in the future. So for now, ‘global’ is the only role supported. Under the role heading (“global:”), you may specify the following settings which will serve as the default values for any slave connections declared. The following values may be given:

  • dbname - Database name (defaults to ‘Database’ from mt-config file)
  • user - Database username (defaults to ‘DBUser’ from mt-config file)
  • pass - Database password (defaults to ‘DBPassword’ from mt-config file)
  • host - Database hostname (defaults to ‘DBHost’ from mt-config file)
  • port - Database port number (defaults to ‘DBPort’ from mt-config file)
  • sock - Database socket (defaults to ‘DBSocket’ from mt-config file)
  • cycle - Limit to length of any persistent database connection (specified in minutes)

Under the “slaves:” heading, you provide the information necessary to make a connection to each slave you have configured. Each of the above settings may also be defined for each slave, if necessary. Values that are not specified for the slave configuration are drawn from the “global” settings instead.

More Examples

Single Slave DB.yaml

mt-config.cgi

Database mtdb
DBUser melody
DBPassword nelson
DatabaseRoles SingleSlaveDB.yaml

SingleSlaveDB.yaml

global:
    host: dbrw-1.ai.com
    cycle: 60
    slaves:
        - host: dbro-1.ai.com

MultiReadOnlyDB.yaml

mt-config.cgi

Database mtdb
DBUser melody
DBPassword nelson
DatabaseRoles MultiReadOnlyDB.yaml

MultiReadOnlyDB.yaml

global:
    cycle: 60
    host: dbrw-0.ai.com
    slaves:
        - host: dbro-1.ai.com
        - host: dbro-2.ai.com
        - host: dbro-3.ai.com
Back

2 Comments

Eric

Eric on August 12, 2009, 9:48 a.m. Reply

Is this for MTE or for MTOS too?

Dave Rawks

Dave Rawks on January 29, 2010, 10:09 a.m. Reply

Neither of the config examples above seems to work correctly. If the base mt-config doesn’t include a DBHost directive connections to mt always report an error like “

Connection error: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

” I’ve explicitly set a DBPort in the mt-config and it still reports the same error which seems to indicate that the setting is being ignored. Any clarification as to how to configure and validate a multidb config would be excellent as this seems to be the ONLY page with any information on it.