icon Join with us for Oracle DBA Training Live Session ENROLL NOW

Why Isn’t Postgres Using My Index? Six Real Reasons and Fixes

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • 27 Oct, 2026
  • 0 Comments
  • 6 Mins Read

Why Isn’t Postgres Using My Index? Six Real Reasons and Fixes

Why Isn’t Postgres Using My Index? Six Real Reasons and Fixes

You created the index. You ran the query. And Postgres still stubbornly does a sequential scan. If this sounds familiar, you are not alone—it is one of the most common frustrations for developers and DBAs working with PostgreSQL.

The truth is, PostgreSQL is not ignoring your index out of spite. Its query planner is making a cost-based decision, and sometimes that decision is wrong because of stale information, misconfigured settings, or a mismatch between the index and the query. Here are six real reasons Postgres skips your index, along with practical fixes you can apply today.

1. The Query Returns Too Much of the Table

This is the most fundamental reason. An index scan requires reading the index, then jumping to the table rows (random I/O). A sequential scan reads the table in order (sequential I/O). If your query returns a large percentage of the table, the random reads of an index scan become more expensive than simply reading the whole table from start to finish.

Rule of thumb: If a query returns more than roughly 10–20% of the rows, PostgreSQL will often prefer a sequential scan—and it is usually right .

How to verify: Run EXPLAIN ANALYZE and compare the estimated rows to the actual rows. If the query returns a large fraction of the table, the sequential scan is likely intentional and efficient.

The fix: There is no fix needed in most cases—the planner is correct. If you truly need faster performance for a large-result query, consider whether you can narrow the result set with better filtering, or whether the query pattern itself needs rethinking (for example, pagination or aggregation instead of fetching everything).

2. Statistics Are Stale or Missing

PostgreSQL relies on table statistics to estimate how many rows a query will return. If those statistics are outdated, the planner may think an index scan will be expensive when it would actually be cheap—or vice versa. Without accurate statistics, the planner is essentially guessing.

A classic symptom is a large gap between the rows= estimate in EXPLAIN and the actual rows= in EXPLAIN ANALYZE. If the planner estimates 1 row but actually returns 10,000, the statistics are misleading it .

How to verify:

sql
SELECT schemaname, relname, last_analyze, last_vacuum, n_live_tup
FROM pg_stat_user_tables
WHERE relname = 'your_table_name';

The fix: Run ANALYZE on the table. For large or frequently changing tables, ensure autovacuum is running regularly, or schedule manual ANALYZE after bulk loads .

sql
ANALYZE your_table_name;

3. Cost Parameters Do Not Match Your Hardware

PostgreSQL’s default cost model assumes spinning disks, where random I/O is significantly more expensive than sequential I/O. The default random_page_cost is 4.0, while seq_page_cost is 1.0. On modern SSDs, random reads are nearly as fast as sequential reads. That default assumption can make the planner overvalue sequential scans and undervalue index scans.

How to verify:

sql
SHOW random_page_cost;
SHOW seq_page_cost;

The fix: For SSD-backed systems, lower random_page_cost to something like 1.1 or 1.2. This makes index scans appear cheaper to the planner and encourages their use where appropriate .

sql
-- Session-level for testing
SET random_page_cost = 1.1;

-- Or set it in postgresql.conf for the whole instance

4. The Index Does Not Match the Query Expression

PostgreSQL can only use an index when the expression in the query matches the index definition exactly. A common mistake is creating an index on a column, then querying with a function wrapped around that column.

For example, if you have an index on created_at but write:

sql
WHERE date(created_at) = '2026-01-25'

the planner cannot use the index on created_at because the function date() changes the value being compared .

The fix: Rewrite the query to avoid the function on the indexed column:

sql
WHERE created_at >= '2026-01-25'
  AND created_at < '2026-01-26'

Alternatively, create an expression index that matches the query exactly:

sql
CREATE INDEX idx_orders_date ON orders (date(created_at));

The same principle applies to implicit type casts, collation mismatches, and operators that are not supported by the index’s operator class .

5. The Index Is Invalid, Corrupted, or Was Built Concurrently

Sometimes the index exists but is not in a usable state. This can happen if a CREATE INDEX CONCURRENTLY operation failed partway through, leaving an invalid index behind. The index appears in \d or pg_indexes, but the planner cannot use it.

This is a subtle and often-overlooked cause. A user on the PostgreSQL mailing list reported exactly this: an index that had worked for a long time suddenly stopped being used. The solution was to REINDEX the table, which restored index usage .

How to verify: Check the indisvalid and indisready flags in pg_index:

sql
SELECT indexrelid::regclass, indisvalid, indisready
FROM pg_index
WHERE indrelid = 'your_table_name'::regclass;

If either flag is false, the index is not usable.

The fix: Rebuild the index. If the table is in active use, use REINDEX CONCURRENTLY to avoid blocking writes :

sql
REINDEX INDEX CONCURRENTLY your_index_name;

Also, be cautious with CREATE INDEX CONCURRENTLY on busy tables—it has caveats and can fail silently in ways that leave an invalid index behind.

6. The Query Uses a Wildcard That Btree Cannot Handle

Btree indexes, the default in PostgreSQL, can only optimize LIKE or pattern-matching queries when the pattern is anchored to the beginning of the string. A query like:

sql
WHERE name LIKE '%smith%'

cannot use a standard btree index because the leading wildcard means the index has no starting point to search from. PostgreSQL must scan the entire table to find matches .

The fix: If you need leading-wildcard searches, you need a different index type. For LIKE and ILIKE queries with leading wildcards, enable the pg_trgm extension and create a GIN or GiST trigram index:

sql
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX idx_name_trgm ON users USING GIN (name gin_trgm_ops);

For full-text search, use a GIN index on a tsvector column. For JSONB containment queries, a GIN index on the JSONB column is the right choice .

Diagnosing the Problem: Your First Three Steps

Before applying any fix, confirm what is actually happening. Run:

sql
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT * FROM your_table WHERE your_condition;

Look for three things:

  1. What scan type is being used? Seq Scan means no index is being used. Index Scan or Bitmap Index Scan means an index is in play.

  2. How do estimated rows compare to actual rows? A large discrepancy points to statistics problems.

  3. How many buffers are being read? High shared hit counts with a sequential scan suggest the table is already cached and the sequential scan may genuinely be fast.

If you want to test whether an index would help without permanently changing anything, you can temporarily discourage sequential scans in your session:

sql
SET enable_seqscan = off;
EXPLAIN ANALYZE SELECT ...;
RESET enable_seqscan;

If the query runs dramatically faster with the index forced, you have confirmed that the planner’s cost estimate is the problem—and the fixes above (especially updating statistics and adjusting random_page_cost) are likely to resolve it permanently .

Final Thought

PostgreSQL’s planner is not perfect, but it is rarely malicious. When it skips your index, it is usually because it believes a sequential scan is cheaper—or because it literally cannot use the index you provided. The six causes above cover the vast majority of real-world cases. Start with EXPLAIN ANALYZE, check your statistics, verify the index is valid, and make sure your query expression matches the index definition. In most cases, a small adjustment is all it takes to get Postgres back on the index.

lets talk - learnomate helpdesk

Book a Free Demo

lets talk - learnomate helpdesk

Book a Free Demo