database 清空数据库是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2128336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does it mean to vacuum a database?
提问by An???drew
As referenced by this Firefox bug, what does the act of vacuuming a database accomplish? Is this operation supported by all modern database software, or only certain ones?
正如这个 Firefox bug所引用的,清空数据库的行为有什么作用?所有现代数据库软件都支持此操作,还是仅某些软件支持?
回答by edgar.holleis
Databases that use MVCCto isolate transactions from each other need to periodically scan the tables to delete outdated copies of rows. In MVCC, when a row is updated or deleted, it cannot be immediately recycled because there might be active transactions that can still see the old version of the row. Instead of checking if that is the case, which could be quite costly, old rows are assumed to stay relevant. The process of reclaiming the space is deferred until the table is vacuumed which, depending on the database, can be initiated automatically or explicitly.
使用MVCC将事务彼此隔离的数据库需要定期扫描表以删除过时的行副本。在 MVCC 中,当一行被更新或删除时,它不能立即回收,因为可能有活动事务仍然可以看到该行的旧版本。假设旧行保持相关,而不是检查是否是这种情况,这可能会非常昂贵。回收空间的过程被推迟到表被清空,这取决于数据库,可以自动或显式启动。
回答by MindStalker
It is specifically referring to SQL lite vacuum command. http://www.sqlite.org/lang_vacuum.html
它特指 SQL lite 真空命令。 http://www.sqlite.org/lang_vacuum.html
It is removing space left over from DELETE statements.
它正在删除 DELETE 语句中剩余的空间。
回答by user3490256
'vacuumdb' is in MySQL, sqlite and PostgreSQL. In Postgres, vacuumdb identifies space that's occupied by deleted rows and catalogues it for future use. 'vacuum full' does a more comprehensive examination and moves records into the newly created space.
'vacuumdb' 在 MySQL、sqlite 和 PostgreSQL 中。在 Postgres 中,vacuumdb 识别已删除行占用的空间并将其编目以备将来使用。'vacuum full' 进行更全面的检查并将记录移动到新创建的空间中。
回答by Shane.A
Vacuum means 2 things:1. reclaim space 2. defrag file [kind of]
真空意味着 2 件事:1. 回收空间 2. 碎片整理文件 [种类]
Why use Vacuum:1. database file always grows in size when you drop database objects such as tables, views, indexes, and triggers or delete data from tables, Because SQLite just marks the deleted objects as free and reserves it for the future uses.
为什么使用 Vacuum:1. 删除数据库对象(例如表、视图、索引和触发器)或从表中删除数据时,数据库文件的大小总是会增长,因为 SQLite 只是将删除的对象标记为空闲并保留以备将来使用。
2 indexes and tables become fragmented, with a high number of inserts, updates, and deletes.
2 索引和表变得碎片化,具有大量的插入、更新和删除。
- unused data block is created by insert, update, & del Operations.
- 未使用的数据块由插入、更新和删除操作创建。
Precautions:different databases may handle this differently: eg in SQLite if you use unaliased rowid, the VACUUM command will reset the rowid values. but If you use INTEGER PRIMARY KEY column, the VACUUM does not change the values of that column.
注意事项:不同的数据库可能会有不同的处理方式:例如,在 SQLite 中,如果您使用无别名的 rowid,则 VACUUM 命令将重置 rowid 值。但是如果您使用 INTEGER PRIMARY KEY 列,则 VACUUM 不会更改该列的值。
Vacuum requires space to copy the database and run the opperations
Vacuum 需要空间来复制数据库并运行操作
回答by jamieb
It's very similiar to defragging a filesystem. More info on the PGSQL docs.
这与对文件系统进行碎片整理非常相似。有关PGSQL 文档的更多信息。

