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 ..