Configure the dblink function of postgresql in Windows

Source: Internet
Author: User
Tags psql

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.