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

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.

主站蜘蛛池模板: 南部县| 大竹县| 盐山县| 孝义市| 裕民县| 阳城县| 托克托县| 五常市| 新昌县| 嘉善县| 平江县| 曲松县| 宾阳县| 开江县| 郓城县| 宁陵县| 福建省| 景宁| 左贡县| 宝兴县| 天长市| 体育| 仁寿县| 上犹县| 锦屏县| 青冈县| 柘荣县| 商南县| 阿尔山市| 绵阳市| 吉林省| 新昌县| 金湖县| 织金县| 襄垣县| 和政县| 平度市| 宜宾市| 宜州市| 南郑县| 且末县|