好久不寫東西,一直在看些開源的東西,下面貼下linux上安裝配置postgres及使用dblink的操作參考,以供讀者和自己今後參考:
1、下載源碼:postgresql-9.3.2.tar.gz
2、建立postgres cluster組和使用者:
groupadd postgres
useradd postgres -d /home/postgres -g postgres
mkdir -p /usr/local/pgsql
mkdir -p /use/local/pgsql/data
chown -R postgres.postgres /usr/local/pgsql
passwd postgres
su -postgres
cd
vi bash_profile
export PGHOME=/usr/local/pgsql
export PGDATA=/usr/local/pgsql/data
export PATH=$PATH:/usr/local/pgsql/bin
. .bash_profile
3、將源碼檔案傳至資料庫伺服器:
/usr/local/pgsql/postgresql-9.3.2.tar.gz
cd /usr/local/pgsql
tar zxf postgresql-9.3.2.tar.gz
4、配置及安裝資料庫:
cd /usr/local/plsql/postgresql-9.3.2
configure
make
su -
make install
5、初始化資料庫:
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
6、配置參數檔案:
cd /usr/local/pgsql/data
vi postgresql.conf
--監聽和連接埠
7、配置登入安全規則:
vi pg_hba.conf
8、登入postgres並修改密碼:
psql postgres postgres
alter user postgres password 'test';
9、配置dblink:
cd /usr/local/pgsql/postgresql-9.3.2/contrib/dblink
make
su
make install
psql postgres postgres
create extension dblink;
select * from pg_extension;
10、建立和使用dblink
psql test test
select dblink_connect('test_dblink','dbname=postgres host=192.168.109.10 port=1921 user=postgres password=test');
select * from dblink('test_dblink','select c1,c3 from ttt') as t1 (c1 integer,c2 varchar);
select dblink_disconnect('test_dblink');
Select dblink_get_connections();