Great and glad it worked for you.. it's always better to cache the foreign server details onto postgres wrappers.. so that your calls to foreign objects would be simpler and more secure..
First you need to create foreign server, foreign data wrapper then followed by granting access to use the postgres_fdw.. then try accessing it.. that's the optimal way.. I'm not getting what is being tried here