Alter databases
You can modify standard databases using the Cypher command ALTER DATABASE
.
Syntax
Command | Syntax |
---|---|
|
|
There can be multiple
|
Alter database access mode
By default, a database has read-write access mode on creation.
The database can be limited to read-only mode on creation using the configuration settings server.databases.default_to_read_only
, server.databases.read_only
, and server.database.writable
.
For details, see the section on Configuration parameters.
A database that was created with read-write access mode can be changed to read-only.
To change it to read-only, you can use the ALTER DATABASE
command with the sub-clause SET ACCESS READ ONLY
.
Subsequently, the database access mode can be switched back to read-write using the sub-clause SET ACCESS READ WRITE
.
Altering the database access mode is allowed at all times, whether a database is online or offline.
If conflicting modes are set by the ALTER DATABASE
command and the configuration parameters, i.e. one says read-write and the other read-only, the database will be read-only and prevent write queries.
Modifying access mode is only available to standard databases and not composite databases. |
Alter database access mode to read-only
To modify the database access mode, use the following command where actors
is the database name:
ALTER DATABASE actors SET ACCESS READ ONLY
The database access mode can be seen in the access
output column of the command SHOW DATABASES
:
SHOW DATABASES yield name, access
+----------------------------+ | name | access | +----------------------------+ | "actors" | "read-only" | | "movies" | "read-write" | | "neo4j" | "read-write" | | "system" | "read-write" | +----------------------------+
Alter database access using IF EXISTS
ALTER DATABASE
commands are optionally idempotent, with the default behavior to fail with an error if the database does not exist.
Appending IF EXISTS
to the command ensures that no error is returned and nothing happens if the database does not exist.
ALTER DATABASE nonExisting IF EXISTS
SET ACCESS READ WRITE
Alter the default Cypher version of an existing database
You can change the default Cypher version of an existing database, including the system
database, using the ALTER DATABASE
command with the SET DEFAULT LANGUAGE
clause.
For example:
ALTER DATABASE movies SET DEFAULT LANGUAGE CYPHER 25
This command will change the default Cypher version of the database movies
to Cypher 25.
To view the default Cypher version of each database in the DBMS, run the command SHOW DATABASES
with the YIELD
clause and specify the defaultLanguage
column.
For example:
SHOW DATABASES YIELD name, defaultLanguage
name | defaultLanguage |
---|---|
|
|
|
|
|
|
|
|
Rows: 4 |
Setting the default language to |
Alter database topology
In a cluster environment, you can use the ALTER DATABASE
command to change the number of servers hosting a database.
For more information, see Managing databases in a cluster.
Alter database options
The ALTER DATABASE
command can be used to set or remove specific options for a database.
Key | Value | Description |
---|---|---|
|
|
Defines the level of enrichment applied to transaction logs for Change Data Capture (CDC) purposes. For details about enrichment mode, see Change Data Capture Manual → Modify a database’s CDC mode. |
The |
Modify the options set for a database
ALTER DATABASE `movies`
SET OPTION txLogEnrichment 'FULL'
The database set options can be seen in the options
output column of the command SHOW DATABASES
.
SHOW DATABASES yield name, options
name | options |
---|---|
|
|
|
|
|
|
|
|
Rows: 4 |
Remove the options set for a database
ALTER DATABASE `movies`
REMOVE OPTION txLogEnrichment
The REMOVE OPTION
clause removes the specified option from the database using the ALTER DATABASE
command.
SHOW DATABASES YIELD name, options
name | options |
---|---|
|
|
|
|
|
|
|
|
Rows: 4 |