Skip to main content

Apply Database Configuration Settings

Use the following methods to change, save, and apply database configuration settings.

  • PutDatabaseSettingsOperation sets and saves new database configurations.
  • ToggleDatabasesStateOperation disables/enables database.
    This is used after PutDatabaseSettingsOperation to apply new settings because configurations are loaded on startup. See code sample below.
  • GetDatabaseSettingsOperation shows a dictionary of newly configured settings.

Do not modify the database settings unless you are an expert and know what you're doing.

In this page:

PutDatabaseSettingsOperation

This method sets and saves new database configurations.
To apply the new settings, use ToggleDatabasesStateOperation.

Syntax:

PutDatabaseSettingsOperation(string databaseName, Dictionary<string, string> configurationSettings)
ParametersTypeDescription
databaseNamestringSelect database to change settings for.
configurationSettingsDictionary<string, string>Pass configuration settings.
Sample:

The following sample shows how to use PutDatabaseSettingsOperation to set the database configuration.

// Configure database settings
static void PutConfigurationSettings(DocumentStore store, Dictionary<string, string> settings)
{
// Save the new settings with PutDatabaseSettingsOperation
store.Maintenance.Send(new PutDatabaseSettingsOperation(store.Database, settings));
// Disable the database
store.Maintenance.Server.Send(new ToggleDatabasesStateOperation(store.Database, true));
// Enable the database to apply new settings
store.Maintenance.Server.Send(new ToggleDatabasesStateOperation(store.Database, false));
}

ToggleDatabasesStateOperation

Use ToggleDatabasesStateOperation to disable/enable the database, e.g. to apply new settings after PutDatabaseSettingsOperation is called.

Syntax:

ToggleDatabasesStateOperation(string databaseName, bool disable)
ParametersTypeDescription
databaseNamestringDatabase name.
disablebooltrue - disable the database
false" - enable the database
Sample:

The following sample uses ToggleDatabasesStateOperation to disable and then enable the database, effectively reloading the database to apply a new configuration.

// Configure database settings
static void PutConfigurationSettings(DocumentStore store, Dictionary<string, string> settings)
{
// Save the new settings with PutDatabaseSettingsOperation
store.Maintenance.Send(new PutDatabaseSettingsOperation(store.Database, settings));
// Disable the database
store.Maintenance.Server.Send(new ToggleDatabasesStateOperation(store.Database, true));
// Enable the database to apply new settings
store.Maintenance.Server.Send(new ToggleDatabasesStateOperation(store.Database, false));
}

GetDatabaseSettingsOperation

Use GetDatabaseSettingsOperation to retrieve a dictionary of the changes made in the database settings. Only settings that have changed will be retrieved.

Syntax:

GetDatabaseSettingsOperation(string databaseName)
ParameterTypeDescription
databaseNamestringDatabase name whose settings you want to retrieve.
Return TypeDescription
DatabaseSettingsA key/value dictionary of database settings.
Only settings that have changed are retrieved.

DatabaseSettings:

public class DatabaseSettings
{
public Dictionary<string, string> Settings { get; set; }
}

Sample:

Get a dictionary of newly configured settings with GetDatabaseSettingsOperation.

static DatabaseSettings GetConfigurationSettings(DocumentStore store)
{
var settings = store.Maintenance.Send(new GetDatabaseSettingsOperation(store.Database));
Assert.NotNull(settings);
return settings;
}