Skip to content

docs: document database-level read-only mode - #24769

Open
expxiaoli wants to merge 5 commits into
pingcap:masterfrom
expxiaoli:read_only
Open

expxiaoli wants to merge 5 commits into
pingcap:masterfrom
expxiaoli:read_only

Conversation

@expxiaoli

@expxiaoli expxiaoli commented Nov 26, 2026 •

Copy link
Copy Markdown

What is changed, added, or deleted? (Required)

Document database-level read-only mode for migration cutover and data validation:

  • Add a feature guide covering read-only state changes, transaction draining, SQL restrictions, explicit privilege bypass, MySQL compatibility, and interactions with import, backup, restore, and replication tools.
  • Add the INFORMATION_SCHEMA.SCHEMATA_EXTENSIONS reference and query example.
  • Update ALTER DATABASE, SHOW CREATE DATABASE, privilege descriptions, system-variable cross-references, and navigation entries.

The release-8.5 documentation assumes that pingcap/tidb#73801 has been merged, including SQL restoration of sequences in read-only databases. The first release version remains a TODO for confirmation.

Validation: Markdown formatting, internal links, link anchors, new-page metadata, and git diff --check passed.

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)

What is the related PR or file link(s)?

AI agent involvement

  • The changes in this PR were primarily made by an AI agent on behalf of the PR author.

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

Summary by CodeRabbit

  • Documentation
    • Added guidance for database-level read-only mode, including how to enable and check it, its effects on transactions and SQL operations, privilege requirements, compatibility limits, interactions with TiDB tools, and recovery steps.
    • Documented the READ ONLY option for ALTER DATABASE, its supported values, and examples for enabling read-only mode and restoring write access.
    • Added documentation for INFORMATION_SCHEMA.SCHEMATA_EXTENSIONS, including its columns, database settings, and a query example, with navigation links to related pages.
    • Clarified how database-level read-only mode interacts with privileges and cluster-wide restrictions, and how it appears in SHOW CREATE DATABASE output.

@expxiaoli expxiaoli added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Nov 26, 2026
@ti-chi-bot ti-chi-bot Bot added the first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. label Nov 26, 2026
@ti-chi-bot

ti-chi-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

In response to a cherrypick label: @expxiaoli once the present PR merges, I will cherry-pick it on top of release-8.5 in a new PR and assign it to you.

@ti-chi-bot

ti-chi-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign tangenta for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added missing-translation-status This PR does not have translation status info. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

The documentation adds coverage for database-level read-only mode, including SQL controls, transaction behavior, restrictions, privileges, tool interactions, and metadata reporting.

Changes: Database-Level Read-Only Mode

Layer / File(s) Summary
SQL controls and transition behavior
TOC.md, database-read-only.md, sql-statements/sql-statement-alter-database.md, sql-statements/sql-statement-show-create-database.md
Documents how to enable, check, and disable database-level read-only mode. Covers transaction behavior and the read-only setting in SHOW CREATE DATABASE output.
Restrictions and privilege behavior
database-read-only.md, privilege-management.md, system-variables.md
Documents SQL restrictions, bypass privilege requirements, cluster-wide read-only restrictions, batch-DML behavior, and interactions with TiDB tools.
Metadata and documentation navigation
information-schema/information-schema-schemata-extensions.md, information-schema/information-schema.md, TOC.md, database-read-only.md
Documents SCHEMATA_EXTENSIONS, its OPTIONS values, an example, and related navigation links.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: qiancai, doc-claw-bot, lilin90

Merge Risk: Low · previous review e6e53

The new read-only mode documentation is mostly complete. Before publishing, state the first supported release and qualify the PITR statement for existing target databases, so readers do not rely on read-only protection that may not be present.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the primary change: documentation for database-level read-only mode. The changeset adds a feature guide for that mode and updates related references, so the title matches the main cha…
Description check Passed The description follows the template sections: changes made, TiDB version selection, related PR links, and AI agent involvement. It states the purpose (migration cutover and data validation), lists th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the primary change: documentation for database-level read-only mode. The changeset adds a feature guide for that mode and updates related references, so the title matches the main change.

Full details: Description check

Explanation

The description follows the template sections: changes made, TiDB version selection, related PR links, and AI agent involvement. It states the purpose (migration cutover and data validation), lists the changed areas, and gives the v8.5 dependency on pingcap/tidb#73801 and validation results. The first release version is still a TODO. The template's first-time contributor checklist is omitted, which is non-critical.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: pingcap/docs
  • Branch: master
  • File: .coderabbit.yaml
  • Commit: 4e25f10
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 61ce743d-c0bf-4346-9952-24a92ae15c90
Commits

Reviewing files that changed from the base of the PR and between 4e25f10 and 0ddb06f.

Files selected for processing: 8

  • TOC.md
  • database-read-only.md
  • information-schema/information-schema-schemata-extensions.md
  • information-schema/information-schema.md
  • privilege-management.md
  • sql-statements/sql-statement-alter-database.md
  • sql-statements/sql-statement-show-create-database.md
  • system-variables.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread database-read-only.md

## Prerequisites

- All TiDB nodes must support this feature before you enable it or restore read-only database metadata.

@coderabbitai coderabbitai Bot Nov 26, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Identify the first supported release.

This prerequisite does not tell users which TiDB version supports the feature. They cannot use it to plan an upgrade or restore. Confirm the first release that includes the feature and the sequence restore fix, then state it here. The feature was merged into the release-8.5 branch on November 24, 2026. (github.com)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that the first supported release needs to be stated before publication. The exact release version is still awaiting confirmation, so the existing explicit TODO is retained for now. Merging the feature into release-8.5 alone does not establish which released patch version includes it. The feature and the SQL sequence restore fix need to be checked separately; if their first supported versions differ, the documentation should distinguish them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@expxiaoli A merge into release-8.5 alone does not establish a patch release. Before publication, confirm the first supported release for the feature and the SQL sequence restore fix separately. If they differ, document both versions.

I’m not marking the finding as addressed while the versions remain unconfirmed.


Learnings added

Learnt from: expxiaoli
Repo: pingcap/docs PR: 24769
File: database-read-only.md:16-16
Timestamp: 2026-11-27T07:38:59.738Z
Learning: Within repository "pingcap/docs", only for files matching one of ["database-read-only.md"]: When documenting the first supported TiDB release for database-level read-only mode in `database-read-only.md`, verify the feature and the SQL sequence restore fix separately. A merge into `release-8.5` alone does not establish the released patch version. If their first supported versions differ, document both.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

Comment thread database-read-only.md Resolved
@expxiaoli

Copy link
Copy Markdown
Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: pingcap/docs
  • Branch: master
  • File: .coderabbit.yaml
  • Commit: 4e25f10
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5cff8c94-4352-4c3c-9cf4-f8e4b9d0e896
Commits

Reviewing files that changed from the base of the PR and between 4e25f10 and 0ddb06f.

Files selected for processing: 8

  • TOC.md
  • database-read-only.md
  • information-schema/information-schema-schemata-extensions.md
  • information-schema/information-schema.md
  • privilege-management.md
  • sql-statements/sql-statement-alter-database.md
  • sql-statements/sql-statement-show-create-database.md
  • system-variables.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread TOC.md Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: pingcap/docs
  • Branch: master
  • File: .coderabbit.yaml
  • Commit: 4e25f10
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 4e3c9a8f-9597-4031-a6be-4dce4ca7f3e8
Commits

Reviewing files that changed from the base of the PR and between 0ddb06f and f59a816.

Files selected for processing: 1

  • database-read-only.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread database-read-only.md Resolved
Comment thread database-read-only.md Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: pingcap/docs
  • Branch: master
  • File: .coderabbit.yaml
  • Commit: 4e25f10
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: fcf3987b-ba85-4dcd-ae3c-7c51d85042f9
Commits

Reviewing files that changed from the base of the PR and between f59a816 and e6e53b6.

Files selected for processing: 1

  • database-read-only.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Comment thread database-read-only.md Resolved

@wjhuang2016 wjhuang2016 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the read-only transition and rollback, privilege enforcement, SCHEMATA_EXTENSIONS output, batch DML, and restore behavior against the merged TiDB implementation and its tests. The Markdown, links, and anchors passed CI.

One P2 remains for the release-8.5 documentation: the guide promises SQL restoration of sequences into read-only databases while the required fix is still open. The table should condition that behavior on a release that includes the fix.

Comment thread database-read-only.md
| Tool | Behavior |
| --- | --- |
| TiDB Lightning | Physical imports using the `local` backend can write directly to TiKV into existing tables despite read-only mode. Control these imports separately. Logical imports obey SQL restrictions. |
| BR and SQL `BACKUP` / `RESTORE` | Snapshot restore preserves backed-up read-only metadata when it creates a database. If the target database already exists, restore retains its current read-only setting. Authorized restores can restore tables and sequences into read-only databases; ordinary writes to read-only databases remain restricted afterward. If you require read-only protection during and after restoring to an existing database, run `ALTER DATABASE ... READ ONLY = 1` and wait for it to complete before starting the restore. If the target database is writable, restored tables can accept ordinary writes before read-only protection takes effect. After restoring, check `INFORMATION_SCHEMA.SCHEMATA_EXTENSIONS`. PITR retains the current read-only setting of reused target databases; do not assume it matches the source setting at the selected time. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Qualify SQL sequence restore for release-8.5. If an operator follows this row and enables READ ONLY on an existing target before restoring a snapshot containing a sequence, SQL RESTORE can fail while restoring the sequence value. In the release-8.5 feature commit, CreateTablePostRestore grants a schema-scoped bypass on the restore session, but tidbGlueSession.Execute dispatches SETVAL through a pooled session that lacks that bypass. The fix is merged on master, and its release-8.5 backport is still open. Please make the sequence guarantee conditional on a release that contains the fix, especially for the 8.5 cherry-pick. Restore path · SQL execution · 8.5 backport.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is already merged on master via pingcap/tidb#73748. The PR description explicitly states that the release-8.5 documentation assumes pingcap/tidb#73801 has been merged. Before cherry-picking the documentation to release-8.5 and publishing it, we will confirm that the target release includes the fix. I will keep the document body unchanged for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. missing-translation-status This PR does not have translation status info. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants