runoobdb=# \d company
Table"public.company"Column|Type|Collation|Nullable|Default---------+---------------+-----------+----------+---------
id | integer ||notnull|
name | text ||notnull|
age | integer ||notnull|
address | character(50)|||
salary | real |||Indexes:"company_pkey" PRIMARY KEY, btree (id)"salary_index" btree (salary)
你可以使用 \di 命令列出数据库中所有索引:
runoobdb=# \di
List of relations
Schema|Name|Type|Owner|Table--------+-----------------+-------+----------+------------public| company_pkey | index | postgres | company
public| department_pkey | index | postgres | department
public| salary_index | index | postgres | company
(3 rows)
DROP INDEX (删除索引)
一个索引可以使用 PostgreSQL 的 DROP 命令删除。
DROP INDEX index_name;
您可以使用下面的语句来删除之前创建的索引:
# DROP INDEX salary_index;
删除后,可以看到 salary_index 已经在索引的列表中被删除:
runoobdb=# \di
List of relations
Schema|Name|Type|Owner|Table--------+-----------------+-------+----------+------------public| company_pkey | index | postgres | company
public| department_pkey | index | postgres | department
(2 rows)