postgresql 安装
时间:2005-03-26 来源:emailwht
postgresql 安装
转至http://java.mblogger.cn/
  先创建账号
  #groupadd postgresql
  #useradd -g postgresql postgresql
  上传postgresql的源码包,我这儿是postgresql-7.4.3.tar.gz,使用tar命令解压
  #tar xvfz postgresql-7.4.3.tar.gz
  设置JAVA、ANT的环境变量,如果不需要生成postgresql的jdbc jar文件,则可以跳过(configure时不用--with-java参数)
  #export JAVA_HOME=/www/server/j2sdk1.4.2_04/
  #export ANT_HOME=/www/server/apache-ant-1.6.1/
  #export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
  开始编译安装
  #./configure --prefix=/www/server/postgresql-7.4.3 --with-java
  #make
  #make install
  创建数据库目录
  #mkdir /www/server/postgresql-7.4.3/data
  # chown -R postgresql:postgresql /www/server/postgresql-7.4.3/data/
  # su -  postgresql
  #cd /www/server/postgresql-7.4.3/bin/
  数据库初始化
  #./initdb -D ../data/
  
  使用pg_ctl命令控制postgresql服务,pg_ctl的详细用法可--help获得
    pg_ctl start   [-w] [-D DATADIR] [-s] [-l FILENAME] [-o "OPTIONS"]
    pg_ctl stop    [-W] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]
    pg_ctl restart [-w] [-D DATADIR] [-s] [-m SHUTDOWN-MODE] [-o "OPTIONS"]
    pg_ctl reload  [-D DATADIR] [-s]
    pg_ctl status  [-D DATADIR]
  
  使用createdb命令创建数据库(数据库名为dm)
  #./createdb dm
  创建一个postgresql的用户账号,(使用--help获得所有参数,-A表示不允许此账号添加新用户,-D不允许此账号创建数据库,-E表现加密存储密码,-P在创建账号时提示输入登录密码)
  #./createuser -A -D -E -P dm
  Enter password for new user:
  Enter it again:
  CREATE USER
  现在可以使用psql命令了(感觉类似于oracle的sqlplus)
  #./psql -d dm -U dm
  Welcome to psql 7.4.3, the PostgreSQL interactive terminal.
  Type:  copyright for distribution terms
         h for help with SQL commands
         ? for help on internal slash commands
         g or terminate with semicolon to execute query
         q to quit
  dm=>
  
  要想远程tcpip连接postgresql,还要改文件
  #cd /www/server/postgresql-7.4.3/data
  #vi postgresql.conf (加上下面这句,或是把#tcpip_socket = false的注释去掉,并且改为true,如果需要更改端口,改#port = 5432)
  tcpip_socket = true
  接下来再改pg_hba.conf文件
  #vi pg_hba.conf
  我想在任何地址上操作dm的库,登录密码使用md5,添加
  host    dm          dm          0.0.0.0           0.0.0.0           trust
  
  使用pg_ctl命令重启服务后,远程用pgAdminIII登录成功。










