Toggle Databases State Operation
(Enable / Disable)



Enable/Disable database from the Client API

Enable database:

# Define the toggle state operation
# specify the database name & pass 'False' to enable
enable_database_op = ToggleDatabasesStateOperation("Northwind", disable=False)

# To enable multiple databases use:
# enable_database_op = ToggleDatabasesStateOperation.from_multiple_names(["DB1", "DB2", ...], disable=False)

# Execute the operation by passing it to maintenance.server.send
toggle_result = store.maintenance.server.send(enable_database_op)

Disable database:

# Define the toggle state operation
# specify the database name(s) & pass 'True' to disable
disable_database_op = ToggleDatabasesStateOperation("Northwind", disable=True)

# To disable multiple databases use:
# enable_database_op = ToggleDatabasesStateOperation.from_multiple_names(["DB1", "DB2", ...], disable=True)

# Execute the operation by passing it to maintenance.server.send
toggle_result = store.maintenance.server.send(disable_database_op)

Syntax:

class ToggleDatabasesStateOperation(ServerOperation[DisableDatabaseToggleResult]):
    def __init__(self, database_name: str, disable: bool): ...
    @classmethod
    def from_multiple_names(cls, database_names: List[str], disable: bool): ...
Parameter Type Description
database_name str Name of database for which to toggle state
database_names str[] List of database names for which to toggle state
disable bool True - request to disable the database(s)
False- request to enable the database(s)

class DisableDatabaseToggleResult:
    def __init__(
        self, disabled: bool = None, name: str = None, success: bool = None, reason: str = None
    ) -> None:
        self.disabled = disabled  # Is database disabled
        self.name = name  # Name of the database
        self.success = success  # Has request succeeded
        self.reason = reason  # Reason for success or failure

Disable database via the file system

It may sometimes be useful to disable a database manually, through the file system.

  • To manually disable a database:

    • Place a file named disable.marker in the database directory.
    • The disable.marker file can be empty,
      and can be created by any available method, e.g. using the File Explorer, a terminal, or code.
  • Attempting to use a manually disabled database will generate the following exception:

     Unable to open database: '{DatabaseName}', 
     it has been manually disabled via the file: '{disableMarkerPath}'. 
     To re-enable, remove the disable.marker and reload the database.
    
  • To enable a manually disabled database:

    • First, remove the disable.marker file from the database directory.
    • Then, reload the database.