# Read Historical Data Using the System Variable tidb_snapshot

+ Reads data from history versions
```
set @@tidb_snapshot="2024-05-20 16:45:00";
Query OK, 0 rows affected (0.00 sec)

select * from t;
```
+ Process historical data

-----------------------------------------------------------------

The `tidb_snapshot` variable is valid in the `SESSION` scop, and can be modified using the `SET` statement. It accepts TSO (Timestamp Oracle) and datetime. `TSO` is a globally unique time service, which is obtained from PD. The acceptable datetime format is "2024-05-20 16:45:45.999". Generally, the datetime can be set using second precision, for example "2024-05-20 16:45:26".
When the variable is set, TiDB creates a snapshot using its value as the timestamp, just for the data structure and there is no any overhead. After that, all the `SELECT` operations will read data from this snapshot.

The following code sets `tidb_snapshot` to 16:45:00 on May 20, 2024. Then `select * from t` should query the data of table t at this point in time.
```
set @@tidb_snapshot="2024-05-20 16:45:00";
Query OK, 0 rows affected (0.00 sec)

select * from t;
```

To recover data from an older version, you can use one of the following methods:
+ For simple cases, use `SELECT` after setting the `tidb_snapshot` variable and copy-paste the output, or use `SELECT ... INTO OUTFILE` and then use `LOAD DATA` to import the data later on.
+ Use Dumpling to export a historical snapshot. Dumpling performs well in exporting larger sets of data.
