官术网_书友最值得收藏!

Adding data while indexing

Creating an index is easy. However, keep in mind that you cannot modify a table, while an index is being built. The CREATE INDEX command will lock up a table using a SHARE lock to ensure that no changes happen. While this is clearly no problem for small tables, it will cause issues on large ones on production systems. Indexing a terabyte of data or so will take some time and therefore blocking a table for too long can become an issue.

The solution to the problem is CREATE INDEX CONCURRENTLY command. Building the index will take a lot longer (usually at least twice as long) but you can use the table normally during index creation.

Here is how it works:

test=# CREATE INDEX CONCURRENTLY idx_name2 ON t_test (name);
CREATE INDEX

Note that PostgreSQL does not guarantee success if you are using the CREATE INDEX CONCURRENTLY command. An index can end up being marked as invalid if the operations going on on your system somehow conflict with index creation.

主站蜘蛛池模板: 新余市| 济阳县| 沛县| 杭锦旗| 琼结县| 临安市| 璧山县| 略阳县| 临清市| 苏尼特右旗| 固阳县| 垦利县| 运城市| 平潭县| 桐柏县| 安宁市| 陵水| 如东县| 遂昌县| 滨海县| 呼伦贝尔市| 屏东县| 连山| 姜堰市| 克山县| 图们市| 大冶市| 社旗县| 梅河口市| 栾城县| 施甸县| 灌云县| 隆林| 寿光市| 朔州市| 新营市| 会昌县| 临清市| 探索| 全南县| 屏东县|