Server rental store

$wgDBtype

# Understanding and Configuring $wgDBtype in MediaWiki

This article provides a comprehensive overview of the `$wgDBtype` configuration variable in MediaWiki 1.40, aimed at newcomers to MediaWiki server administration. It details what `$wgDBtype` does, supported database types, configuration considerations, and troubleshooting tips. Properly configuring this variable is critical for a stable and performant wiki.

What is $wgDBtype?

`$wgDBtype` is a global PHP variable within the `LocalSettings.php` file that specifies the type of database backend MediaWiki will use to store its data. MediaWiki supports a variety of database systems, each with its own strengths and weaknesses. Selecting the appropriate database is crucial for performance, scalability, and maintainability. Incorrectly setting `$wgDBtype` will lead to errors and a non-functional wiki. It is one of the very first configurations you must get correct. See Manual:Configuration settings for more general information.

Supported Database Types

MediaWiki 1.40 officially supports the following database types. Each has its own dependencies and configuration nuances, detailed below.

Database Type Description Common Use Cases Performance Characteristics
MySQL/MariaDB The most commonly used database for MediaWiki. Mature, well-documented, and widely available. Small to large wikis, most general use cases. Generally good performance, especially with proper indexing and caching. | PostgreSQL A powerful, open-source object-relational database system. Known for its data integrity and advanced features. Large wikis, wikis requiring high data integrity, complex queries. Excellent performance, particularly with complex queries, but may require more tuning. | SQLite A self-contained, serverless, zero-configuration, transactional SQL database engine. Small wikis, testing environments, single-user wikis. Suitable for very small datasets, but performance degrades rapidly with scale. Not recommended for production.

Configuration Details

After selecting a database type, you must configure the `$wgDBtype` variable in your `LocalSettings.php` file. You will also need to define other database-related variables. Here's a breakdown for each supported type:

MySQL/MariaDB

```php $wgDBtype = 'mysql'; $wgDBserver = 'localhost'; // Or the IP address of your MySQL server $wgDBname = 'your_database_name'; $wgDBuser = 'your_database_user'; $wgDBpassword = 'your_database_password'; $wgDBport = 3306; // Default port, change if needed ```

Refer to Manual:Database setup for more comprehensive MySQL/MariaDB configuration. Consider using a Database replication setup for larger wikis to improve read performance and provide redundancy.

PostgreSQL

```php $wgDBtype = 'pgsql'; $wgDBserver = 'localhost'; // Or the IP address of your PostgreSQL server $wgDBname = 'your_database_name'; $wgDBuser = 'your_database_user'; $wgDBpassword = 'your_database_password'; $wgDBport = 5432; // Default port, change if needed ```

For PostgreSQL, ensure the `pg_hba.conf` file is correctly configured to allow access from the MediaWiki server. See Manual:PostgreSQL for detailed instructions. Proper Database indexing is essential for PostgreSQL performance.

SQLite

```php $wgDBtype = 'sqlite'; $wgDBserver = '/path/to/your/database.sqlite'; // Full path to the SQLite database file ```

SQLite is simple to set up, but remember its limitations. It is generally unsuitable for wikis with more than a few users. Ensure the web server user has write access to the SQLite database file. See Manual:SQLite for more information.

Database Character Sets and Collations

Choosing the correct character set and collation is vital for supporting multiple languages and ensuring proper data storage. UTF-8 is the recommended character set for MediaWiki.

Database Type Recommended Character Set Recommended Collation
MySQL/MariaDB utf8mb4 utf8mb4_unicode_ci | PostgreSQL UTF8 en_US.UTF-8 (or your preferred locale) | SQLite UTF-8 NOCASE (optional, for case-insensitive searches)

Incorrect character set settings can lead to data corruption and display issues. Refer to the database documentation for instructions on setting these values. See Manual:Internationalization and localization for wiki specific details.

Troubleshooting $wgDBtype Issues

If you encounter errors related to the database, here are some common troubleshooting steps:

⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️