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.3.3

    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.3.3
    iconOceanBase Database
    SQL - V 4.3.3
    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

    Flashback queries

    Last Updated:2024-12-02 03:48:29  Updated
    Share
    What is on this page
    Considerations
    Prerequisites
    Run a flashback query in MySQL mode
    Run a flashback query in Oracle mode

    folded

    Share

    OceanBase Database supports record-specific flashback queries, which allow you to obtain data of a specific historical version. You can use the AS OF SCN and AS OF TIMESTAMP clauses to perform flashback queries in Oracle mode and the AS OF SNAPSHOT clause to perform flashback queries in MySQL mode.

    OceanBase Database allows you to set the undo_retention parameter for a tenant to perform a flashback query. After you set the undo_retention parameter, you can use the flashback query feature to obtain data of multiple versions in the time range from T - undo_retention to T. The default value of the undo_retention parameter is 1800, in seconds. For more information about this parameter, see undo_retention.

    Considerations

    When you set the undo_retention parameter to perform a flashback query, note that:

    • If you set the undo_retention parameter to T0, this feature takes effect only on data generated after T - T0.

    • If the queried table is moved to the recycle bin, you must restore it from the recycle bin before you can query data in the table.

      For more information, see Restore objects from the recycle bin.

    • Assuming the current time is T, after setting undo_retention, if there were any DDL operations within the time period T - undo_retention, then:

      • For adding column operations, when performing a flashback query to view data before the operation, all newly added columns will have Default values.

      • For operations like creating tables, dropping tables, or dropping columns, when performing a flashback query to view data before the operation, the system will report an error.

    • Flashback queries require additional storage space to retain historical data. If you increase the value of the undo_retention parameter, the storage space required is increased. We recommend that you observe the change of the storage space after you increase the value of the undo_retention parameter.

    Prerequisites

    Before you set the undo_retention parameter to perform a flashback query, check whether multi-version minor compaction is enabled, namely whether the value of the undo_retention parameter is not 0. The default value of the undo_retention parameter is 1800, in seconds.

    1. Log in to the database as a tenant administrator.

      Note

      The administrator user of a MySQL user tenant is root and that of an Oracle user tenant is SYS.

      Note that you must specify the corresponding parameters in the following sample code based on your actual database configurations.

      obclient -h10.xx.xx.xx -P2883 -uroot@mysql#demo -p***** -A
      

      For more information about how to connect to a database, see Overview (MySQL mode) or Overview (Oracle mode).

    2. Modify the value of the undo_retention parameter.

      Here is an example:

      obclient [(none)]> ALTER SYSTEM SET undo_retention=900;
      

      For more information about the undo_retention parameter, see undo_retention.

    Run a flashback query in MySQL mode

    1. Log in to the database as an administrator of a MySQL user tenant.

      Note that you must specify the corresponding parameters in the following sample code based on your actual database configurations.

      obclient -h10.xx.xx.xx -P2883 -uinfo@mysql#demo -p***** -A
      

      For more information, see Overview.

    2. Perform a flashback query on a table.

      Assume that the value of the undo_retention parameter is 900 and you have a table named table1. Specify a historical point in time by using AS OF SNAPSHOT and query the status and data of the table at this point in time.

      obclient [(none)]> SELECT * FROM table1 AS OF SNAPSHOT 1597306800000000000;
      

      Here, 1597306800000000000 is a timestamp, in nanoseconds. The timestamp is the time since 08:00:00 (UTC+8) on January 1, 1970. You can convert the point in time to be queried into a timestamp based on your business needs.

      For example, if you want to perform a flashback query on table data at 16:20:00 on August 13, 2020, you can convert the time as follows:

      obclient [(none)]> SELECT time_to_usec('2020-08-13 16:20:00') * 1000;
      +--------------------------------------------+
      | time_to_usec('2022-01-01 00:00:00') * 1000 |
      +--------------------------------------------+
      |                        1597306800000000000 |
      +--------------------------------------------+
      1 row in set
      

    Run a flashback query in Oracle mode

    1. Log in to the database as an administrator of an Oracle user tenant.

      Note that you must specify the corresponding parameters in the following sample code based on your actual database configurations.

      obclient -h10.xx.xx.xx -P2883 -uinfo@oracle#demo -p***** -A
      

      For more information, see Overview.

    2. Perform a flashback query on a table.

      Assume that the value of the undo_retention parameter is 900 and you have three tables: table1, table2, and expr1. The following examples show the sample code for flashback queries in Oracle mode.

      • Specify a historical point in time by using TIMESTAMP and query the status and data of a single table at this point in time:

        obclient [SYS]> SELECT * FROM table1 AS OF TIMESTAMP TO_TIMESTAMP('2020-08-13 16:20:00','yyyy-mm-dd hh24:mi:ss');
        
      • Specify a historical point in time by using TIMESTAMP and query the status and data of the multiple tables at this point in time:

        obclient [SYS]> SELECT * FROM table1,table2 AS OF TIMESTAMP TO_TIMESTAMP('2020-08-13 16:20:00','yyyy-mm-dd hh24:mi:ss');
        
      • Specify a historical point in time by using SCN and query the status and data of a single table at this point in time:

        obclient [SYS]> SELECT * FROM table1 AS OF SCN 1597306800000000000;
        

        Here, 1597306800000000000 is a timestamp, in nanoseconds. The timestamp is the time since 08:00:00 (UTC+8) on January 1, 1970. You can convert the point in time to be queried into a timestamp based on your business needs.

        For example, if you want to perform a flashback query on table data at 16:20:00 on August 13, 2020, you can convert the time as follows:

        obclient [(none)]> SELECT (to_date('2020-08-13 16:20:00','yyyy-mm-dd hh24:mi:ss') - to_date('1970-01-01 08:00:00', 'yyyy-mm-dd hh24:mi:ss')) * 86400 * 1000 * 1000 * 1000 AS unix_nsec_timestamp FROM DUAL;
        +---------------------+
        | UNIX_NSEC_TIMESTAMP |
        +---------------------+
        | 1597306800000000000 |
        +---------------------+
        1 row in set
        

    Previous topic

    Purge the recycle bin
    Last

    Next topic

    Overview
    Next
    What is on this page
    Considerations
    Prerequisites
    Run a flashback query in MySQL mode
    Run a flashback query in Oracle mode