Purpose
This statement is used to modify the attributes of a database (schema).
Syntax
ALTER DATABASE [database_name] [SET] alter_option [alter_option ...]
alter_option:
{READ ONLY | READ WRITE}
| DEFAULT_TABLEGROUP [=] {tablegroup_name | NULL}
Parameters
Parameter |
Description |
|---|---|
| database_name | Specifies the name of the database (schema) whose attribute is to be modified. If not specified, the current database is modified by default. |
| READ ONLY | Set the database to read-only mode. In read-only mode, regular users cannot perform DML write operations (INSERT/UPDATE/DELETE) on tables in this database, but can execute SELECT queries. |
| READ WRITE | Set the database to read/write mode (the default mode). |
| DEFAULT_TABLEGROUP tablegroup_name | Sets the default table group for a database. After modification, newly created tables in this database will automatically use the specified table group. After executing this command, the system will also change the table group attribute of all existing tables in this database to the target table group. |
| DEFAULT_TABLEGROUP NULL | Unbind the database from its default table group. |
Note
After you modify the default table group of a database, the system does not immediately align the partitions of all user tables to the same log stream. To trigger partition balancing for user tables as soon as possible, you can manually invoke the DBMS_BALANCE.TRIGGER_PARTITION_BALANCE subprogram.
Examples
Set the database to read-only/read/write
Sets the current database to read-only mode.
obclient> ALTER DATABASE READ ONLY;
Sets the current database to read/write mode.
obclient> ALTER DATABASE READ WRITE;
Set the default table group for a database
Create a table group named tg_main:
obclient> CREATE TABLEGROUP tg_main;
Set the default table group of the current database to tg_main:
obclient> ALTER DATABASE DEFAULT_TABLEGROUP = tg_main;
Unbind the current database from its default table group.
obclient> ALTER DATABASE DEFAULT_TABLEGROUP = NULL;
