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();
 

 

 

原文地址:https://www.cnblogs.com/lhdz_bj/p/8759064.html