How to connect to localhost with postgres_fdw?

后端 未结 2 2049
长情又很酷
长情又很酷 2021-01-02 16:59

The idea is that I have local database named northwind, and with postgres_fdw I want to connect with another database named test on lo

2条回答
  •  忘掉有多难
    2021-01-02 17:33

    You may connect using Unix Domain Socket instead of TCP connection to gain simpler configuration and better performance (Linux/Unix only, not supported in Windows).

    CREATE SERVER app_db
    FOREIGN DATA WRAPPER postgres_fdw
    OPTIONS (dbname 'test');
    

    Also, you may omit the password if peer authentication is enabled (default).

    CREATE USER MAPPING for postgres
    SERVER app_db 
    OPTIONS (user 'postgres');
    

    Note: peer authentication can only be used for postgres user as the FDW connection is created by the server backend which runs as the system user postgres.

    Also, for security reasons, postgresq_fdw allows peer authentication only for clients with SUPERUSER privilege. To allow restricted users to use the FDW, you have to use password authentication as described in this answer

提交回复
热议问题