postgresql - Postgres 同时构建索引

标签 postgresql

我正在从 Postgres 文档中阅读此内容:

Building Indexes Concurrently

... PostgreSQL supports building indexes without locking out writes. This method is invoked by specifying the CONCURRENTLY option of CREATE INDEX. When this option is used, PostgreSQL must perform two scans of the table, and in addition it must wait for all existing transactions that could potentially modify or use the index to terminate. Thus this method requires more total work than a standard index build and takes significantly longer to complete. However, since it allows normal operations to continue while the index is built, this method is useful for adding new indexes in a production environment....

In a concurrent index build, the index is actually entered into the system catalogs in one transaction, then two table scans occur in two more transactions. Before each table scan, the index build must wait for existing transactions that have modified the table to terminate. After the second scan, the index build must wait for any transactions that have a snapshot (see Chapter 13) predating the second scan to terminate. Then finally the index can be marked ready for use, and the CREATE INDEX command terminates. Even then, however, the index may not be immediately usable for queries: in the worst case, it cannot be used as long as transactions exist that predate the start of the index build.

什么是系统目录?什么是表扫描?因此,听起来索引是首先构建的,然后它必须等待现有事务(在索引构建期间发生的事务?)终止,然后等待任何在第二次扫描之前有快照的事务终止(这是什么意思)是什么意思?它与第一个语句有何不同)。这些扫描是什么?

最佳答案

  1. 什么是系统目录? -https://www.postgresql.org/docs/current/static/catalogs.html
  2. 什么是表扫描? - 它读取表以获取您构建索引的列的值。
  3. 在索引构建期间发生的那些? - 不,第一次表扫描后可能会更改数据
  4. 这是什么意思?这意味着它等待事务结束。
  5. 这些扫描是什么?在开始并发构建索引之前,首先扫描读取表。允许更改表以避免锁定。构建完成后,它会粗略地扫描差异,应用短锁并将索引标记为可用。它与创建索引的不同之处在于,最后一个锁定表,不允许对数据进行任何更改,而并发扫描两次,但允许在构建索引时更改数据

关于postgresql - Postgres 同时构建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43125789/

相关文章:

database - PostgreSQL 9 : could not fsync file "base/16386": Invalid argument

sql - 如何在 PostgreSql 中从秒获取年、月、日?

sql - Postgresql 按不同表中的多列排序

java - NoSuchMethodError 异常

用于 Hibernate + JPA2 项目的 MySQL 或 PostgreSQL

postgresql - 为两个不同的服务器使用相同的 postgresql 数据库有什么问题吗?

sql - PostgreSQL:为什么 NOT NULL 在这里不起作用?

ruby-on-rails - Rails 的 ActiveRecord::Migration 的外键?

sql - PostgreSQL 11 可重复读隔离级别

sql - 如何在 PostgreSQL 中以日期格式本身添加 AM 或 PM?