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

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 the 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 the 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 the index creation.

主站蜘蛛池模板: 合肥市| 新乡市| 南川市| 敦煌市| 布拖县| 沭阳县| 霸州市| 广河县| 迭部县| 延吉市| 乌兰县| 福安市| 靖边县| 丹东市| 佛冈县| 乌拉特前旗| 望都县| 潼南县| 塔城市| 泗洪县| 章丘市| 竹北市| 侯马市| 荣成市| 北流市| 元朗区| 乌兰浩特市| 昌吉市| 梅河口市| 苍山县| 荣昌县| 建始县| 达日县| 万荣县| 南开区| 南投市| 永川市| 鲁山县| 房山区| 黄大仙区| 马山县|