postgresqlamazon-rdsdblink

Create db_link to the same Database in Postgres


We do have a requirement to create a db_link(Database link) have to refer to the same database.

When I am looking at the code in the function. It is some how like this.

perform dblink_connect(cn,'loopback'::text);
   cn is the connection name;

I verified if there are any foreign servers with the name loopback by using this query. But, no luck

select 
    srvname as name, 
    srvowner::regrole as owner, 
    fdwname as wrapper, 
    srvoptions as options
from pg_foreign_server
join pg_foreign_data_wrapper w on w.oid = srvfdw;

I suspect that loopback refers to the same database.

When I execute the Function, I am receiving the below error

**Error:password is required**

I verified the db_link extension it's there and dblink_fdw is also there

Environment:Postgres RDS

Solution

  • The function call should look like this:

    PERFORM dblink_connect(cn, 'host=loopback user=...');
    

    This is a normal libpq connect string; see the documentation for details.

    It would be smarter to use the IP addresses in the connection string, like

    host=127.0.0.1 user=...
    

    or to use domain socket connections, like this

    host=/var/run/postgresql user=...
    

    (that is, if your unix_socket_directories contains this directory).

    pg_hba.conf should contain lines like

    # lockal socket connections
    local   all             all                                     trust
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            trust
    # IPv6 local connections:
    host    all             all             ::1/128                 trust
    

    If you want password authentications, use md5 instead of trust and supply a password in the connection string.

    I have never heard of dblink_fdw …