Postgresql数据库的安装指引


一、解压数据库































cd /usr/local/src linux






























tar -jxvf postgresql-8.4.14.tar.bz2


























































二、进入数据库文件





























  cd postgresql-8.4.14



























  将数据库安装指定到特定的目录postgresqlsql





































  (postgresql文件夹是新建)






  ./configure --prefix=/usr/local/postgresql/























































有可能出现如下报错提示找不到readline,但readline已经安装,说明缺乏了readline-devel可经过yum安装

A、配置/etc/yum.repos.d/rhel-debuginfo.repo (注意linux版本不同配置也会有所不一样)





[base]

































name=Server Local Sources


























baseurl=file:///media/rhel/Server























enable=1
































gpcheck=1
































gpgkey=file:///media/rhel/RPM-GPG-KEY-redhat-release















B、挂载光驱的系统盘数据库






























  新建一个目录用于挂载点:mkdir /media/rhel



















   mount /dev/cdrom /media/rhel























C、验证挂载是否成功查看df -Th
























D、yum安装相关软件




























yum makecache 清理缓存


























yum install readline -devel

























  yum install read*



























三、编译&安装































gmake

































gmake install



































































四、增长postgresql专用用户


























  useradd postgres

































































五、切换postgres用户以前,先创建数据目录data并赋给postgres用户













  mkdir /postgresql/data


























  chown postgres /usr/local/postgresql/data




















  su - postgres


































































六、初始化目录数据





























/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data











/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data >logfile 2>&1 &









































七、启动postgresql数据库



























/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data










启动报以下错误






























LOG: could not translate host name "localhost", service "5432" to address: Name or service not known
WARNING: could not create listen socket for "localhost"














FATAL: could not create any TCP/IP sockets



















解决办法是:修改/etc/hosts

























增长了  127.0.0.1       localhost localhost.localdomain














八、再次启动postgresql



























/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data  缓存













出现以下提示,说明数据库安装成功
























LOG:database system was shut down at 2012-12-10 10:22:40 CST












LOG:database system is ready to accept connections
















LOG:autovacuum launcher started




























































八、之后台服务方式启动以前,切换到root在/usr/local/postgresql/data/建立logfile文件,并赋用户postgres
$su - root






























touch /usr/local/postgresql/data/logfile



















chown postgres logfile


























/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data >logfile 2>&1 &











































































九、数据库的启动与关闭



























 $ cd /usr/local/postgresql/bin























  ./pg_ctl -D /usr/local/postgresql/data start

















  ./pg_ctl -D /usr/local/postgresql/data stop


















十、建立数据库及链接数据库

























/usr/local/pgsql/bin/createdb test






















/usr/local/pgsql/bin/psql test安全


























十一、数据库的一些相关配置



























容许远程链接






























postgresql由于安全方面的考虑,默认状况下只接受本机的链接。为了管理的方便,咱们须要开通远程链接。
修改data/postgresql.conf,增长:























122248753.png





































修改监听端口:






























122349307.png





































修改data/pg_hba.conf,增长md5那一行:





















122439806.png





































而后重启posgtres。




























修改配置后立刻生效不重启:

























cd /usr/local/postgresql/bin

























pg_ctl reloaddom
































十二、把Postgres服务设置为自动启动























进入postgresql的源代码解压目录:cd /usr/local/src/postgresql-8.4.14










#cp contrib/start-scripts/linux /etc/init.d/postgresql















#chmod a+x /etc/init.d/postgresql























#cd /etc/init.d/





























#chkconfig --add postgresql

























#chkconfig postgresql --level 345 onsocket
























1三、在postgresql中建立用户,并设置数据库ide






















create database test owner test;























这样就设置了一个数据库叫test,而且它的拥有者是一个叫test的用户