在上一篇在Ubuntu中通过源码安装编译安装软件(MySQL篇)中主要介绍了通过源码编译安装作为数据存储的MySQL,但是相信众多的Fans应该知道MySQL被SUN公司收购,对此也表示了不放心;近期释出的MySQL版本就对功能进行了限制,参考MySQL 5.1.24 rc版本中已取消集群功能。PostgreSQL尽管非常优秀,但是由于这么多年来一直缺乏一家公司来进行支撑运营,所以一直默默无闻,第一次了解PostgreSQL是在台湾的一个个人网站上,花了一晚上将作者写的关于PostgreSQL的推荐文章实际项目的实践以及测试数据全部看完。今天再次Google去找那个网站,非常遗憾没有找着。
这一篇将主要介绍PostgreSQL在Ubuntu Server平台下的编译安装方法在Windows下通过PgAdmin来进行管理数据库。
前三步和上次安装MySQL一样,如果上次已经做过了可以省略前三步
1、更新您的Ubuntu
sudo apt-get update
sudo apt-get upgrade
2、安装所需软件包
sudo apt-get install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.3-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential
3、安装libncurses5-dev
sudo apt-get install libncurses5-dev
到 http://www.postgresql.org/ftp/ 下载PostgreSQL源码,最新版是 PostgreSQL 8.3.1
adduser postgres
tar -vxf postgresql*.tar.gz
./configure --prefix=/usr/local/postgresql
make
make install
mkdir /usr/local/postgresql/data
chown postgres /usr/local/postgresql/data
chown -R postgres /usr/local/postgresql
su – postgres
初始化数据库:
/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data
运行数据库服务器:
/usr/local/postgresql/bin/postmaster -D /usr/local/postgresql/data>logfile 2>&1 &
创建一个数据库:
/usr/local/postgresql/bin/createdb test
在本机上运行客户端进行管理:
/usr/local/postgresql/bin/psql test
根据需要对Postgresql的配置文件Postgresql.conf进行修改,该文件在数据目录/usr/local/postgresql/data下,
比如你需要用局域网或通过互联网远程管理Postgresql进行管理,就需要把# listen_address=’localhost’改为
listen_address='*',记住要去掉注释,这点用过MySQL的用户比较好理解,
接下来修改Postgresql的配置文件pg_hba.conf,该文件在数据目录/usr/local/postgresql/data下,在文件后面加一句:
host all all 192.168.0.0/24 password
就是允许192.168.0.0网段的所有用户通过密码来访问数据库。
重新启动postgresql服务器:
/usr/local/postgresql/bin/pg_ctl stop -D /usr/local/postgresql/data
停止原来的服务器
/usr/local/postgresql/bin/postmaster -i -D /usr/local/postgresql/data >logfile 2>&1 &
更多关于PostgreSQL的配置和管理请参考
PostgreSQL官方网站
PostgreSQL 中文网
Windows台PostgreSQL管理工具:pgAdmin III v1.8.2