- Mastering PostgreSQL 12
- Hans Jürgen Sch?nig
- 194字
- 2021-08-20 10:00:28
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.
- Photoshop CS3圖層、通道、蒙版深度剖析寶典
- 中國戰(zhàn)略性新興產(chǎn)業(yè)研究與發(fā)展·智能制造裝備
- 統(tǒng)計挖掘與機器學習:大數(shù)據(jù)預測建模和分析技術(原書第3版)
- Apache源代碼全景分析(第1卷):體系結構與核心模塊
- 嵌入式GUI開發(fā)設計
- 三菱FX/Q系列PLC工程實例詳解
- 中老年人學電腦與上網(wǎng)
- 51單片機應用程序開發(fā)與實踐
- 玩轉PowerPoint
- 智能小車機器人制作大全(第2版)
- Cisco UCS Cookbook
- 實戰(zhàn)大數(shù)據(jù)(Hadoop+Spark+Flink):從平臺構建到交互式數(shù)據(jù)分析(離線/實時)
- 智能機器人創(chuàng)新熱點與趨勢
- INSTANT Oracle GoldenGate
- 人工智能算法(卷2):受大自然啟發(fā)的算法