Forcing use of an index

You have all the relevant indexes and you know it would be faster if Postgres used them but EXPLAIN is showing that Postgres is getting its cost calculations wrong.

Solution

Issue SET SEQSCAN TO OFF before the query to force all indexes to be used ref adm.

Discussion

Before forcing Postgres to use indexes, make sure you have run VACUUM ANALYZE recently and that the EXPLAIN shows unexpected cost calculations. It's important to make sure Postgres is using accurate information before overriding its decisions.

If that still doesn't help, you can tell Postgres to always use an index if one is available. If you have a complex query with a mix of sequence scans and index searches this may actually make things worse.

SET SEQSCAN TO OFF
SELECT ...
SET SEQSCAN TO ON
   

Check the runtime-configuration page for other settings you can change. You alter the various cost weightings at your own risk.