下载并解包
$ 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
=== 配置完成 ===
$ 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]