Skip to content

Database management

Multi-database support is included in immudb server. immudb automatically creates an initial database named defaultdb.

Managing users and databases requires the appropriate privileges. A user with PermissionAdmin rights can manage everything. Non-admin users have restricted access and can only read or write databases to which they have been granted permission.

Each database can be configured with a variety of settings. While some values can be changed at any time (though it may require a database reload to take effect), following ones are fixed and cannot be changed: FileSize, MaxKeyLen, MaxValueLen, MaxTxEntries and IndexOptions.MaxNodeSize.

Database creation

This example shows how to create a new database and how to write records to it. To create a new database, use CreateDatabaseV2 method.

:::: tabs

::: tab Go <<< @/code-examples/go/database-create/main.go :::

::: tab Java

java
package io.codenotary.immudb.helloworld;

import io.codenotary.immudb4j.*;

public class App {

    public static void main(String[] args) {
        FileImmuStateHolder stateHolder = FileImmuStateHolder.newBuilder()
                    .withStatesFolder("./immudb_states")
                    .build();

        ImmuClient client = ImmuClient.newBuilder()
                    .withServerUrl("127.0.0.1")
                    .withServerPort(3322)
                    .withStateHolder(stateHolder)
                    .build();

        client.login("immudb", "immudb");
    
        client.createDatabase("db1");
    }

}

:::

::: tab Python

python
from immudb import ImmudbClient

URL = "localhost:3322"  # immudb running on your machine
LOGIN = "immudb"        # Default username
PASSWORD = "immudb"     # Default password
DB = b"defaultdb"       # Default database name (must be in bytes)

def main():
    client = ImmudbClient(URL)
    client.login(LOGIN, PASSWORD, database = DB)

    client.createDatabase("db1")

if __name__ == "__main__":
    main()

:::

::: tab Node.js

ts
import ImmudbClient from 'immudb-node'
import Parameters from 'immudb-node/types/parameters'

const IMMUDB_HOST = '127.0.0.1'
const IMMUDB_PORT = '3322'
const IMMUDB_USER = 'immudb'
const IMMUDB_PWD = 'immudb'

const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });

(async () => {
    await cl.login({ user: IMMUDB_USER, password: IMMUDB_PWD })

    const createDatabaseReq: Parameters.CreateDatabase = {
        databasename: 'myimmutabledb'
    }

    const createDatabaseRes = await cl.createDatabase(createDatabaseReq)
    console.log('success: createDatabase', createDatabaseRes)
})()

:::

::: tab .Net This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github project :::

::: tab Others If you're using another development language, please refer to the immugw option. :::

::::

Listing databases

This example shows how to list existent databases using DatabaseListV2 method.

:::: tabs

::: tab Go <<< @/code-examples/go/database-list/main.go :::

::: tab Java

java
package io.codenotary.immudb.helloworld;

import io.codenotary.immudb4j.*;

public class App {

    public static void main(String[] args) {
        FileImmuStateHolder stateHolder = FileImmuStateHolder.newBuilder()
                    .withStatesFolder("./immudb_states")
                    .build();

        ImmuClient client = ImmuClient.newBuilder()
                    .withServerUrl("127.0.0.1")
                    .withServerPort(3322)
                    .withStateHolder(stateHolder)
                    .build();

        client.login("immudb", "immudb");

        List<String> dbs = client.databases();
        // List of database names
    }

}

:::

::: tab Python This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github project :::

::: tab Node.js This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Node.js sdk github project :::

::: tab .Net This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github project :::

::: tab Others If you're using another development language, please refer to the immugw option. :::

::::

Database loading/unloading

Databases can be dynamically loaded and unloaded without having to restart the server. After the database is unloaded, all its resources are released. Unloaded databases cannot be queried or written to, but their settings can still be changed. Upon startup, the immudb server will automatically load databases with the attribute Autoload set to true. If a user-created database cannot be loaded successfully, it remains closed, but the server continues to run normally. As a default, autoloading is enabled when creating a database, but it can be disabled during creation or turned on/off at any time thereafter.

Following example shows how to load and unload a database using LoadDatabase and UnloadDatabase methods.

:::: tabs

::: tab Go <<< @/code-examples/go/database-load-unload/main.go :::

::: tab Java This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Java sdk github project :::

::: tab Python This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github project :::

::: tab Node.js This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Node.js sdk github project :::

::: tab .Net This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github project :::

::: tab Others If you're using another development language, please refer to the immugw option. :::

::::

Database settings

Database settings can be individually changed using UpdateDatabaseV2 method.

Each database can be configured with a variety of settings. While some values can be changed at any time (though it may require a database reload to take effect), following ones are fixed and cannot be changed: FileSize, MaxKeyLen, MaxValueLen, MaxTxEntries and IndexOptions.MaxNodeSize.

Note: Replication settings take effect without the need of reloading the database.

Following example shows how to update database using UpdateDatabaseV2 method.

:::: tabs

::: tab Go <<< @/code-examples/go/database-settings/main.go :::

::: tab Java This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Java sdk github project :::

::: tab Python This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github project :::

::: tab Node.js This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Node.js sdk github project :::

::: tab .Net This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github project :::

::: tab Others If you're using another development language, please refer to the immugw option. :::

::::

Configuration options

Following main database options are available:

NameTypeDescription
replicationSettingsReplication SetingsRepliation settings are described below
indexSettingsIndex SettingsIndex settings are described below
fileSizeUint32maximum file size of files on disk generated by immudb
maxKeyLenUint32maximum length of keys for entries stored in the database
maxValueLenUint32maximum length of values for entries stored in the database
maxTxEntriesUint32maximum number of entries inside one transaction
excludeCommitTimeBoolif set to true, commit time is not added to transaction headers allowing reproducible database state
maxConcurrencyUint32max number of concurrent operations on the db
maxIOConcurrencyUint32max number of concurrent IO operations on the db
txLogCacheSizeUint32size of transaction log cache
vLogMaxOpenedFilesUint32maximum number of open files for payload data
txLogMaxOpenedFilesUint32maximum number of open files for transaction log
commitLogMaxOpenedFilesUint32maximum number of open files for commit log
writeTxHeaderVersionUint32transaction header version, used for backwards compatibility
autoloadBoolif set to false, do not load database on startup

Replication settings:

NameTypeDescription
replicaBoolif true, the database is a replica of another one
masterDatabaseStringname of the database to replicate
masterAddressStringhostname of the master immudb instance
masterPortUint32tcp port of the master immudb instance
followerUsernameStringusername used to connect to the master immudb instance
followerPasswordStringpassword used to connect to the master immudb instance

Additional index options:

NameTypeDescription
flushThresholdUint32threshold in number of entries between automatic flushes
syncThresholdUint32threshold in number of entries between flushes with sync
cacheSizeUint32size of btree node cache
maxNodeSizeUint32max size of btree node in bytes
maxActiveSnapshotsUint32max number of active in-memory btree snapshots
renewSnapRootAfterUint64threshold in time for automated snapshot renewal during data scans
compactionThldUint32minimum number of flushed snapshots to enable full compaction of the index
delayDuringCompactionUint32extra delay added during indexing when full compaction is in progress
nodesLogMaxOpenedFilesUint32maximum number of files opened for nodes data
historyLogMaxOpenedFilesUint32maximum number of files opened for nodes history
commitLogMaxOpenedFilesUint32maximum number of files opened for commit log
flushBufferSizeUint32in-memory buffer size when doing flush operation
cleanupPercentageFloat% of data to be cleaned up from during next automatic flush operation

Released under the Apache 2.0 License.