How to use (install) dblink in PostgreSQL?

I use Oracle and create dblink in my schema and then access the remote database as follows: mytable@myremotedb , anyway, with PostgreSQL?

I am currently using dblink as follows:

 SELECT logindate FROM dblink('host=dev.toto.com user=toto password=isok dbname=totofamily', 'SELECT logindate FROM loginlog'); 

When I execute this command, I get the following error:

TIP: no function matches the specified name and argument types. You may need to add explicit types.

Does anyone have any ideas? Do I need to โ€œactivateโ€ dblinks or do something before using them?

Is there anything to do in the remote database that we will query? Do I need to activate dblink? I keep having could not establish connection . This is a string like:

 SELECT dblink_connect_u('host=xxxx dbname=mydb user=root port=5432'); 

The IP address is correct and Postgres is running on the remote server. Any idea?

+38
sql postgresql dblink
Oct 05 '10 at 10:08
source share
7 answers

With PostgreSQL 9.1 or later , the installation of additional modules has been simplified. Registered extensions (including dblink) can be installed using CREATE EXTENSION :

 CREATE EXTENSION dblink; 

Installed in the default scheme ( public by default). Make sure your search_path set correctly before running the command, and that the scheme is visible to all users who need to work with it.

Run once for each database. Or run it in the standard system database template1 to automatically add it to each created database. Details in the manual.

First you must have the files that provide the module installed on the local computer. Obviously, for Debian and its derivatives, this will be the postgresql-contrib-9.1 package - for PostgreSQL 9.1.

+79
Nov 07 '12 at 7:22
source share

I am using DBLINK to connect an internal database for cross-database queries.

Link taken from this article.

Install the DbLink extension.

 CREATE EXTENSION dblink; 

Check out DbLink:

 SELECT pg_namespace.nspname, pg_proc.proname FROM pg_proc, pg_namespace WHERE pg_proc.pronamespace=pg_namespace.oid AND pg_proc.proname LIKE '%dblink%'; 

Check database connection:

 SELECT dblink_connect('host=localhost user=postgres password=enjoy dbname=postgres'); 
+11
Oct 23 '15 at 9:44
source share

In linux, find dblink.sql, then do something like this in the postgresql console to create all the necessary functions:

 \i /usr/share/postgresql/8.4/contrib/dblink.sql 

you may need to install contrib packages: sudo apt-get install postgresql-contrib

+10
Mar 03 '11 at 2:16
source share

To install the modules, you usually need to run the sql script, which is included in the database installation.

Assuming a Linux-like OS

 find / -name dblink.sql 

Check the location and run it

+4
05 Oct '10 at 10:20
source share

It can be added using:

 $psql -d databaseName -c "CREATE EXTENSION dblink" 
+1
09 Oct '14 at 13:11
source share
 # or even faster copy paste answer if you have sudo on the host sudo su - postgres -c "psql template1 -c 'CREATE EXTENSION IF NOT EXISTS \"dblink\";'" 
0
Jul 28 '17 at 15:14
source share



All Articles