-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: add doc for flashback database
#11915
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4cbe541
sql: add doc for `flashback database`
Defined2014 f335de4
Apply suggestions from code review
Defined2014 091478b
Apply suggestions from code review
Defined2014 158c3c6
refine format
ran-huang c2234bf
Apply suggestions from code review
Defined2014 9c4c543
Apply suggestions from code review
Defined2014 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: FLASHBACK DATABASE | ||
summary: TiDB 数据库中 FLASHBACK DATABASE 的使用概况。 | ||
--- | ||
|
||
# FLASHBACK DATABASE | ||
|
||
TiDB v6.4.0 引入了 `FLASHBACK DATABASE` 语法,其功能是在 Garbage Collection (GC) life time 时间内,可以用 `FLASHBACK DATABASE` 语句来恢复被 `DROP` 删除的数据库以及数据。 | ||
|
||
可以使用系统变量 [`tidb_gc_life_time`](/system-variables.md#tidb_gc_life_time-从-v50-版本开始引入) 配置数据的历史版本的保留时间(默认值是 `10m0s`)。可以使用以下 SQL 语句查询当前的 `safePoint`,即 GC 已经清理到的时间点: | ||
|
||
```sql | ||
SELECT * FROM mysql.tidb WHERE variable_name = 'tikv_gc_safe_point'; | ||
``` | ||
|
||
只要一个数据库是在 `tikv_gc_safe_point` 时间之后被 `DROP`,即可以用 `FLASHBACK DATABASE` 语法来恢复。 | ||
|
||
## 语法 | ||
|
||
```sql | ||
FLASHBACK DATABASE DBName [TO newDBName] | ||
``` | ||
|
||
### 语法图 | ||
|
||
```ebnf+diagram | ||
FlashbackDatabaseStmt ::= | ||
'FLASHBACK' DatabaseSym DBName FlashbackToNewName | ||
|
||
FlashbackToNewName ::= | ||
( 'TO' Identifier )? | ||
``` | ||
ran-huang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## 注意事项 | ||
|
||
- 如果数据库被删除的时间超过了 GC life time (`tikv_gc_safe_point`),就无法使用 `FLASHBACK DATABASE` 语句来恢复被删除的数据了,否则会返回错误。错误类似于 `ERROR 1105 (HY000): Can't find dropped database 'test' in GC safe point 2022-11-06 16:10:10 +0800 CST`。 | ||
|
||
- 不能用 `FLASHBACK DATABASE` 多次恢复同一个被删除的数据库,因为 `FLASHBACK DATABASE` 所恢复数据库的 schema ID 和原被删除数据库的 schema ID 一致,多次恢复同一数据库会导致重复的 schema ID。在 TiDB 中,所有数据库的 schema ID 必须全局唯一。 | ||
|
||
- 在开启 TiDB Binlog 时,使用 `FLASHBACK DATABASE` 需要注意以下情况: | ||
|
||
* 下游从集群也需要支持 `FLASHBACK DATABASE`。 | ||
* 从集群的 GC life time 一定要长于主集群的 GC life time。否则上下游同步存在的延迟可能也会造成下游恢复数据失败。 | ||
* 如果 TiDB Binlog 同步出错,则需要在 TiDB Binlog 中过滤掉该数据库,同时手动全量重新导入该数据库的数据。 | ||
|
||
## 示例 | ||
|
||
- 恢复被 `DROP` 删除的 `test` 数据库: | ||
|
||
```sql | ||
DROP DATABASE test; | ||
``` | ||
|
||
```sql | ||
FLASHBACK DATABASE test; | ||
``` | ||
|
||
- 恢复被 `DROP` 删除的 `test` 数据库并重命名为 `test1`: | ||
|
||
```sql | ||
DROP DATABASE test; | ||
``` | ||
|
||
```sql | ||
FLASHBACK DATABASE test TO test1; | ||
``` | ||
|
||
## MySQL 兼容性 | ||
|
||
该语句是 TiDB 对 MySQL 语法的扩展。 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是实验特性还是 GA 呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GA