External storage is an abstraction for storing the wiki's content (ie. what would normally go into the text table) outside the normal database, possibly with some kind of compression applied. Some extensions (such as StructuredDiscussions) can use external storage directly for storing other kinds of data.
The contents of external storage are addressed with an URL in the form
<protocol>://<location>/<object name>, with the protocol determining what type of storage should be used. Pre-1.32 these URLs were stored in the
old_text field of the text table, with
old_flags set to external; since 1.32 they are stored in the
content_address field of the content table.
The main class for interacting with external storage is
insert or (more typically)
insertToDefault to store a piece of data and receive the URL at which it was stored; that URL can be used with
fetchFromURL to retrieve the data.
ExternalStore interacts with the subclass corresponding with the protocol.
ExternalStoreDB, which is the commonly used one, differs from the others in that it provides special handling when the stored data is a serialized subclass; such objects can be retrieved with
<protocol>://<location>/<object name>/<item id>, in which case the store will unserialize the object and get the appropriate item (by calling
getItem on it).
In practice, you should avoid using
ExternalStorage directly most of the time, and use (or an even higher-level abstraction such as ) instead.
$wgExternalStores = [ 'DB' ]; $wgExternalServers = [ 'demoCluster' => [ [ 'host' => 'master.example.org', 'user' => 'userM', 'password' =>'pwdM', 'dbname' => 'dbM', 'type' => "mysql", 'load' => 1 ], [ 'host' => 'slave1.example.org', 'user' => 'userS1', 'password' =>'pwdS1', 'dbname' => 'dbS1', 'type' => "mysql", 'load' => 1 ], [ 'host' => 'slave2.example.org', 'user' => 'userS2', 'password' =>'pwdS2', 'dbname' => 'dbS2', 'type' => "mysql", 'load' => 1 ], ] ]; $wgDefaultExternalStore = [ 'DB://demoCluster' ];
- The Manual:$wgExternalStores line states that a
DBexternal store can be used. (The
DBpart is not an arbitrary name that can be adjusted. It has to be
DB.) This corresponds to the
ExternalStoreMediumsubclass used, and the protocol of the blob address.
- The Manual:$wgExternalServers line states all the usable clusters with all usable nodes of a cluster. The top-level array's keys denote a cluster's name (The above example defines only one cluster. It has the name
demoCluster). The value to those keys are again arrays. They hold the specifications of the individual nodes. The first node is consider the master. All writes to the database are performed through this master node. Zero or more slave nodes may follow. (In the above example, you find two slave nodes). Each node may have its own
type, as shown in the example. The
loadparameter allows to specify how much of the load should pass through this note.
- The Manual:$wgDefaultExternalStore line holds those external stores that may be used for storage of new text. If you omit this line, the external store will be read-only and new texts will go into the default database (i.e.: the same database holding page, revision, image data; not the cluster).
For a multi-master wiki farm setup (like Wikimedia), consider using LBFactory_Multi instead.
For the above configuration example, you would have to:
- Create the database
dbMon the host
- Run the
maintenance/storage/blobs.sqlSQL-script on the on the database
dbMon the host
master.example.org. Do not use
maintainance/sql.phpfor this task, as it will add the required tables to your default database (i.e.: the database holding page, revision, image data) and not to
dbM. If you are not sure how to run the SQL-script on the database
dbMon the host
master.example.org, please consult your database documentation.
- Set up replication (consult your database's documentation on how to set up replication) towards
dbS1on the host
- Set up replication towards
dbS2on the host
There are several maintenance scripts for moving content to the external store: