Jump to content


From mediawiki.org
This page is a translated version of the page Manual:$wgDBservers and the translation is 5% complete.
LoadBalancer settings: $wgDBservers
Settings for the database load balancer (database servers and load ratios).
Introducido en la versión:1.2.0
Eliminado en la versión:aún se usa
Valores permitidos:see below
Valor predeterminado:false


Since MediaWiki 1.18 (Release notes) the database user for all databases configured in this array (if you use replication) needs the REPLICATION CLIENT privilege to determine the lag between primary <-> replica.

Database load balancer. This is a two-dimensional array, an array of server info structures. Fields are:

Host name (see $wgDBserver ). For MySQL, it can contain a port or socket path after a colon.
Default database name (see $wgDBname )
DB user (see $wgDBuser )
DB password (see $wgDBpassword )
"mysql" or "postgres" (see $wgDBtype )
ratio of DB_REPLICA load, must be >=0, the sum of all loads must be >0
array of load ratios, the key is the query group name. A query may belong to several groups, the most specific group defined here is used. (introducido en 1.4.3)
max lag
(optional) Maximum replication lag before a replica will be taken out of rotation
max threads
(optional) Maximum number of running threads (eliminado en 1.23)
bit field:
  • DBO_DEFAULT — turns on DBO_TRX only if $wgCommandLineMode  != true (recommended)
  • DBO_DEBUG — equivalent of $wgDebugDumpSql
  • DBO_TRX — automatically start transactions (see Database transactions )
  • DBO_IGNORE — ignore errors (not useful in LocalSettings.php)
  • DBO_NOBUFFER — turn off buffering (not useful in LocalSettings.php)
  • DBO_SSL — use a secure connection (desaprobado in 1.39)
  • DBO_COMPRESS — compress communication
  • DBO_PERSISTENT — enable persistent connections
ssl (introducido en 1.39)
Boolean, whether to use TLS encryption. Overrides DBO_SSL.

Leave at false to use the single-server variables listed above.

The primary must be the first entry in the array.

Ejemplo 1:

$wgDBservers = [
        'host' => "primary.serv.er",
        'dbname' => "wikidb",
        'user' => "wikiuser",
        'password' => "secret",
        'type' => "mysql",
        'flags' => DBO_DEFAULT,
        'load' => 0,
        'host' => "replica1.serv.er",
        'dbname' => "wikidb",
        'user' => "wikiuser",
        'password' => "secret",
        'type' => "mysql",
        'flags' => DBO_DEFAULT,
        'load' => 1,
        'host' => "replica2.serv.er",
        'dbname' => "wikidb",
        'user' => "wikiuser",
        'password' => "secret",
        'type' => "mysql",
        'flags' => DBO_DEFAULT,
        'load' => 1,

This would configure one primary and two replicas, each replica getting an equal amount of read access load.

Ejemplo 2:

$wgDBservers = [
        'host' => 'serv.er',
        'dbname' => 'wikidb',
        'user' => 'wikiuser',
        'password' => 'secret',
        'type' => 'mysql',
        'flags' => DBO_DEFAULT | DBO_SSL,
        'load' => 0

This would configure one server with custom SSL connection if $wgDBssl set to true fails.

These and any other user-defined properties will be assigned to the mLBInfo member variable of the Database object.

MySQL specific options

Set to one of (Seconds_Behind_Master,pt-heartbeat). pt-heartbeat assumes the table is at heartbeat.heartbeat and uses UTC timestamps in the heartbeat.ts column. (https://www.percona.com/doc/percona-toolkit/2.2/pt-heartbeat.html)
If using pt-heartbeat, this can be set to an array map to change the default behavior. Normally, the heartbeat row with the server ID of this server's primary will be used. Set the "conds" field to override the query conditions, e.g. ['shard' => 's1'].
Use GTID methods like MASTER_GTID_WAIT() when possible.
Path to key file.
Path to certificate file.
Path to a single certificate authority PEM file. (introducido en 1.30+)
Path to certificate authority PEM directory.
Array list of allowable ciphers.

PostgreSQL specific options

Port to connect to the server.
Map of reserved table names to alternative table names to use

SQLite specific options

Path to the database file.
Path to the directory containing the database file. Only needed if dbFilePath is not specified, and requires dbname.
Name of the database (without the .sqlite extension). Only needed if dbFilePath is not specified, and requires dbDirectory.
Transaction mode. One of DEFERRED, IMMEDIATE or EXCLUSIVE.

MSSQL specific options

Note that MSSQL is no longer supported starting with MediaWiki 1.34.
Port to connect to the server.
Use Integrated Windows Authentication for authentication to the database instead of username/password.

Notas importantes

If you switch to this, ensure you either keep $wgDBname , $wgDBprefix y $wgDBTableOptions set, or ensure $wgCookiePrefix y $wgCachePrefix are set explicitly. Note also that if you only connect to one database server the load parameter needs to be set to 0.

See also