It depends.
Assuming we are talking about default B-Tree indexes only. If other index types like GIN or GiST are involved, things are not as simple.
In principal an index on (a,b)
is good for searches on just a
and another index on just (a)
is not needed. (But an additional index on just (b)
generally makes sense!)
It may still be a good idea if the column b
is big, so that an index on just (a)
is substantially smaller.
You would have to consider the size of the table, available RAM, typical queries, the involved data types, the size of the index, overhead per tuple and size of data, data alignment and padding ... or just run tests with your actual data and queries (but careful what you are testing really).
For example if a
and b
are no bigger than 4 bytes (integer
, smallint
, date
, ...) the index on (a,b)
is exactly as big as the one on just (a)
and there is no point whatsoever to keep the second.
A more detailed answer on dba.SE for this case exactly.
The manual for the current version of Postgres is always a good source for more detailed information.