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 afterPutDatabaseSettingsOperation
to apply new settings because configurations are loaded on startup. See code sample below.GetDatabaseSettingsOperation
shows a dictionary of newly configured settings.
-
Database settings can also be configured via the Studio
-
After editing & saving a configuration, the change does not take effect until the database is disabled and enabled again.
Warning
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)
Parameters | Type | Description |
---|---|---|
databaseName | string |
Select database to change settings for. |
configurationSettings | Dictionary<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)
Parameters | Type | Description |
---|---|---|
databaseName | string |
Database name. |
disable | bool |
true - 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)
Parameter | Type | Description |
---|---|---|
databaseName | string |
Database name whose settings you want to retrieve. |
Return Type | Description |
---|---|
DatabaseSettings |
A 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;
}