Writen by
Devil
7:00 PM
-
7
Comments
VACUUM -- can be interpreted as garbage-collect and optionally analyze a database
Why we need to use VACCUM:
VACUUM reclaims storage occupied by dead tuples. In normal PostgreSQL operation, tuples that are deleted or obsoleted by an update are not physically removed from their table; they remain present until a VACUUM is done. Therefore it's necessary to do VACUUM periodically, especially on frequently-updated tables.
Examples
In the examples below, [tablename] is optional. Without a table specified, VACUUM will be run on available tables in the current schema that the user has access to.
- Plain VACUUM: Frees up space for re-use
VACUUM [tablename]
- Full VACUUM: Locks the database table, and reclaims more space than a plain VACUUM
/* Before Postgres 9.0: */ VACUUM FULL /* Postgres 9.0+: */ VACUUM(FULL) [tablename]
- Full VACUUM and ANALYZE: Performs a Full VACUUM and gathers new statistics on query executions paths using ANALYZE
/* Before Postgres 9.0: */ VACUUM FULL ANALYZE [tablename] /* Postgres 9.0+: */ VACUUM(FULL, ANALYZE) [tablename]
- Verbose Full VACUUM and ANALYZE: Same as #3, but with verbose progress output
/* Before Postgres 9.0: */ VACUUM FULL VERBOSE ANALYZE [tablename] /* Postgres 9.0+: */ VACUUM(FULL, ANALYZE, VERBOSE) [tablename]
ANALYZE
ANALYZE gathers statistics for the query planner to create the most efficient query execution paths. Per PostgreSQL documentation, accurate statistics will help the planner to choose the most appropriate query plan, and thereby improve the speed of query processing.
Example
In the example below, [tablename] is optional. Without a table specified, ANALYZE will be run on available tables in the current schema that the user has access to.
ANALYZE VERBOSE [tablename]
REINDEX
The REINDEX command rebuilds one or more indices, replacing the previous version of the index. REINDEX can be used in many scenarios, including the following (from Postgres documentation):
- An index has become corrupted, and no longer contains valid data. Although in theory this should never happen, in practice indexes can become corrupted due to software bugs or hardware failures. REINDEX provides a recovery method.
- An index has become "bloated", that is it contains many empty or nearly-empty pages. This can occur with B-tree indexes in PostgreSQL under certain uncommon access patterns. REINDEX provides a way to reduce the space consumption of the index by writing a new version of the index without the dead pages.
- You have altered a storage parameter (such as fillfactor) for an index, and wish to ensure that the change has taken full effect.
- An index build with the CONCURRENTLY option failed, leaving an "invalid" index. Such indexes are useless but it can be convenient to use REINDEX to rebuild them. Note that REINDEX will not perform a concurrent build. To build the index without interfering with production you should drop the index and reissue the CREATE INDEX CONCURRENTLY command.
Examples
Any of these can be forced by adding the keyword
FORCE
after the command- Recreate a single index, myindex:
REINDEX INDEX myindex
- Recreate all indices in a table, mytable:
REINDEX TABLE mytable
- Recreate all indices in schema public:
REINDEX SCHEMA public
- Recreate all indices in database postgres:
REINDEX DATABASE postgres
- Recreate all indices on system catalogs in database postgres:
REINDEX SYSTEM postgres
Obviously, the edges make a special case. We speak to the condition of the entryways (open, shut and, how about we be insane, bolted) by the bits with the accompanying show : ExcelR Data Science Courses
ReplyDeleteThanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. PostgreSQL alias
ReplyDeletePositive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. Check it out
ReplyDeleteI read that Post and got it fine and informative. chiropodists drills
ReplyDeleteI really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. battery impact wrench reviews
ReplyDeleteA dirty pool means a lot of hostile microorganisms living in it, which causes sickness for anyone who insists on swimming just to beat the heat. However, cleaning, as for nearly all people is one of the most tedious jobs when owning a certain facility. https://www.earthhershop.com/best-pool-vacuum-head
ReplyDeleteExtremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing. data science institute in delhi
ReplyDelete