Vitess’s OverrideDatabaseConfig setting lets you dynamically change database connection parameters per keyspace, a powerful tool for fine-tuning performance and behavior without touching your application code.

Let’s see it in action. Imagine you have a user_data keyspace and you want to increase the max_connections for its underlying MySQL instance to 200, while leaving other keyspaces at their default.

Here’s what the relevant part of your vt_tablet command might look like, or a configuration file it reads:

{
  "tablet": {
    "tablet_type": "REPLICA",
    "tablet_hostname": "your-tablet-hostname",
    "tablet_port": 15999,
    "grpc_port": 15998,
    "http_port": 15997,
    "keyspace": "user_data",
    "shard": "0",
    "cell": "your-cell",
    "vt_hostname": "your-vt-hostname",
    "tablet_manager_hostname": "your-tablet-manager-hostname",
    "tablet_manager_port": 15994,
    "primary_tablet_type": "PRIMARY",
    "semi_sync_enabled": true,
    "semi_sync_master_timeout_seconds": 30,
    "semi_sync_replica_timeout_seconds": 30,
    "data_dir": "/path/to/vitess/data",
    "mysql_server_port": 3306,
    "mysql_server_bind_address": "127.0.0.1",
    "mysql_server_socket_path": "/path/to/mysql.sock",
    "mysql_server_user": "vt_user",
    "mysql_server_password_file": "/path/to/vt_user.passwd",
    "mysql_server_charset": "utf8mb4",
    "mysql_server_strict_sql_mode": true,
    "mysql_server_max_connections": 100, // Default for other keyspaces
    "override_database_config": {
      "user_data": {
        "mysql_server_max_connections": 200,
        "mysql_server_max_heap_table_size": 67108864,
        "mysql_server_max_heap_table_size": 67108864
      }
    }
  }
}

This setting is defined within the tablet section of your Vitess configuration. The override_database_config is a map where keys are keyspace names, and values are themselves maps of database configuration parameters you wish to override. In this example, for the user_data keyspace, we’re setting mysql_server_max_connections to 200. This value will be applied to the underlying MySQL instance serving this specific keyspace, while any other keyspaces on the same tablet will continue to use the mysql_server_max_connections value defined directly in the tablet section (which is 100 in this case).

The real power of OverrideDatabaseConfig lies in its ability to adapt your database’s behavior to the specific needs of different datasets or application workloads. For instance, a logging keyspace might benefit from a much lower max_connections to prevent resource exhaustion, while a high-throughput transaction keyspace could warrant a higher max_connections and potentially larger buffer sizes like innodb_buffer_pool_size. You can also override parameters like innodb_flush_log_at_trx_commit to trade durability for performance, or wait_timeout to control how long idle connections persist. The available parameters are a subset of those you’d find in a MySQL my.cnf or my.ini file.

When a Vitess tablet starts up, it reads its primary configuration. If override_database_config is present, it merges these overrides into the base configuration. Crucially, these overrides are applied per keyspace. So, if a tablet serves multiple keyspaces, each can have its own distinct set of database parameters applied to its respective MySQL instance. This is achieved by Vitess dynamically generating and applying configuration snippets to the mysqld process it manages for each keyspace. It doesn’t modify the global my.cnf but rather injects specific settings into the mysqld startup or runtime configuration for the relevant shard.

A common misconception is that this setting applies to the entire Vitess cluster. It’s important to remember that OverrideDatabaseConfig is a tablet-specific setting. To apply an override across multiple tablets, you need to configure it on each relevant tablet. This allows for granular control, enabling you to tailor configurations based on the specific load and resource characteristics of individual tablets and the keyspaces they serve. You can also use it to temporarily adjust settings during peak loads or for A/B testing different database configurations without downtime.

The core mechanism involves Vitess’s tablet startup process. When vttablet initializes, it reads its configuration. If override_database_config is defined, it iterates through the provided keyspace-to-config mappings. For each keyspace, it constructs a temporary configuration that includes the base tablet settings plus the specific overrides for that keyspace. This temporary configuration is then used to configure the mysqld process associated with that keyspace/shard. This means that if you change the override_database_config on a running tablet, you will likely need to restart the vttablet process for the changes to take effect, as these are primarily applied during initialization.

Beyond simple parameter tuning, this feature can be leveraged to manage different MySQL versions or feature sets for distinct keyspaces if your infrastructure supports it, though direct version management is typically handled at the deployment level. The flexibility it offers means you can experiment with advanced MySQL tuning parameters like sort_buffer_size or join_buffer_size on a per-keyspace basis to optimize specific query patterns without impacting other parts of your application.

After successfully overriding database configurations, the next challenge you might encounter is ensuring these configurations are correctly reflected in your query performance metrics, leading you to explore Vitess’s VReplication metrics for deep dives into data movement and consistency.

Want structured learning?

Take the full Planetscale course →