Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 通过rename修改库名会不会丢失数据
【TiDB Usage Environment】Production Environment / Testing / PoC
【TiDB Version】tidb v6.1.0
【Reproduction Path】What operations were performed that caused the issue
【Encountered Issue: Will data be lost by renaming table test.t1 to test1.t1?
【Resource Configuration】
【Attachments: Screenshots / Logs / Monitoring】
Online: 4.0.16
Scenario: Due to TiCDC synchronizing data changes, and the data coming from synchronization with other databases, in some scenarios where the primary key changes, a new table is often synchronized, TiCDC is stopped, and the new and old tables are replaced through rename, then TiCDC is restarted. No data loss has been found so far.
Personal understanding: TiDB uses TiKV for storage, and the actual data has little to do with the table name. The actual record data is associated with the table ID. The table name and table ID information are all in a separate metadata key-value structure. Rename only changes the metadata, and the table ID does not change, similar to the principle of renaming an index as shown below.
You can check out the official principles of each TiDB component, which I believe will give you a deeper understanding of TiDB.
https://learn.pingcap.com/learner/course/600003
I don’t think data will be lost; the underlying logic should be associated with the table ID.
I have tested this, but with a relatively small amount of data. After renaming, the data did not change. I’m not sure if this is of any reference value.
The rename process will lock, so data should not be lost.
This is just an update to the data dictionary, a fundamental capability of the database, and it definitely cannot lose data.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.