简体   繁体   中英

Truncated a table in postgresql. How to recover it back?

Truncate table tablename;

How to recover it back in dbeaver

You cannot. See doc: http://www.postgresql.org/docs/9.1/static/sql-truncate.html

It has the same effect as an unqualified DELETE on each table, but since it does not actually scan the tables it is faster. Furthermore, it reclaims disk space immediately, rather than requiring a subsequent VACUUM operation. This is most useful on large tables.

The space is returned to OS, it could be occupied by new data etc.

Tuncate uses file-level operations to delete the data, and this has a number of implications:

  1. On commit you cannot recover
  2. This is not MVCC safe. In other words, other concurrent transactions see the table as empty despite transaction isolation levels that should let them see the old rows.

This means you basically have to recover from backup and this is a great case to use to warn that backups are about more than hardware failure. They are also there in case of administrator error (and that is why replication is not a backup).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM