FDW, replication and CREATE SERVER - will it work? We have two servers (master, slave) and we want to use the FDW. The two databases to be connected with the FDW are both on the master (and the slave of course).  When we are to CREATE SERVER we would run something like:

CREATE SERVER server_db2 FOREIGN DATA WRAPPER postgres_fdw 
    OPTIONS (host 'master', dbname 'db2', port '5432');


The question is this:  Does the slave create the server_db2 and connects to the master's IP address?  What will happen if I break the relationship and the slave is promoted to master? I suppose it will be looking for the master to connect right?

Would connecting via 127.0.0.1 and setting the method to something other than trust be a safe option?

In general the behavior of the postgres_fdw is unclear to me in a replicated environment.
You cannot really use postgres_fdw to connect from a replica server to the master, because you cannot create the foreign server on the replica, it is read only.

You'd have to run the create on the master, then rely on it replicating to the read-replica.

Even if you were to do this, it would make no sense. There is no point connecting from a replica to the master, because the replica has the same data as the master. There is no purpose to doing this.