I want to you table which is located in the other database.
I am using the dblink for this.
Procedure:
Step 1: Created extension.
CREATE EXTENSION dblink;
Step 2: Making dblink connection string.
select dblink_connect('con','host=127.0.0.1 dbname=makdb user=postgres password=postgres');
Step 3:
select * from dblink('con','select cola,colb from tbl_test') as tbl(cola int,colb varchar(10));
My Question: How do i hide password in step 2?
By searching i came to know that i need to create .pgpass
file. But got stuck in how to create and in which step i need to use that file name.
Install dblink extension:
Install postgres_fdw extension (which can be used to access data stored in external PostgreSQL servers):
Create a new foreign server connection:
Create a user mapping for the foreign server connection that you recently created and your database.
Select some fields in a remote db with the conexion created. Notice that you does not need use the user and password anyrmore.
More info:
https://www.postgresql.org/docs/9.5/postgres-fdw.html
https://www.postgresql.org/docs/current/sql-createserver.html
https://www.postgresql.org/docs/current/sql-createusermapping.html