One of the quickest and fastest way of increasing your database performance is to index your data. Several type of data should be indexed:
- Primary Key: should be done automatically by the database engine.
- Foreign Key: it is not done by the database engine automatically so it is your responsability (or your ORM's).
- Field in
where
clause: definitely not done automatically but increases performances.
JSONB
type should be index using a gin()
index.
PostgreSQL does not handle composite indexes, it only indexes the first element so make sure you create indexes with only one element.
30% to 40% of your database data should be indexed.