RedHat Linux 安装 PostgreSQL 8.4.2

下载并解包
$ tar zxvf postgresql-8.2.4.tar.gz
$ cd postgresql-8.2.4
配置
$ ./configure --prefix=/usr/local/pgsql-8.2.4
  ...
  config.status: linking ./src/makefiles/Makefile.linux to src/Makefile.port
编译
$ make
  ...
  All of PostgreSQL successfully made. Ready to install.
测试
$ make check
  ...
  =======================
   All 103 tests passed.
  =======================
安装(root)
# su -
# groupadd postgresql
# useradd -g postgresql postgresql
# cd <安装目录>
# make install
  ...
  PostgreSQL installation complete.
# cd /usr/local
# ln -s pgsql-8.2.4 pgsql
# mkdir /usr/local/pgsql/data
# cd /usr/local/pgsql
# chown postgresql.postgresql data
初始化数据库目录(postgresql)
# su - postgresql
$ cd /usr/local/pgsql/bin
设置locale为C,并且template1编码为UNICODE,使数据库支持中文
$ ./initdb --locale=C -E UNICODE -D ../data/
  ...
  Success. You can now start the database server using:
    ./postgres -D ../data
  or
    ./pg_ctl -D ../data -l logfile start
配置环境变量及日志文件(root)
$ (^d)
# vi /etc/profile
    PATH=/usr/local/pgsql/bin:$PATH
    PGDATA=/usr/local/pgsql/data
使环境变量生效(或重启操作系统)
# export PGDATA=/usr/local/pgsql/data
# touch /var/log/pgsql.log
# chown postgresql.postgresql /var/log/pgsql.log
修改配置文件(postgresql)
$ su - postgresql
$ cd /usr/local/pgsql/data
修改配置使监听生效,取消以下两行的注释
$ vi postgresql.conf
    listen_addresses = '*' # what IP address(es) to listen on;
    port = 5432            # (change requires restart)

启动数据库(postgresql)
$ cd /usr/local/pgsql/bin
$ ./postmaster -D /usr/local/pgsql/data > /var/log/pgsql.log 2>&1 &
$ cat /var/log/psql.log
  LOG:  checkpoint record is at 0/42C424
  LOG:  redo record is at 0/42C424; undo record is at 0/0; shutdown TRUE
  LOG:  next transaction ID: 0/593; next OID: 10820
  LOG:  next MultiXactId: 1; next MultiXactOffset: 0
  LOG:  database system is ready
创建数据库dm
$ ./createdb dm
  CREATE DATABASE
创建用户
$ ./createuser -A -D -E -P dm
  Enter password for new role: 123456
  Enter it again: 123456
  Shall the new role be allowed to create more new roles? (y/n) y
  CREATE ROLE
使用psql
$ ./psql -d dm -U dm
  Welcome to psql 8.2.4, the PostgreSQL interactive terminal.
  Type:  /copyright for distribution terms
       /h for help with SQL commands
       /? for help with psql commands
       /g or terminate with semicolon to execute query
       /q to quit

  dm=> /q

*在psql中若需要使用中文,先发送:
dm=> set client_encoding to 'gbk';

配置数据库自启动脚本(root)
$ (^d)
# cd /etc/rc.d/init.d
# cp (安装目录)/postgresql-8.2.4/contrib/start-script/linux postgresql
# chmod +x postgresql
# vi postgresql
    prefix=/usr/local/pgsql
    PGDATA="/usr/local/pgsql/data"
    PGUSER=postgresql
    PGLOG="/var/log/pgsql.log"
# chkconfig --add postgresql
重启数据库
# /etc/rc.d/init.d/postgresql restart
=== 配置完成 ===

相关的贴子:
[http://java.mblogger.cn/wuyu/posts/9222.aspx]
[http://www.pgsqldb.org/pgsqldoc-8.1c/index.html]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值