How it works...

When it comes to this recipe, we begin by moving the existing pgbench_accounts table out of the way. The intent in this case is to prove that we can treat a materialized view similarly to a local table. To do this, we want to create it with the same name the foreign table currently uses. Thus, pgbench_accounts becomes remote_accounts and better illustrates its relationship with the foreign server as a bonus.

Next, we create the actual materialized view. We could define all of the columns manually, but in this case, we want it to simply mirror the remote table. Think of this as object-oriented programming; we have a class named pgbench_remote, and we will instantiate it as pgbench_accounts.

Notice, however, that we added a ...

Get PostgreSQL High Availability Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.