linux安裝配置postgres及使用dblink

sqysl發表於2016-06-11

好久不寫東西,一直在看些開源的東西,下面貼下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 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();





來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8484829/viewspace-2118618/,如需轉載,請註明出處,否則將追究法律責任。

相關文章