HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMajor

Is there a way to show the creation statement for an index in PostgreSQL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlshowthestatementwayforindextherecreation

Problem

I need to recreate an index in PostgreSQL which has suffered index bloat. Since I need the index to be usable while it's being created, I can't use REINDEX. I am going to recreate the index with a new name and then drop the old one. Is there any way to see the SQL statement that was used to create an index so I can just copy that?

Solution

There is actually, just query the pg_indexes system catalog view as follows:

SELECT indexdef FROM pg_indexes WHERE indexname = '...'


and you should get back the SQL statement used to define it.

Code Snippets

SELECT indexdef FROM pg_indexes WHERE indexname = '...'

Context

StackExchange Database Administrators Q#116797, answer score: 48

Revisions (0)

No revisions yet.