# How to reference PostgreSQL index names?

**URL:** <https://discourse.getdbt.com/t/how-to-reference-postgresql-index-names/6424>\
**Category:** Help\
**Tags:** postgres\
**Created:** [January 30, 2023, 6:41pm UTC](https://discourse.getdbt.com/t/how-to-reference-postgresql-index-names/6424 "2023-01-30T18:41:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kinghuang](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/kinghuang/32/1291_2.png) [@kinghuang](https://discourse.getdbt.com/u/kinghuang)\
**Post date:** [January 30, 2023, 6:41pm UTC](https://discourse.getdbt.com/t/how-to-reference-postgresql-index-names/6424/1 "2023-01-30T18:41:25Z")

</div>

## The problem I’m having

For PostgreSQL configs, dbt creates indexes with names that are [a hash of its properties and the current timestamp](https://docs.getdbt.com/reference/resource-configs/postgres-configs#indexes). What’s a good way for me to reference these generated index names? Is there a way to customize or set the name of the index?

## The context of why I’m trying to do this

I’d like to add a post hook to [CLUSTER](https://www.postgresql.org/docs/current/sql-cluster.html) tables. `CLUSTER` takes the name of an index to order the table rows by. But, there isn’t an obvious way to figure out the name of the indexes created by dbt-postgres.

## What I’ve already tried

I briefly [tried to find the implementation](https://github.com/dbt-labs/dbt-core/blob/main/plugins/postgres/dbt/adapters/postgres/impl.py) for the index name in the code. But, couldn’t see where it was.

## Some example code or error messages

_None_

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [January 30, 2023, 7:29pm UTC](https://discourse.getdbt.com/t/how-to-reference-postgresql-index-names/6424/2 "2023-01-30T19:29:48Z")

</div>

Not a direct answer to your question, but I think this is where the index name is calculated: [https://github.com/dbt-labs/dbt-core/blob/main/plugins/postgres/dbt/adapters/postgres/impl.py#L39](https://github.com/dbt-labs/dbt-core/blob/main/plugins/postgres/dbt/adapters/postgres/impl.py#L39)

Note: `@Owen` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1675106980530719?thread_ts=1675104112.577999&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![kinghuang](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/kinghuang/32/1291_2.png) [@kinghuang](https://discourse.getdbt.com/u/kinghuang)\
**Post date:** [January 31, 2023, 9:19pm UTC](https://discourse.getdbt.com/t/how-to-reference-postgresql-index-names/6424/3 "2023-01-31T21:19:20Z")

</div>

Thanks, that helps. Looks like it’s going to be impossible to generate a matching index name for `CLUSTER` later on since it gets the datetime on every call.

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [January 31, 2023, 9:51pm UTC](https://discourse.getdbt.com/t/how-to-reference-postgresql-index-names/6424/4 "2023-01-31T21:51:30Z")

</div>

Perhaps you could do something clever by querying `<http://pg_catalog.pg|pg_catalog.pg>_indexes` system catalog view? [https://www.postgresql.org/docs/current/view-pg-indexes.html](https://www.postgresql.org/docs/current/view-pg-indexes.html)

Note: `@Owen` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1675201883879729?thread_ts=1675104112.577999&cid=CBSQTAPLG). It might not have transferred perfectly.
