Materialized view on a foreign table with postgresql_fdw - postgresql

Is it possible to use a materialized view on top of a foreign table with postgresql_fdw? (Postgres 9.3)
Currently thinking of some kind of "caching" for postgresql_fdw.

View can be updated by REFRESH MATERIALIZED VIEW. No real need for external triggering.

Related

Using materialized views

I am looking for a mechanism to reload tables from a production environment.
Using materialized views ultimately bring little benefit compare to a basic truncate / insert as select on existing table.
what added value give materialized views?

materialized view mechanism

i learn materialized view for reporting by database. the materialized view as shown on this site https://www.postgresqltutorial.com/postgresql-materialized-views/#:~:text=PosgreSQL%20extends%20the%20view%20concept%20to%20a%20next,then%20allow%20you%20to%20refresh%20this%20result%20periodically. The data in materialized view is depends on the last time you deploy from the table, if the table is being updated, you have to refresh materialized view to have full data. I have search to many sites but, i need to know this materialized view mechanism.
If the data insert into main table and i use refresh materialized view for being updated, does the materialized view truncate or insert mechanism?
or if the data drop in main table and missing some, then i refresh materialized view, is dropping data like truncate or just dropping?
Thank you for your explanation

How to create materialized view of an external table

CREATE VIEW materialized_view WITH SCHEMABINDING AS
SELECT ...
FROM ext.external_table
Fails with
The option 'SCHEMABINDING' is not supported with external tables.
If I understand correctly SCHEMABINDING is necessary to make a materialized view.
How can I correct this query?
You cannot create an indexed view based on tables that are in a different database.
I think your options are:
a) create the indexed view in the other database and create a regular view in this database to query that indexed view
b) create a copy of the table in this database and a mechanism to update this table whenever the data is changed in the table which is in the other database; this could be done with triggers, replication, a stored procedure called on a schedule, etc.

Postgresql materialized view efficient with many refreshes?

Does the postgresql materialize view rebuild the entire table on a REFRESH command? Is it efficient to TRIGGER a refresh to a materialized view that is dependent on a table with heavy writes?
Yes, REFRESH MATERIALIZED VIEW will rebuild the whole materialized view.
It would be very inefficient to do that after every data modufication.
What you could do is to use a normal table instead of a materialized view and write a trigger that keeps the table updated.

TOAD-Modify Materialized View Select Query without dropping

Is there any way I can edit the MVIEW query without dropping it in TOAD.I am not sure if we can do it?If not how Can I do it in a way that does not affect the table contents?
Thanks in advance
You can't alter a materialized view query, you have to drop and recreate it.
See: http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_2001.htm
Use the ALTER MATERIALIZED VIEW statement to modify an existing
materialized view in one or more of the following ways:
To change its storage characteristics
To change its refresh method, mode, or time
To alter its structure so that it is a different type of materialized
view
To enable or disable query rewrite
As pointed out by Jeffre Kemp, you cannot change the query of an existing Materialized View.
However, if you expect that changes will be necessary in the future, you can choose one of these approaches:
use an intermediate VIEW that does all the heavy lifting; your MATERIALIZED VIEW then does a simple SELECT * FROM myView. This allows you to change the query - however, it does not allow you to add / remove columns to/from the MATERIALIZED VIEW
use a pre-built table for your materialized view; this logically separates the TABLE that holds the content from the query that is used to update the content. Now, you can drop the MATERIALIZED VIEW, add/remove columns from your TABLE as needed, and re-create the MATERIALIZED VIEW afterwards
use a synonym for all code that queries the MATERIALIZED VIEW; if necessary, create a backup table using CTAS, point the synonym to this backup table, drop and re-create your MATERIALIZED VIEW, point the synonym back to the MATERIALIZED VIEW, and drop your backup table (that's how we do it)