Multi-tenancy Enterprise
Multi-tenant support in Memgraph enables users to manage multiple isolated databases within a single instance. The primary objective is to facilitate efficient resource isolation, maintain data integrity, and manage access for different clients.
Enterprise: To enable the database switch feature, you need to enable the Memgraph Enterprise license.
When multi-tenancy is enabled on Memgraph, you can utilize it in Lab in several different ways:
- Initial connection - Define the database name you want to connect to
- Switch databases - See all available databases and switch between them while connected to Memgraph
- Run queries on different databases which is really handy when you want to compare results within the same Lab session
Initial connection
When connecting to Memgraph, you can define a database name to which you want to connect. If you omit the database name, you will be connected to the default database assigned to your user.
If multi-tenancy is not configured on the Memgraph side, the database name is not used when establishing a connection.
Switch databases
When you have multiple databases, you can see all available databases by clicking on your connection in the upper left corner of the Lab status bar. You can switch your connection to another database from that view, and any query running from that point on will be executed on the newly switched database.
Queries on different databases within the same session
As seen in the previous section, you can switch databases through the UI, and that change is applied to the current active connection.
If you were to use a Cypher command from query execution:
USE DATABASE another_db;
You would see that nothing happens visually. You are still going to be on the
actual database. When using query execution to switch databases with the USE DATABASE
Cypher command, Lab actually does a temporary switch to the named
database and then returns back to the one defined by the connection.
This can still be handy, especially if you want to compare results from
different databases. For example, let’s say we have three databases: memgraph
(default), production
, and staging
.
If you were to run the following queries in query execution:
// current database is "memgraph"
MATCH (n) RETURN count(n); // data query 1) runs on database "memgraph"
USE DATABASE staging; // temporarily switches to database "staging"
MATCH (n) RETURN count(n); // data query 2) runs on database "staging"
CREATE INDEX ON :Node; // data query 3) runs on database "staging"
USE DATABASE production; // temporarily switches to database "production"
MATCH (n) RETURN count(n); // data query 4) runs on database "production"
MATCH ()-[e]->() RETURN count(e); // data query 5) runs on database "production"
// switches back to database "memgraph"
When you issue a USE DATABASE <database>
command inside query execution, all
subsequent queries will be executed against that database
until either another
USE DATABASE
command is encountered or the execution block ends, at which
point Lab switches back to the originally connected database.
It would execute 5 queries on three different databases:
- First query would return the number of nodes from database “memgraph”
- Second query would return the number of nodes from database “staging”
- Third query would create an index in database “staging”
- Fourth query would return the number of nodes from database “production”
- Fifth query would return the number of relationships from database “production”