Search code examples
postgresqlpostgres-fdw

How would you create a unique index on a foreign table?


Database 1 has foreign tables a and b on database 2.

How can we create indexes on these foreign tables a and b. These foreign tables are wrappers over database2.c and database2.d tables respectively, which do have the necessary indexes in place.

How would you create indexes on foreign tables a and b? Is that even possible?

I get a cannot create index on foreign table a - when I try a simple Create Index command in postgres


Solution

  • You cannot create index on a foreign table, instead write a trigger on foreign table and create a local table in postgres such that whenever an insert, update or delete is happening in your foreign table it will be reflected in your local table and index it.