OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.4.2

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.4.2
    iconOceanBase Database
    SQL - V 4.4.2
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Automatic management of materialized view logs

    Last Updated:2026-04-02 06:23:57  Updated
    Share
    What is on this page
    Limitations
    Considerations
    Related configurations
    Examples
    Example 1: Automatically create an mlog
    Example 2: Automatically update the mlog definition
    Example 3: Automatically prune an mlog
    References

    folded

    Share

    OceanBase Database supports automatic management of materialized view logs (mlogs). This feature includes the following two aspects:

    1. When you create a materialized view, OceanBase Database analyzes the dependencies of the materialized view on the base table and automatically creates the required mlogs.
    2. OceanBase Database periodically prunes mlogs in the background, deletes mlogs that are no longer referenced, and reduces the number of columns in mlogs to reduce the maintenance cost of mlogs.

    Limitations

    When you create a materialized view, an mlog is automatically created or the definition of an mlog is automatically updated only if you explicitly declare the materialized view as an incremental refresh materialized view (by specifying REFRESH FAST) or a real-time materialized view (by specifying ENABLE ON QUERY COMPUTATION).

    Considerations

    • When you update the definition of an mlog, OceanBase Database actually creates a new mlog table and replaces the original mlog. During the replacement, it performs an incremental refresh on the associated incremental refresh materialized views to transfer the incremental data from the original mlog to the materialized views. This ensures a safe replacement of the mlog. Therefore, when a base table is associated with a large number of materialized views and contains a significant amount of incremental data, updating the mlog definition may be a time-consuming operation. You need to be aware of this in advance.

    • We recommend that you do not set the mlog_trim_interval parameter to a very small value. Otherwise, the mlog may be mistakenly trimmed, and you may need to recreate or update the mlog when you create a materialized view.

    Related configurations

    OceanBase Database provides two parameters to control the automated behavior of mlogs:

    • enable_mlog_auto_maintenance: specifies whether to enable the automatic management of mlogs.
    • mlog_trim_interval: specifies the scheduling cycle of the background automatic trimming task of an mlog.

    Examples

    Enable mlog auto-maintenance.

    Note

    In OceanBase Database V4.4.2, for a new tenant, the default value of the enable_mlog_auto_maintenance parameter is True, which means that the mlog auto-maintenance feature is enabled by default. For a tenant upgraded from a previous version of OceanBase Database (V4.4.2 or earlier), the default value of the enable_mlog_auto_maintenance parameter is False, which means that the mlog auto-maintenance feature is disabled by default.

    obclient> ALTER SYSTEM SET enable_mlog_auto_maintenance = True;
    

    Example 1: Automatically create an mlog

    1. Create a table named test_tbl1.

      obclient> CREATE TABLE test_tbl1(col1 INT, col2 INT, col3 INT);
      
    2. Create an incremental refresh materialized view named mv_test_tbl1 on the test_tbl1 table. OceanBase Database automatically creates an mlog for the col2 column in the test_tbl1 table.

      obclient> CREATE MATERIALIZED VIEW mv_test_tbl1
          REFRESH FAST
          AS SELECT
                 col2,
                 count(*) cnt
             FROM test_tbl1
             GROUP BY col2;
      
    3. Query the information about the materialized view log of the test_tbl1 table. The query result is as follows:

      obclient> DESC mlog$_test_tbl1;
      

      The query result is as follows:

      +------------+-----------------+------+------+---------+-------+
      | FIELD      | TYPE            | NULL | KEY  | DEFAULT | EXTRA |
      +------------+-----------------+------+------+---------+-------+
      | COL2       | NUMBER(38)      | YES  | NULL | NULL    | NULL  |
      | SEQUENCE$$ | BIGINT(20)      | NO   | PRI  | NULL    | NULL  |
      | DMLTYPE$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | OLD_NEW$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | M_ROW$$    | BIGINT UNSIGNED | NO   | PRI  | NULL    | NULL  |
      +------------+-----------------+------+------+---------+-------+
      5 rows in set
      

    Example 2: Automatically update the mlog definition

    1. Create a table named test_tbl2.

      obclient> CREATE TABLE test_tbl2(col1 INT, col2 INT, col3 INT);
      
    2. Create an incremental refresh materialized view named mv1_test_tbl2 on the test_tbl2 table. OceanBase Database automatically creates an mlog for the col2 column in the test_tbl2 table.

      obclient> CREATE MATERIALIZED VIEW mv1_test_tbl2
          REFRESH FAST
          AS SELECT
                 col2,
                 count(*) cnt
             FROM test_tbl2
             GROUP BY col2;
      
    3. Query the information about the materialized view log of the test_tbl2 table. The query result is as follows:

      obclient> DESC mlog$_test_tbl2;
      

      The query result is as follows:

      +------------+-----------------+------+------+---------+-------+
      | FIELD      | TYPE            | NULL | KEY  | DEFAULT | EXTRA |
      +------------+-----------------+------+------+---------+-------+
      | COL2       | NUMBER(38)      | YES  | NULL | NULL    | NULL  |
      | SEQUENCE$$ | BIGINT(20)      | NO   | PRI  | NULL    | NULL  |
      | DMLTYPE$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | OLD_NEW$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | M_ROW$$    | BIGINT UNSIGNED | NO   | PRI  | NULL    | NULL  |
      +------------+-----------------+------+------+---------+-------+
      5 rows in set
      
    4. Create an incremental refresh materialized view named mv2_test_tbl2 on the test_tbl2 table. OceanBase Database detects that the current mlog table contains only the col2 column and updates the mlog definition to add the col3 column to the mlog table.

      obclient> CREATE MATERIALIZED VIEW mv2_test_tbl2
          REFRESH FAST
          AS SELECT
              col3,
              count(*) cnt
          FROM test_tbl2
          GROUP BY col3;
      
    5. Query the information about the materialized view log of the test_tbl2 table. The query result is as follows:

      obclient> DESC mlog$_test_tbl2;
      

      The query result is as follows:

      +------------+-----------------+------+------+---------+-------+
      | FIELD      | TYPE            | NULL | KEY  | DEFAULT | EXTRA |
      +------------+-----------------+------+------+---------+-------+
      | COL2       | NUMBER(38)      | YES  | NULL | NULL    | NULL  |
      | COL3       | NUMBER(38)      | YES  | NULL | NULL    | NULL  |
      | SEQUENCE$$ | BIGINT(20)      | NO   | PRI  | NULL    | NULL  |
      | DMLTYPE$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | OLD_NEW$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | M_ROW$$    | BIGINT UNSIGNED | NO   | PRI  | NULL    | NULL  |
      +------------+-----------------+------+------+---------+-------+
      6 rows in set
      

    Example 3: Automatically prune an mlog

    1. Create a table named test_tbl3.

      obclient> CREATE TABLE test_tbl3(col1 INT, col2 INT, col3 INT);
      
    2. Create an incremental refresh materialized view named mv1_test_tbl3 on the test_tbl3 table. OceanBase Database automatically creates an mlog for the col2 column in the test_tbl3 table.

      obclient> CREATE MATERIALIZED VIEW mv1_test_tbl3
          REFRESH FAST
          AS SELECT
                 col2,
                 count(*) cnt
             FROM test_tbl3
             GROUP BY col2;
      
    3. Create an incremental refresh materialized view named mv2_test_tbl3 on the test_tbl3 table. OceanBase Database detects that the current mlog table contains only the col2 column and updates the mlog definition to add the col3 column to the mlog table.

      obclient> CREATE MATERIALIZED VIEW mv2_test_tbl3
          REFRESH FAST
          AS SELECT
              col3,
              count(*) cnt
          FROM test_tbl3
          GROUP BY col3;
      
    4. Query the information about the materialized view log of the test_tbl3 table. The query result is as follows:

      obclient> DESC mlog$_test_tbl3;
      

      The query result is as follows:

      +------------+-----------------+------+------+---------+-------+
      | FIELD      | TYPE            | NULL | KEY  | DEFAULT | EXTRA |
      +------------+-----------------+------+------+---------+-------+
      | COL2       | NUMBER(38)      | YES  | NULL | NULL    | NULL  |
      | COL3       | NUMBER(38)      | YES  | NULL | NULL    | NULL  |
      | SEQUENCE$$ | BIGINT(20)      | NO   | PRI  | NULL    | NULL  |
      | DMLTYPE$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | OLD_NEW$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | M_ROW$$    | BIGINT UNSIGNED | NO   | PRI  | NULL    | NULL  |
      +------------+-----------------+------+------+---------+-------+
      6 rows in set
      
    5. Modify the mlog pruning interval to observe the pruning result faster.

      obclient> ALTER SYSTEM SET mlog_trim_interval = '5s';
      
    6. Drop the mv1_test_tbl3 materialized view.

      obclient> DROP MATERIALIZED VIEW mv1_test_tbl3;
      
    7. Wait for 5 seconds and query the information about the materialized view log of the test_tbl3 table. The query result is as follows:

      obclient> DESC mlog$_test_tbl3;
      

      The query result is as follows:

      +------------+-----------------+------+------+---------+-------+
      | FIELD      | TYPE            | NULL | KEY  | DEFAULT | EXTRA |
      +------------+-----------------+------+------+---------+-------+
      | COL3       | NUMBER(38)      | YES  | NULL | NULL    | NULL  |
      | SEQUENCE$$ | BIGINT(20)      | NO   | PRI  | NULL    | NULL  |
      | DMLTYPE$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | OLD_NEW$$  | VARCHAR2(1 )    | YES  | NULL | NULL    | NULL  |
      | M_ROW$$    | BIGINT UNSIGNED | NO   | PRI  | NULL    | NULL  |
      +------------+-----------------+------+------+---------+-------+
      5 rows in set
      
    8. Drop the mv2_test_tbl3 materialized view.

      obclient> DROP MATERIALIZED VIEW mv2_test_tbl3;
      
    9. Wait for 5 seconds and query the information about the materialized view log of the test_tbl3 table. The query result is as follows:

      obclient> DESC mlog$_test_tbl3;
      

      The query result is as follows:

      OBE-04043: object TEST_USER001.MLOG$_TEST_TBL3 does not exist
      
    10. Restore the mlog pruning interval.

      obclient> ALTER SYSTEM SET mlog_trim_interval = '1d';
      

    References

    • Overview of materialized views
    • Materialized view logs
    • Create materialized views
    • Delete materialized views

    Previous topic

    Materialized view logs
    Last

    Next topic

    Create materialized views
    Next
    What is on this page
    Limitations
    Considerations
    Related configurations
    Examples
    Example 1: Automatically create an mlog
    Example 2: Automatically update the mlog definition
    Example 3: Automatically prune an mlog
    References