土鳖是什么意思| 乳腺增生不能吃什么食物| 什么花什么门的成语| 巴氏杀菌是什么意思| 伊丽莎白雅顿什么档次| 男人什么时候精子最强| 总是拉稀大便不成形是什么原因| 水金龟属于什么茶| 什么笑容| 为什么不能打死飞蛾| 水泡长什么样| 彩金是什么金| 血红蛋白低说明什么| 上天是什么意思| 微凉是什么意思| 中医调理身体挂什么科| 宝宝肚子疼吃什么药| 隐血是什么意思| 1949属什么生肖| 蕨根粉是什么做的| 世界上最长的蛇是什么| 三秋是什么意思| 护士证什么时候下来| 百合的花语是什么| 扫兴是什么意思| 食道肿瘤有什么症状| 什么的水花| 酵母是什么| 类风湿要吃什么药| 小孩子长白头发是什么原因| 鸡蛋白过敏指的是什么| foryou是什么意思| 化疗后吃什么增加白细胞| 托梦是什么意思| 吃什么不会胖又减肥| 又什么又什么| 提溜是什么意思| 感冒头疼吃什么药好| p站是什么| 动脉硬化吃什么药最好| 阳离子是什么面料| 中将是什么级别的干部| 女性私处长痘痘是什么原因| 环球中心有什么好玩的| 什么是肛瘘| 朱迅和朱军是什么关系| 什么光没有亮度| aids是什么病的简称| 狸猫是什么猫| 什么霄云外| 质体是什么| 画龙点睛指什么生肖| 抬头头晕是什么原因| 甲状腺是什么病啊| 梦见打死蛇是什么预兆| 吃什么东西能减肥| 水痘疫苗第二针什么时候打| 黄帝内经是什么时期的| 例假少吃什么能让量多| 你说到底为什么都是我的错| 什么的废墟| 河童是什么意思| 鲁迅为什么弃医从文| 蒲公英和什么一起泡水喝最好| 宫腔内异常回声是什么意思| 荷尔蒙是什么意思啊| 楔形是什么形状| 粤语骑马过海什么意思| 狗狗咳嗽吃什么药| 头发硬适合什么发型| 三月十二是什么星座| 白带有血丝是什么情况| tct检查是什么| 新疆是什么气候| 磨砂膏有什么作用| 贫血吃什么补血最快| 孕妇现在吃什么水果好| 风热感冒和风寒感冒有什么区别| 质是什么意思| 养神经的药是什么药最好| 强化灶是什么意思| 太阳为什么能一直燃烧| 蛋白粉什么时间喝最好| 双肺纹理增多什么意思| 卡姿兰是什么档次| 荔枝吃了有什么好处| 牛奶加咖啡叫什么| 鸡腿炖什么好吃| 1991年属什么| 猎德村为什么那么有钱| 4.20什么星座| 溶菌酶是什么| 氧化锌是什么| 阴道有异味用什么药| 澳大利亚人说什么语言| 柏拉图爱情是什么意思| 身上长痣是什么原因| 中秋节的习俗是什么| 指甲上有竖条纹是什么原因| 快走对身体有什么好处| 嗓子痒痒老想咳嗽是什么原因| 头发少是什么原因| www指什么| 婴儿流鼻涕吃什么药| 老司机什么意思| 自来卷的头发适合什么发型| 真实是什么意思| 肺部有结节要注意什么| 刘亦菲是什么国籍| 哥弟属于什么档次| 嘴唇有痣代表什么| 甘之如饴什么意思| 新疆是什么气候| 吃什么长内膜| 紫萱名字的含义是什么| 桂花代表什么生肖| 体外受精是什么意思| 发呆表情是什么意思| 吃饭老是噎着是什么原因| 7月生日是什么星座| 开胸手术吃什么补元气| 城头土命是什么意思| 敲木鱼是什么意思| 大便陶土色是什么颜色| 额头凉凉的是什么原因| 检查肾挂什么科| 春天有什么| 肾虚吃什么食物好| 观音菩萨属什么生肖| 腰痛应该挂什么科| 异类是什么意思| 蛇盘疮长什么样| 金克什么| 孤单是什么意思| 什么样的降落伞| 油烟机什么牌子好| 蔓越莓是什么水果| 胸闷气短是什么病| 薤是什么菜图片| 88岁属什么生肖| 比是什么意思| 扦插是什么意思| 什么是spa| 扁桃体是什么样子图片| 奇变偶不变是什么意思| 一周不排便是什么原因| 尿液细菌高是什么原因| 左旋肉碱什么时候吃效果好| 什么叫真丝| 可遇不可求是什么意思| 乩童是什么意思| 晚上9点多是什么时辰| 想怀孕需要检查什么项目| 吃皮蛋有什么好处和坏处| 拉肚子去医院挂什么科| 锁阳是什么| 童心未泯什么意思| 为什么右眼皮一直跳| 甘油脂肪酸酯是什么| 固精缩尿是什么意思| 肺囊肿是什么病严重吗| 时令水果是什么意思| 鸽子怕什么怎么赶走| ph值是什么意思| 东边日出西边雨是什么生肖| 口吐白沫是什么生肖| 茄子有什么功效和作用| 割包皮去医院挂什么科| gg是什么品牌| 74岁属什么| 转网是什么意思| 两个土念什么| o型血和什么血型容易溶血| 有机什么意思| tct和hpv有什么区别| 什么血型不招蚊子| 今年七夕节是什么时候| 肝小钙化灶是什么意思| 疫情是什么| 你为什么| 化疗后白细胞低吃什么食物补得快| 坏血症什么症状| sansui是什么牌子| 55岁属什么| 姓黑的都是什么族| 打猎是什么意思| 尿肌酐低是什么原因| 田各读什么| 皮肤痒挂什么科| 4月份什么星座| 没吃多少东西但肚子很胀是什么| 燊念什么| 吃什么对头发有好处| 如饥似渴是什么意思| 1999年五行属什么| 嘴苦口臭是什么原因造成的| 左侧肚脐旁边疼是什么原因| 检查是否怀孕要做什么检查| 乔丹是什么品牌| 米索前列醇片是什么药| 为什么会有湿气| 怀孕是什么意思| 脱脂是什么意思| 筋膜炎是什么| 70年属什么生肖| Mary英文名什么意思| 月经血是什么血| 辰龙是什么意思| samsung是什么牌子| 前列腺液是什么| 母婴传播是什么意思| o型阴性血是什么意思| 血管瘤长什么样子图片| 1月29日是什么星座| 可乐饼为什么叫可乐饼| 肚脐眼左边是什么部位| 青蛙吃什么| 黑白双煞是什么意思| 子宫薄是什么原因造成的| 梦见自己相亲是什么征兆| 吃核桃有什么好处和坏处| 三点水加个有字念什么| 花金龟吃什么| 光明会到底是干什么的| 一个齿一个禹念什么| 副教授是什么级别| 奥司他韦是什么药| 女性尿道口有小疙瘩是什么原因| 什么人容易得精神病| 吃螃蟹不能喝什么饮料| 兆后面的单位是什么| 7大营养素是什么| 扁桃体发炎吃什么消炎药| 咖啡是什么做的| 羽字五行属什么的| 气管炎的症状吃什么药好得快| 平行班是什么意思| 羊日冲牛是什么意思| 沙和尚是什么动物变的| 五岳是什么意思| 1963年属兔的是什么命| 卵泡不破是什么原因造成的| 芒果不可以跟什么一起吃| 53年属什么生肖| 什么是人格| 黄瓜敷脸有什么作用与功效| 开颌是什么意思| 什么叫蛋白质| 禾末念什么| 湿气重吃什么水果| 经常吐口水是什么原因| 小孩牙龈黑紫色是什么原因| 脾大对身体有什么影响| 直肠炎用什么药效果最好| 3楼五行属什么| 性欲什么意思| 娃娃鱼属于什么类动物| 1109是什么星座| Polo什么意思| 心脏不舒服有什么症状| 用什么洗脸可以美白| 渴望是什么意思| 阳萎是什么意思| 部队政委是什么级别| 百度
Supported Versions: Current (17) / 16 / 15 / 14 / 13
Development Versions: 18 / devel
Unsupported versions: 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

REINDEX

REINDEX — rebuild indexes

Synopsis

REINDEX [ ( VERBOSE ) ] { INDEX | TABLE | SCHEMA | DATABASE | SYSTEM } [ CONCURRENTLY ] name

Description

REINDEX rebuilds an index using the data stored in the index's table, replacing the old copy of the index. There are several scenarios in which to use REINDEX:

  • 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. See Section 24.2 for more information.

  • You have altered a storage parameter (such as fillfactor) for an index, and wish to ensure that the change has taken full effect.

  • If an index build fails with the CONCURRENTLY option, this index is left as invalid. Such indexes are useless but it can be convenient to use REINDEX to rebuild them. Note that only REINDEX INDEX is able to perform a concurrent build on an invalid index.

Parameters

INDEX

Recreate the specified index.

TABLE

Recreate all indexes of the specified table. If the table has a secondary TOAST table, that is reindexed as well.

SCHEMA

Recreate all indexes of the specified schema. If a table of this schema has a secondary TOAST table, that is reindexed as well. Indexes on shared system catalogs are also processed. This form of REINDEX cannot be executed inside a transaction block.

DATABASE

Recreate all indexes within the current database. Indexes on shared system catalogs are also processed. This form of REINDEX cannot be executed inside a transaction block.

SYSTEM

Recreate all indexes on system catalogs within the current database. Indexes on shared system catalogs are included. Indexes on user tables are not processed. This form of REINDEX cannot be executed inside a transaction block.

name

The name of the specific index, table, or database to be reindexed. Index and table names can be schema-qualified. Presently, REINDEX DATABASE and REINDEX SYSTEM can only reindex the current database, so their parameter must match the current database's name.

CONCURRENTLY

When this option is used, PostgreSQL will rebuild the index without taking any locks that prevent concurrent inserts, updates, or deletes on the table; whereas a standard index rebuild locks out writes (but not reads) on the table until it's done. There are several caveats to be aware of when using this option — see Rebuilding Indexes Concurrently.

For temporary tables, REINDEX is always non-concurrent, as no other session can access them, and non-concurrent reindex is cheaper.

VERBOSE

Prints a progress report as each index is reindexed.

Notes

If you suspect corruption of an index on a user table, you can simply rebuild that index, or all indexes on the table, using REINDEX INDEX or REINDEX TABLE.

Things are more difficult if you need to recover from corruption of an index on a system table. In this case it's important for the system to not have used any of the suspect indexes itself. (Indeed, in this sort of scenario you might find that server processes are crashing immediately at start-up, due to reliance on the corrupted indexes.) To recover safely, the server must be started with the -P option, which prevents it from using indexes for system catalog lookups.

One way to do this is to shut down the server and start a single-user PostgreSQL server with the -P option included on its command line. Then, REINDEX DATABASE, REINDEX SYSTEM, REINDEX TABLE, or REINDEX INDEX can be issued, depending on how much you want to reconstruct. If in doubt, use REINDEX SYSTEM to select reconstruction of all system indexes in the database. Then quit the single-user server session and restart the regular server. See the postgres reference page for more information about how to interact with the single-user server interface.

Alternatively, a regular server session can be started with -P included in its command line options. The method for doing this varies across clients, but in all libpq-based clients, it is possible to set the PGOPTIONS environment variable to -P before starting the client. Note that while this method does not require locking out other clients, it might still be wise to prevent other users from connecting to the damaged database until repairs have been completed.

REINDEX is similar to a drop and recreate of the index in that the index contents are rebuilt from scratch. However, the locking considerations are rather different. REINDEX locks out writes but not reads of the index's parent table. It also takes an ACCESS EXCLUSIVE lock on the specific index being processed, which will block reads that attempt to use that index. In contrast, DROP INDEX momentarily takes an ACCESS EXCLUSIVE lock on the parent table, blocking both writes and reads. The subsequent CREATE INDEX locks out writes but not reads; since the index is not there, no read will attempt to use it, meaning that there will be no blocking but reads might be forced into expensive sequential scans.

Reindexing a single index or table requires being the owner of that index or table. Reindexing a schema or database requires being the owner of that schema or database. Note that is therefore sometimes possible for non-superusers to rebuild indexes of tables owned by other users. However, as a special exception, when REINDEX DATABASE, REINDEX SCHEMA or REINDEX SYSTEM is issued by a non-superuser, indexes on shared catalogs will be skipped unless the user owns the catalog (which typically won't be the case). Of course, superusers can always reindex anything.

Reindexing partitioned tables or partitioned indexes is not supported. Each individual partition can be reindexed separately instead.

Rebuilding Indexes Concurrently

Rebuilding an index can interfere with regular operation of a database. Normally PostgreSQL locks the table whose index is rebuilt against writes and performs the entire index build with a single scan of the table. Other transactions can still read the table, but if they try to insert, update, or delete rows in the table they will block until the index rebuild is finished. This could have a severe effect if the system is a live production database. Very large tables can take many hours to be indexed, and even for smaller tables, an index rebuild can lock out writers for periods that are unacceptably long for a production system.

PostgreSQL supports rebuilding indexes with minimum locking of writes. This method is invoked by specifying the CONCURRENTLY option of REINDEX. When this option is used, PostgreSQL must perform two scans of the table for each index that needs to be rebuilt and wait for termination of all existing transactions that could potentially use the index. This method requires more total work than a standard index rebuild and takes significantly longer to complete as it needs to wait for unfinished transactions that might modify the index. However, since it allows normal operations to continue while the index is being rebuilt, this method is useful for rebuilding indexes in a production environment. Of course, the extra CPU, memory and I/O load imposed by the index rebuild may slow down other operations.

The following steps occur in a concurrent reindex. Each step is run in a separate transaction. If there are multiple indexes to be rebuilt, then each step loops through all the indexes before moving to the next step.

  1. A new transient index definition is added to the catalog pg_index. This definition will be used to replace the old index. A SHARE UPDATE EXCLUSIVE lock at session level is taken on the indexes being reindexed as well as their associated tables to prevent any schema modification while processing.

  2. A first pass to build the index is done for each new index. Once the index is built, its flag pg_index.indisready is switched to true to make it ready for inserts, making it visible to other sessions once the transaction that performed the build is finished. This step is done in a separate transaction for each index.

  3. Then a second pass is performed to add tuples that were added while the first pass was running. This step is also done in a separate transaction for each index.

  4. All the constraints that refer to the index are changed to refer to the new index definition, and the names of the indexes are changed. At this point, pg_index.indisvalid is switched to true for the new index and to false for the old, and a cache invalidation is done causing all sessions that referenced the old index to be invalidated.

  5. The old indexes have pg_index.indisready switched to false to prevent any new tuple insertions, after waiting for running queries that might reference the old index to complete.

  6. The old indexes are dropped. The SHARE UPDATE EXCLUSIVE session locks for the indexes and the table are released.

If a problem arises while rebuilding the indexes, such as a uniqueness violation in a unique index, the REINDEX command will fail but leave behind an invalid new index in addition to the pre-existing one. This index will be ignored for querying purposes because it might be incomplete; however it will still consume update overhead. The psql \d command will report such an index as INVALID:

postgres=# \d tab
       Table "public.tab"
 Column |  Type   | Modifiers
--------+---------+-----------
 col    | integer |
Indexes:
    "idx" btree (col)
    "idx_ccnew" btree (col) INVALID

If the index marked INVALID is suffixed ccnew, then it corresponds to the transient index created during the concurrent operation, and the recommended recovery method is to drop it using DROP INDEX, then attempt REINDEX CONCURRENTLY again. If the invalid index is instead suffixed ccold, it corresponds to the original index which could not be dropped; the recommended recovery method is to just drop said index, since the rebuild proper has been successful.

Regular index builds permit other regular index builds on the same table to occur simultaneously, but only one concurrent index build can occur on a table at a time. In both cases, no other types of schema modification on the table are allowed meanwhile. Another difference is that a regular REINDEX TABLE or REINDEX INDEX command can be performed within a transaction block, but REINDEX CONCURRENTLY cannot.

Like any long-running transaction, REINDEX on a table can affect which tuples can be removed by concurrent VACUUM on any other table.

REINDEX SYSTEM does not support CONCURRENTLY since system catalogs cannot be reindexed concurrently.

Furthermore, indexes for exclusion constraints cannot be reindexed concurrently. If such an index is named directly in this command, an error is raised. If a table or database with exclusion constraint indexes is reindexed concurrently, those indexes will be skipped. (It is possible to reindex such indexes without the CONCURRENTLY option.)

Examples

Rebuild a single index:

REINDEX INDEX my_index;

Rebuild all the indexes on the table my_table:

REINDEX TABLE my_table;

Rebuild all indexes in a particular database, without trusting the system indexes to be valid already:

$ export PGOPTIONS="-P"
$ psql broken_db
...
broken_db=> REINDEX DATABASE broken_db;
broken_db=> \q

Rebuild indexes for a table, without blocking read and write operations on involved relations while reindexing is in progress:

REINDEX TABLE CONCURRENTLY my_broken_table;

Compatibility

There is no REINDEX command in the SQL standard.

胃糜烂是什么原因引起的 数典忘祖指什么动物 34是什么意思 医学hr是什么意思 范仲淹是什么朝代的
什么是 孔夫子搬家的歇后语是什么 总想喝水是什么原因 什么食物可以化解结石 地主之谊是什么意思
吃什么补雌激素 什么药能治阳痿早泄 屁多是什么病的前兆 种猪是什么意思 单核细胞高是什么意思
岁月的痕迹是什么意思 磷偏低是什么原因 氟哌酸又叫什么名字 嘴唇干裂是什么原因引起的 imax是什么意思
什么是特异性皮炎bysq.com 阴道瘙痒是什么原因造成的hcv9jop5ns8r.cn 双鱼座是什么性格hcv8jop2ns4r.cn 蒲公英吃了有什么好处hcv8jop4ns6r.cn 朋友圈屏蔽显示什么hcv7jop6ns9r.cn
农村入党需要什么条件hcv7jop7ns2r.cn 驹是什么意思hcv8jop8ns7r.cn 大连有什么好吃的hcv8jop4ns2r.cn 1944年属什么hcv8jop2ns1r.cn 艾灸是什么hcv9jop3ns1r.cn
手麻是什么原因引起的hcv8jop2ns1r.cn 感统训练是什么hcv7jop5ns3r.cn 脉搏细是什么原因hcv8jop5ns7r.cn 牙龈肿痛上火吃什么药最好hcv8jop1ns2r.cn 制片人是干什么的hcv8jop8ns1r.cn
狗摇尾巴是什么意思hcv9jop1ns0r.cn 黄豆吃多了有什么坏处hcv9jop3ns2r.cn 中国姓什么的人最多hcv9jop4ns7r.cn 挑灯夜战是什么意思hcv7jop9ns2r.cn 敛是什么意思hcv9jop2ns1r.cn
百度