TypeDB 3.0 is live! Get started for free.

Open a session

This guide covers session control and best practices with Studio, Console, or one of the drivers. Both Studio and Console provide automated session control, so you don’t need to open and close sessions manually. To open a session, you need to choose a session type and an existing database.

Understanding sessions

A session represents an active connection to a specific database on a TypeDB server, and it can be of two types: schema and data. The schema session type is specifically employed for Define and Undefine queries.

Open a new session

Before you begin, Make sure to create a new database using instructions from the Create a database page. To open a session to a database, you need to have a connection to the server and know the name of the database.

Studio controls transactions automatically when you run a query.

Use the Session type switch at the top toolbar to select the type of session to use to send a query. For the selector to be active, you need to connect Studio to TypeDB server and select a database from a drop-down list in the top toolbar.

TypeDB drivers provide manual session control via native API:

Open a session
let databases = DatabaseManager::new(driver);
let session = Session::new(databases.get(DB_NAME)?, SessionType::Schema)?;
rust

Where driver is an instance of a driver, connected to TypeDB, and DB_NAME is the name of the database.

After connecting to a server and opening a session, see how to open a transaction.

Close a session

Both Studio and Console manage sessions automatically.

For manual session control, use TypeDB drivers:

A session is automatically closed when the variable containing it is dropped from memory.

To explicitly close a session, use the force_close method:

Close a session
let _ = session.force_close();
rust

Session management

Session timeout

Any TypeDB Client automatically exchanges internal signals with TypeDB server to keep a session alive when it’s open. If a TypeDB server doesn’t receive this signal for a period of time bigger than the timeout (default: 30 seconds) it forcibly closes the session due to inactivity.

Schema session blocks

Only one Schema session can be open at any time. An open Schema session blocks all attempt to open a write transaction in any data session. For more information on these limitations, see the Schema integrity enforcement section on the Transactions page.

Learn more

See how to manage transactions in TypeDB.

See how to define a schema for your database.