DROP INDEX (Drop Index)
Last updated: 2026-11-04
DROP INDEX (Drop Index)
DROP INDEX removes an index that is no longer needed, reclaiming space and speeding up writes. An index created automatically for a primary key or unique constraint cannot be dropped directly — the constraint has to go first.
| Kind | command |
|---|---|
| Example Language | SQL |
📝 Syntax
DROP INDEX [CONCURRENTLY] [IF EXISTS] <index name> [, ...]
⚙️ Parameters
| IF EXISTS | Do not raise an error when the index is missing |
|---|---|
| CONCURRENTLY | Drops the index without blocking reads or writes |
Returns:No return value. Once it succeeds the index is gone from pg_indexes.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
DROP TABLE
CREATE TABLE
CREATE INDEX
DROP INDEX
DROP INDEX
indexes_left
------------
1
📌 Key Points
- An index backing a constraint cannot be dropped directly: you get cannot drop index ... because constraint ... requires it.
- To remove such an index, drop the constraint first with ALTER TABLE ... DROP CONSTRAINT — dropping a primary key leaves the table without one.
- DROP INDEX IF EXISTS does not fail when the index is missing, which makes it safe in repeatable scripts.
- Dropping an index does not touch the data, but queries that relied on it fall back to sequential scans.
- DROP INDEX CONCURRENTLY cannot run inside a transaction block.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QHow do I tell that an index is unused?
ACheck the idx_scan counter in pg_stat_user_indexes; an index stuck at zero is usually unused, provided no constraint depends on it.
QDoes dropping an index affect data correctness?
ANo, only performance is affected. Before dropping a unique index, clear out duplicate rows — otherwise later inserts will fail.