Home > database >  Size of a GIN index in postgreSQL
Size of a GIN index in postgreSQL

Time:11-30

I have created a model in Django.

class MyModel(models.Model):
    features = TextField(blank=True, default='')

There are several possible ways to store the data in the feature field. Some examples below.

  1. feature1;feature2
  2. feature1, feature2
  3. feature1,feature2

And so on. I created a GIN index for that field using migrations.RunSQL() (thanks to the following answer). The postgreSQL command looks as follows

CREATE INDEX features_search_idx ON "mymodel" USING gin (regexp_split_to_array("mymodel"."features", '[,;\\s] '));

Now I need to check the size of the created index in my database. I tried to do it with the following commands

SELECT pg_size_pretty (pg_indexes_size("mymodel"."features_search_idx"));

SELECT pg_size_pretty(pg_indexes_size("features_search_idx")) FROM "mymodel";

The latter one failed with ERROR: column "features_search_idx" does not exist and the former one failed with ERROR: missing FROM-clause entry for table "mymodel".

How can I check the index size?

CodePudding user response:

pg_indexes_size takes an argument of type regclass, that is an object ID that is represented as a string that is the object name. So if you don't supply an object ID, you have to supply a string (single quotes) that is the name of the table:

SELECT pg_size_pretty (pg_indexes_size('mymodel.features_search_idx'));
  • Related