安装包:postgresql-8.2.0.tar.gz
安装步骤
1,进入Linux的命令行模式,登陆后进到存放postgresql-8.2.0.tar.gz的文件夹
例如我把安装包放在/home/lsp文件夹下,那么命令为:
[root@localhost root]# cd /home/lsp
2,解压安装包:
[root@localhost lsp]# tar -xzvf postgresql-8.2.0.tar.gz
3,进入解压后的文件夹:
[root@localhost lsp]# cd postgresql-8.2.0
4,配置源代码树:
[root@localhost postgresql-8.2.0]# ./configure
说明:如果在后面增加参数“--prefix=PREFIX”可以实现设置安装路径的功能
比如:# ./configure --prefix=/home/lsp/pgsql
不设置会安装在默认路径“/usr/local/pgsql”下
5,制作:
[root@localhost postgresql-8.2.0]# gmake
显示的最后一行应该是:All of PostgreSQL is successfully made. Ready to install.
6,安装:
[root@localhost postgresql-8.2.0]# gmake install
说明:其实5,6可以合成为一步[root@localhost postgresql-8.2.0]# gmake && gmake install
7,设置共享库:
[root@localhost postgresql-8.2.0]# /sbin/ldconfig /usr/local/pgsql/lib/
8,配置环境变量:
[root@localhost postgresql-8.2.0]# vi /etc/profile
PGLIB=/usr/local/pgsql/lib
PGDATA=$HOME/data
PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PGLIB PGDATA PATH MANPATH
9,添加PostgreSQL用户帐户postgres(这个名字可以自己取):
[root@localhost postgresql-8.2.0]# adduser postgres
10,创建数据库集群:
[root@localhost postgresql-8.2.0]# mkdir /usr/local/pgsql/data
[root@localhost postgresql-8.2.0]# chown postgres /usr/local/pgsql/data
[root@localhost postgresql-8.2.0]# su postgres
[postgres@localhost postgresql-8.2.0]$ initdb -D /usr/local/pgsql/data
说明:(1)创建存放数据库的目录
(2)将存放数据库的目录的权限交给用户postgres
(3)切换到用户postgres
(4)用户postgres创建数据库集群
11,启动数据库:
我们要回到图形化界面运行Terminal(图形化界面里面的命令行)
[root@localhost root]# su postgres
[postgres@localhost root]$ postmaster -D /usr/local/pgsql/data
LOG: database system was interrupted at 2007-01-24 04:19:37 HKT
LOG: checkpoint record is at 0/42C46C
LOG: redo record is at 0/42C46C; 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 was not properly shut down; automatic recovery in progress
LOG: record with zero length at 0/42C4B4
LOG: redo is not required
LOG: database system is ready
就说明数据库服务已经开启了。
12,新建个数据库测试一下:
再打开一个Terminal
[root@localhost root]# su postgres
[postgres@localhost root]$ createdb /usr/local/pgsql/data/mydb
提示CREATE DATABASE表示创建成功
13,进入交互工具psql:
[postgres@localhost root]$ psql /usr/local/pgsql/data/mydb
会出现如下提示:
Welcome to psql 8.2.0, 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
/usr/local/pgsql/data/mydb=#
14,这时就可以输入SQL命令了:
建表:/usr/local/pgsql/data/mydb=# CREATE TABLE mytable(id varchar(20),name varchar(20));
插入:/usr/local/pgsql/data/mydb=# INSERT INTO mytable values('2007001', 'postgres');
查询:/usr/local/pgsql/data/mydb=# SELECT * FROM MYTABLE;