Hacker News new | ask | show | jobs
by michelpp 2761 days ago
You cannot have a local index for a FDW, how would it know to update when the foreign data changed? an approach you can take if you want indexed data from an fdw is to materialize the data (or a subset of it) and index that with 'CREATE MATERIALIZED VIEW... AS SELECT ... FROM my_fdw...' and then index columns of that view.

You _can_ run ANALYZE on foreign tables:

"When use_remote_estimate is true, postgres_fdw obtains row count and cost estimates from the remote server and then adds fdw_startup_cost and fdw_tuple_cost to the cost estimates. When use_remote_estimate is false, postgres_fdw performs local row count and cost estimation and then adds fdw_startup_cost and fdw_tuple_cost to the cost estimates. This local estimation is unlikely to be very accurate unless local copies of the remote table's statistics are available. Running ANALYZE on the foreign table is the way to update the local statistics; this will perform a scan of the remote table and then calculate and store statistics just as though the table were local. Keeping local statistics can be a useful way to reduce per-query planning overhead for a remote table — but if the remote table is frequently updated, the local statistics will soon be obsolete."

https://www.postgresql.org/docs/11/postgres-fdw.html#id-1.11...