How to Name Your Indexes in Postgres

2 Comments

When you create indexes on a table, here are a few simple guidelines to make your life easier down the road.

1. Start the index name with the table name, like mytable_. In Postgres, every index name needs to be unique in the database. If you have several tables that all have a column named created_date, for example, you couldn’t do this:

Instead, you wanna do this so each index name is unique and you don’t get errors:

2. Name the index with the key columns in order. When you’re reading an explain plan, this will make it easier for you to understand where the data is coming from, and its sort order in the index.

3. Don’t put individual included column names in the name. Your index might include half a dozen non-key columns to help with select performance, but there’s no need to list those individually in the index name. Instead, just put _includes at the end of the index name to denote that it has included columns, like this:

4. For partial indexes, use a _partial suffix as well. You don’t need to put the full filter clause in the index name. Index names just can’t handle all your complicated filtering sql.

Are there any other index naming conventions that you think should be included in this list? Drop a note in the comments, and if I agree with you, I’ll promote your suggestion up into this list and credit you by name.

Previous Post
How to Use check_indexes to Learn About Your Postgres Database’s Indexes
Next Post
I Really Wish PostgreSQL Had Index Hints.

2 Comments. Leave new

  • Michael Christofides
    April 11, 2025 7:02 am

    Really nice list. One addition, I really like it when people who use the occasional non-btree index add the type as a suffix (e.g. _hash _brin _gin …). Like your other tips, it really helps when looking at explain plans.

    Reply
  • Mario Splivalo
    August 26, 2025 7:17 am

    I prefix my indices (indexes?) with ix_, for some reason 🙂 (I guess I picked that up from MSSQL back in the day?)
    I don’t suffix my indexes unless unorthodox ones, as Michael mentioned.

    Reply

Leave a Reply to Mario Splivalo Cancel reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed