Linux安装PostgreSQL9.0

以前对PostgreSQL研究比较少,这几天没事就对这个数据库研究一下,第一步当然是安装了

相关软件可在在官网上下载:http://www.postgresql.org/download/

其实安装也比较简单,现将软件SSH到root用户下(注意,只能在root用户下安装)

[root@rhsde opt]# chmod 777 postgresql-9.0.8-1-linux-x64.run
[root@rhsde opt]# ./postgresql-9.0.8-1-linux-x64.run
----------------------------------------------------------------------------
Welcome to the PostgreSQL Setup Wizard.

----------------------------------------------------------------------------
Please specify the directory where PostgreSQL will be installed.

Installation Directory [/opt/PostgreSQL/9.0]:

----------------------------------------------------------------------------
Please select a directory under which to store your data.

Data Directory [/opt/PostgreSQL/9.0/data]:

----------------------------------------------------------------------------
Please provide a password for the database superuser (postgres). A locked Unix
user account (postgres) will be created if not present.

Password :
Retype password :
----------------------------------------------------------------------------
Please select the port number the server should listen on.

Port [5432]:

//相关字符集的选择
.....
[628] zh_SG.utf8
[629] zh_TW.euctw
[630] zh_TW.utf8
[631] zu_ZA
[632] zu_ZA.iso88591
[633] zu_ZA.utf8
Please choose an option [1] :

----------------------------------------------------------------------------
Setup is now ready to begin installing PostgreSQL on your computer.

Do you want to continue? [Y/n]: y

----------------------------------------------------------------------------
Please wait while Setup installs PostgreSQL on your computer.

 Installing
 0% ______________ 50% ______________ 100%
 #########################################

----------------------------------------------------------------------------
Setup has finished installing PostgreSQL on your computer.
安装过程中全部回车即可,不过你需要弄清楚都做了些什么

1:PostgreSQL软件装在什么地方

2:PostgreSQL的数据Data放在什么地方

3:为超级用户postgres设置密码以及确认

4:设置端口号默认的是5432

5:选择字符集

6:是否继续


如果安装成功后,我们可以看到,系统会自动创建一个postgres用户,他所在的路径为你选择的PostgreSQL安装的路径,不过该用户的环境变量没有设置好,我们需要设置一下即可

[root@rhsde opt]# su - postgres
-bash-3.2$ pwd
/opt/PostgreSQL/9.0
-bash-3.2$ su -
Password:
[root@rhsde ~]# cp .bash_profile /opt/PostgreSQL/9.0
[root@rhsde ~]# cp .bashrc /opt/PostgreSQL/9.0
[root@rhsde ~]# su - postgres

然后就是,虽然是root用户下安装,那么安装的文件的权限所属的是root用户,那么我们需要将这些文件转为postgres用户

[root@rhsde PostgreSQL]# ll
total 4
drwxr-xr-x 12 root daemon 4096  8月 24 08:52 9.0
[root@rhsde PostgreSQL]# pwd
/opt/PostgreSQL
[root@rhsde PostgreSQL]# chown -R postgres:postgres /opt/PostgreSQL/
[root@rhsde PostgreSQL]# ll
total 4
drwxr-xr-x 12 postgres postgres 4096  8月 24 08:52 9.0

然后设置postgres用户的环境变量

export PGHOME=/opt/PostgreSQL/9.0
export PATH=$PGHOME/bin:$PATH
export PGDATA=$PGHOME/data
export LD_LIBRARY_PATH=$PGHOME/lib

然后我们可以启动服务,其实默认服务以及启动了

[root@rhsde ~]# service postgresql-9.0 start
Starting PostgreSQL 9.0:
pg_ctl: another server might be running; trying to start server anyway
pg_ctl: could not start server
Examine the log output.
PostgreSQL 9.0 did not start in a timely fashion, please see /opt/PostgreSQL/9.0/data/pg_log/startup.log for details
查看一下相关日志,我们可以看到已经启动了服务
[root@rhsde ~]# more /opt/PostgreSQL/9.0/data/pg_log/startup.log
2012-08-24 00:56:54 GMT FATAL:  lock file "postmaster.pid" already exists
2012-08-24 00:56:54 GMT HINT:  Is another postmaster (PID 27765) running in data direc
tory "/opt/PostgreSQL/9.0/data"?

我们也可以检查一下服务状态和端口情况

[root@rhsde ~]# chkconfig --list postgresql-9.0
postgresql-9.0  0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@rhsde ~]# netstat -ano | grep 5432
tcp        0      0 0.0.0.0:5432                0.0.0.0:*                   LISTEN      off (0.00/0/0)
tcp        0      0 :::5432                     :::*                        LISTEN      off (0.00/0/0)
unix  2      [ ACC ]     STREAM     LISTENING     3759370 /tmp/.s.PGSQL.5432

那么我们可以验证一下是否可以连接上

[postgres@rhsde ~]$ cd scripts/
[postgres@rhsde scripts]$ ls
images            launchpsql.sh          runpsql.sh          xdg
launchbrowser.sh  launchstackbuilder.sh  runstackbuilder.sh
launchpgadmin.sh  launchsvrctl.sh        serverctl.sh
[postgres@rhsde scripts]$ ./runpsql.sh
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Password for user postgres:
psql.bin (9.0.8)
Type "help" for help.

postgres=#

如果其他机器连接该数据库服务器,我们还要修改/opt/PostgreSQL/9.0/data/pg_hba.conf文件

如果软件安装完毕,我们也可以在Linux的开始菜单看到相关的信息

其实最简单的方法如下



-------------------------------------------------------------------------------------------------------
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!
------------------------------------------------------------------------------------------------------

你可能感兴趣的:(PostgreSQL,Linux)