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

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 1 TB of data or so will take some time, and therefore blocking a table for too long can become an issue.

The solution to this 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's how it works:

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

Note that PostgreSQL doesn't guarantee success if you are using the CREATE INDEX CONCURRENTLY command. An index can end up being marked as invalid if the operations running on your system somehow conflict with the index creation. If you want to figure out if your indexes are invalid, use \d on the relation.

主站蜘蛛池模板: 海盐县| 新巴尔虎右旗| 广东省| 临海市| 汤阴县| 伊宁市| 甘孜县| 扶沟县| 喀喇沁旗| 竹山县| 衡阳县| 滕州市| 汝南县| 鄯善县| 崇义县| 宜州市| 七台河市| 西乌珠穆沁旗| 辽源市| 新乐市| 太康县| 汽车| 平果县| 棋牌| 崇义县| 永和县| 资阳市| 西贡区| 大渡口区| 彩票| 韩城市| 泽库县| 巴林左旗| 迁安市| 吴旗县| 会理县| 井冈山市| 钟祥市| 望都县| 绥宁县| 牙克石市|