Postgres uses dblink

Source: Internet
Author: User

In Oracle, dblink is often used to import some online data to the development database to locate the problem.

Dblink can also be used in PostgreSQL.

The following is an online document:

1. How to Create dblink in PostgreSQL?
2. How do I use dblink after the build is successful?
3. What is the difference between dblink in PostgreSQL and dblink in Oracle?

The solution is as follows:

Question 1:

# Useradd postgre (automatically create a postgre Group)

Decompress the package to/usr/local/src:
# Tar xvfz postgresql-7.1.3.tar.gz
# Cd postgresql-7.1.3
#./Configure -- prefix =/usr/local/pgsql
# Make
# Make install
# Chown-r postgre. postgre/usr/local/pgsql

# Vi ~ Postgre/. bash_profile
Add:

Pglib =/usr/local/pgsql/lib
Pgdata = $ home/Data
Path = $ path:/usr/local/pgsql/bin
Manpath = $ manpath:/usr/local/pgsql/man
Export pglib pgdata path manpath

Log On As an ipvs user,
# Su-postgre
Create a database directory:
$ Mkdir data

Start the database engine:
[Postgre @ WWW postgre] $ initdb
[Postgre @ WWW postgre] $ postmaster-I-d ~ /Data &
In this way, PostgreSQL uses a database located in/usr/local/pgsql/data to allow Internet users to connect (-I) and run it in the background.
At this step of installation, the database is running

Create databases and tables
$ Createdb mydb

Then enter/contrib/dblink
Make/make install
// After success, start pg_ctl restart
Run
Psql-F dblink. SQL-D database-u User Name


Question 2:
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.

Question 3
I feel like
PostgreSQL has stricter permission settings than orcale ..

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.