The dblink function in PostgreSQL is used to access remote database data through the current database environment. Of course, you must have the permission to access the remote database. It has similar functions as dblink in Oracle.
In Windows, dblink configuration is easier than in Linux, because after you install PostgreSQL, dblink exists in the PostgreSQL/8.1/lib directory of your installation directory. DLL file (equivalent to dblink in Linux. so file), this is the function file necessary to use dblink, of course, in Linux environment you can create through the following method. so file:
# Cd contrib/dblink
# Make
# Make install
The next step is to import the dblink functions in the database where you need to remotely access other databases. These functions have been officially written for you, it is the dblink stored in the PostgreSQL/8.1/share/contrib directory. SQL file, you only need to enter the PostgreSQL command line to execute the following statement:
... Bin> Psql-d [database name]-f [SQL file name (that is, path + name of dblink. SQL file)]
Okay. If you see a string of create functions, it means it is successful. Next, let's get started with the dblink function.
(The following part is network excerpt)
Enter Psql below:
Pgsql = # select dblink_connect ('host = localhost user = pgsql Password = ');
Dblink_connect
----------------
OK
(1 row)
This function is used to establish a connection to a remote database.
We can insert a record in a remote database as follows:
Pgsql = # select dblink_exec ('insert into student values (/'linux _ prog/',/'2017 /')');
Dblink_exec
-------------------
Insert 22516276 1
(1 row)
Now we can retrieve the insert record:
Pgsql = # select * From dblink ('select * from student ') as student (name varchar (100), pass varchar (100 ));
Name | pass
------------ + -------
Linux_prog | 12345
(1 row)
How is it? The insert record is already in.
Dblink is very powerful. I listed it as its simplest application. You can refer to the source code of postgresql below:
Contrib/dblink/SQL/dblink. SQL take a closer look.