How it works...

We start by connecting to the database where we will be accessing remote data. As our test database is pgbench, this is where the foreign server will reside.

Server creation itself consists of a server name, a foreign data wrapper, and options to the foreign data wrapper. For the server name, we used primary_db to keep things simple, but anything relatively descriptive is a good choice.

The CREATE SERVER statement can use several available foreign data wrappers, but to contact a PostgreSQL server, we need postgres_fdw. This data wrapper will accept many standard PostgreSQL connection parameters, including host, dbname, port, and so on.

We only used the dbname and host settings because we don't want to force this server connection ...

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.