`
wandejun1012
  • 浏览: 2680530 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

linux 安装 postgresql

 
阅读更多

环境:Oracle Linux Server release 5.8 +postgresql-9.1.9.tar.gz

 

思路:

1、将postgresql-9.1.9.tar.gz放到/opt目录下(目录随便放)

2、创建postgres用户及dba组

 

useradd -g dba postgres

 

 

3、将postgresql-9.1.9.tar.gz属主改为postgres.

 

cd /opt
chown postgres postgresql-9.1.9.tar.gz

 

 

4、从root切换到postgres用户

 

su - postgres

 注意中间有空格,切换回root的命令是(su - root或者su  - )

 

 

5、解压postgresql-9.1.9.tar.gz

tar -zxvf postgresql-9.1.9.tar.gz

 

6、进入postgresql-9.1.9目录,进行配置

cd /opt
./configure --prefix=/opt/postgresql --enable-profiling --with-blocksize=8 --with-wal-blocksize=8

 

7、编译,大约需要5分钟

make

 

8、安装

make install

 安装,执行2分钟左右,屏幕打印“PostgreSQL installation complete”表示安装完成。

 

 

9、在/opt/postgresql-9.1.9下面新建data文件夹,并把它的属主改成postgresql,这一部要在root用户下完成

mkdir data
chown postgres data

 

10、初始化数据库,这一步要切换回postgres用户

cd /opt/postgresql-9.1.9/bin
./initdb --encoding=utf8 -D /opt/postgresql/data

 初始化完成后屏幕会显示如下信息:

Success. You can now start the database server using:

    ./postgres -D /opt/postgresql/data

or

    ./pg_ctl -D /opt/postgresql/data -l logfile start

 

 

11、启动数据库,这里用第二种方法,因为第二种方法关闭postgresql很方便。 

./pg_ctl -D /opt/postgresql-9.1.9/data/  start  

 

 

至此,postgresql安装完成,下面开始添加数据库用户/建立新数据库。

 

12、建立新用户sa

cd /opt/bin
./createuser -drSP sa

 Enter password for new role: 123

再输入一遍:123

 

13、建立新数据库

./createdb -O sa mydb

 

至此,用户、数据库建立完成。

下面开始讲解如何通过pgAdmin III 客户端连接到此服务端。

 

14、首先将Linux防火墙停止(也可以将防火墙中新添加5432端口,不过我失败了,只好将防火墙停掉)

service iptables stop

 

15、其次要将Linux设置成对外公开,否则它不对外提供服务。

在/opt/postgresql-9.1.9/data/postgresql.conf中将listen_addresses改成Linux服务器的IP地址,然后将listen_addresses前面的#去掉,把port前面的#去掉。

 

16、另外必须要在pg_hba.conf文件中将客户端的IP地址添加进去(这一步如果不设置的话,在linux控制台中可以看到日志的)

在pg_hba.conf文件最后一行添加:

host all all 172.23.21.60/16 trust 

 

解释:172.23.21.60是起始IP,16代表共有2的16次方个主机, 即65535,即IP段为:172.23.21.60~172.23.255.254

 

好了,至此用pgAdmin III新加一个主机,即可以连接上服务端了。

 

 

 

 

 

 

 

 

 

注:postgresql-9.1.9.tar.gz下载地址:http://ftp.postgresql.org/pub/source/v9.1.9/postgresql-9.1.9.tar.gz

 

refurl:http://blog.csdn.net/dyx1024/article/details/6594522 (主线)

 

http://my.oschina.net/dyx1024/blog/28311(和主线差不多)

 

http://down.chinaz.com/server/201104/244_1.htm(和主线差不多)

 

http://blog.csdn.net/dyx1024/article/details/6594851 (postgresql启动和关闭的方法)

 

http://miao19880124.iteye.com/blog/778732(如何建立用户名、建数据库等)

 

http://www.360doc.com/content/11/0210/13/4171006_91842572.shtml (Linux防火墙开启、关闭等)

 

http://origin100.iteye.com/blog/289925 (防火墙的设置)

 

http://community.itbbs.cn/thread/19530/ 

 

http://www.doserv.com/article/2012-05-02/4368525.shtml

 

http://blog.csdn.net/guo_rui22/article/details/3862282

 

 http://www.linuxidc.com/Linux/2010-11/29705.htm  Centos 5.5 安装postgresql9.0)

http://blog.chinaunix.net/uid-26167002-id-2420320.html   (postgresql源码安装) 

---------------------------------------------------------------------------

关闭的方法:  ./pg_ctl   stop -D ../data -m fast

开启的方法:./pg_ctl start  -D ../data 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics