postgresql 索引使用参考
更新:HHH   时间:2023-1-7



通常在postgresql创建普通索引如下
create index idx_table_name_x1 on table_name(col_name);
reate index 执行后在创建索引期间会阻塞 dml,创建索引时加concurrently参数不阻塞dml。
创建索引:
CREATE INDEX  idx_t_info ON "public".t_info(code);
在线创建索引:
CREATE INDEX concurrently idx_t_info ON "public".t_info(code);
重建单个索引:
REINDEX INDEX my_index;
重建和表my_table有关的索引
REINDEX TABLE my_table;
重建broken_db数据库下所有的索引:
REINDEX DATABASE broken_db;
创建唯一索引:
CREATE UNIQUE INDEX idx_t_info ON t_info(name1);
函数索引:
CREATE INDEX concurrently idx_t_info ON t_info(lower(name1));
部分索引
CREATE INDEX concurrently idx_t_info ON t_info(code) where (code >5);


删除索引:
drop index idx_t_info;
索引重命名:
alter index idx_t_info rename to idx_t_info1;

返回数据库教程...