lang_vacuum.html 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html><head>
  3. <title>SQLite Query Language: VACUUM</title>
  4. <style type="text/css">
  5. body {
  6. margin: auto;
  7. font-family: Verdana, sans-serif;
  8. padding: 8px 1%;
  9. }
  10. a { color: #45735f }
  11. a:visited { color: #734559 }
  12. .logo { position:absolute; margin:3px; }
  13. .tagline {
  14. float:right;
  15. text-align:right;
  16. font-style:italic;
  17. width:240px;
  18. margin:12px;
  19. margin-top:58px;
  20. }
  21. .toolbar {
  22. font-variant: small-caps;
  23. text-align: center;
  24. line-height: 1.6em;
  25. margin: 0;
  26. padding:1px 8px;
  27. }
  28. .toolbar a { color: white; text-decoration: none; padding: 6px 12px; }
  29. .toolbar a:visited { color: white; }
  30. .toolbar a:hover { color: #80a796; background: white; }
  31. .content { margin: 5%; }
  32. .content dt { font-weight:bold; }
  33. .content dd { margin-bottom: 25px; margin-left:20%; }
  34. .content ul { padding:0px; padding-left: 15px; margin:0px; }
  35. /* rounded corners */
  36. .se { background: url(images/se.png) 100% 100% no-repeat #80a796}
  37. .sw { background: url(images/sw.png) 0% 100% no-repeat }
  38. .ne { background: url(images/ne.png) 100% 0% no-repeat }
  39. .nw { background: url(images/nw.png) 0% 0% no-repeat }
  40. </style>
  41. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  42. </head>
  43. <body>
  44. <div><!-- container div to satisfy validator -->
  45. <a href="lang.html">
  46. <h2 align="center">SQL As Understood By SQLite</h2></a><h1>VACUUM</h1><h4><a href="syntaxdiagrams.html#vacuum-stmt">vacuum-stmt:</a></h4><blockquote> <img alt="syntax diagram vacuum-stmt" src="images/syntax/vacuum-stmt.gif"></img> </blockquote>
  47. <p>When an object (table, index, or trigger) is dropped from the
  48. database, it leaves behind empty space.
  49. This empty space will be reused the next time new information is
  50. added to the database. But in the meantime, the database file might
  51. be larger than strictly necessary. Also, frequent inserts, updates,
  52. and deletes can cause the information in the database to become
  53. fragmented - scrattered out all across the database file rather
  54. than clustered together in one place.</p>
  55. <p>The VACUUM command cleans
  56. the main database by copying its contents to a temporary database file and
  57. reloading the original database file from the copy. This eliminates
  58. free pages, aligns table data to be contiguous, and otherwise cleans
  59. up the database file structure.</p>
  60. <p>The VACUUM command may change the
  61. <a href="lang_createtable.html#rowid">ROWIDs</a> of entries in tables that do
  62. not have an explicit <a href="lang_createtable.html#rowid">INTEGER PRIMARY KEY</a>.</p>
  63. <p>VACUUM only works on the main database.
  64. It is not possible to VACUUM an attached database file.</p>
  65. <p>The VACUUM command will fail if there is an active transaction.
  66. The VACUUM command is a no-op for in-memory databases.</p>
  67. <p>As of SQLite version 3.1, an alternative to using the VACUUM command
  68. is auto-vacuum mode, enabled using the
  69. <a href="pragma.html#pragma_auto_vacuum">auto_vacuum</a> pragma. When <a href="pragma.html#pragma_auto_vacuum">auto_vacuum</a> is enabled for a database,
  70. large deletes cause
  71. the size of the database file to shrink. However, <a href="pragma.html#pragma_auto_vacuum">auto_vacuum</a>
  72. also causes excess fragmentation of the database file. And <a href="pragma.html#pragma_auto_vacuum">auto_vacuum</a>
  73. does not compact partially filled pages of the database as VACUUM
  74. does.</p>
  75. <p>The <a href="pragma.html#pragma_page_size">page_size</a> and/or <a href="pragma.html#pragma_auto_vacuum">auto_vacuum</a> mode of a database can be changed
  76. by invoking the <a href="pragma.html#pragma_page_size">page_size pragma</a> and/or <a href="pragma.html#pragma_auto_vacuum">auto_vacuum pragma</a> and then
  77. immediately VACUUMing the database.</p>