linux安裝配置postgres及使用dblink
好久不寫東西,一直在看些開源的東西,下面貼下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
或
configure --prefix=/usr/local/pgsql --with-perl --with-python
--註:
1)configure過程中,如報錯:configure:error:readline library not found,其實是readline-devel未被安裝,yum -y install readline-devel安裝即可。
2)configure過程中,如報錯:configure:error:zlib not installed,其實是zlib-delvel未被安裝,yum -y install zlib-delvel安裝即可。
3)configure過程中,如報錯:configure:error:header file <Python.h>is required,其實是pyhton-delvel未被安裝,yum -y install python-delvel安裝即可。
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();
linux安裝配置postgres及使用dblink