当前位置:Gxlcms > 数据库问题 > postgreSQL在linux中安装详解

postgreSQL在linux中安装详解

时间:2021-07-01 10:21:17 帮助过:10人阅读

postgreSQL在linux中安装详解 收藏 
这里安装8.4.4版本,首先下载postgresql-8.4.4-1-linux.bin。
(http://www.postgresql.org/download/)下载linux32版本的
1.       如果该文件不在linux系统中,将其从Windows拖到linux系统中,放到任意一个目录下,最好放在/opt或者/home。推荐一个Windows文件转到linux的工具:WinSCP3

(

1、打开一个终端,su -成root用户;
2、chmod +xpostgresql-8.4.4-1-linux.bin
3、./postgresql-8.4.4-1-linux.bin //运行这个命令就可以安装软件了)

2.       [root@william ~]# /postgresql-8.4.1-1-linux-x64.bin – –mode text (我这里是放在了root路径下)
—————————————————————————
Welcome to the PostgreSQL Setup Wizard.

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

3.       Installation Directory [/opt/PostgreSQL/8.4]: (这里直接回车,表示装在/opt目录下)
—————————————————————————

Please select a directory under which to store your data.

4.       Data Directory [/opt/PostgreSQL/8.4/data]:(这里直接回车,表示data数据装在该目录下)
—————————————————————————

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

5.       Password :[ 输入密码]

6.       Retype password :[ 重复输入]

—————————————————————————
7.       Please select the port number the server should listen on.

Port [5432]:[ 默认端口,直接回车]

[616] yi_US

[617] yi_US.utf8

[618] zh_CN

[619] zh_CN.utf8

[620] zh_HK

[621] zh_HK.utf8

[622] zh_SG

[623] zh_SG.utf8

[624] zh_TW

[625] zh_TW.euctw

[626] zh_TW.utf8

[627] zu_ZA

[628] zu_ZA.iso88591

[629] zu_ZA.utf8

Please choose an option [1] :619[ 默认字符集]

8.       Install pl/pgsql in template1 database? [Y/n]: n[是否安装模板库,这里选否]

—————————————————————————-

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

9.       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.

Launch Stack Builder at exit?

10.   Stack Builder may be used to download and install additional tools, drivers and applications to complement your PostgreSQL installation. [Y/n]: y(这里是继续安装额外的工具,驱动和先关应用程序)
到这里数据库就安装成功了,然后就需要配置用户,环境变量,以及初始化数据库
11.   [root@william ~]# cp .bash_profile .bashrc /home/PostgreSQL/8.4/ (将文件拷到相应目录,这个是配置环境变量的)
[root@william ~]# chown -R postgres.postgres /home/PostgreSQL/* (将改文件的owner和group都配置为postgres)
12.   [root@william ~]# ls -ltr /home/PostgreSQL/8.4/.bash* (查看下是否已更改)
-rw-r–r– 1 postgres postgres 174 Nov 10 19:18 /home/PostgreSQL/8.4/.bash_profile

-rw-r–r– 1 postgres postgres 176 Nov 10 19:18 /home/PostgreSQL/8.4/.bashrc

初始化该数据库集群的缺省区域和字符集编码
13.   [root@william ~]#su – postgres(转到postgres用户下)
14.   [postgres@william ~]$/opt/PostgreSQL/8.4/bin/initdb –D /opt/PostgreSQL/8.4/data/(初始化数据库集群的缺省区域和字符集编码)
The files belonging to this database system will be owned by user "postgres".

This user must also own the server process.

The database cluster will be initialized with locale en_US.

The default database encoding has accordingly been set to LATIN1.

The default text search configuration will be set to "english".

fixing permissions on existing directory /home/PostgreSQL/8.4/data … ok

creating subdirectories … ok

selecting default max_connections … 100

selecting default shared_buffers … 32MB

creating configuration files … ok

creating template1 database in /home/PostgreSQL/8.4/data/base/1 … o

initializing pg_authid … ok

initializing dependencies … ok

creating system views … ok

loading system objects’ descriptions … ok

creating conversions … ok

creating dictionaries … ok

setting privileges on built-in objects … ok

creating information schema … ok

vacuuming database template1 … ok

copying template1 to template0 … ok

copying template1 to postgres … ok

WARNING: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the -A option the

next time you run initdb.

Success. You can now start the database server using:

postgres -D /home/PostgreSQL/8.4/data

or

pg_ctl -D /home/PostgreSQL/8.4/data -l logfile start

恭喜你,现在就把所有的都装完了!
 

常用命令:
Createdb 
 创建数据库 
 
Createuser 
 创建数据库用户 
 
Dropdb 
 删除数据库 
 
Dropuser 
 删除数据库用户 
 
Psql 
 交互式PostgreSQL前端工具,可以用它来操作数据库 
 
Initdb 
 初始化postgreSQL数据库 
 

例如:
psql  \q                               à 退出psql命令符界面
psql  \c  dbname     à 连接数据库
pg_ctl  -D /opt/PostgreSQL/8.4/data/ status         à 查看当前服务状态
pg_ctl  -D /opt/PostgreSQL/8.4/data/ start  à 启动服务
pg_ctl  -D /opt/PostgreSQL/8.4/data/ stop   à 停止服务
 

 

远程登录设置:
●打开opt/PostgreSQL/8.4/data/pg_hba.conf,像下面一样添加一行代码:(红色为添加的)
# IPv4 local connections:

host    all         all         0.0.0.0/0             md5

host    all         all         127.0.0.1/32    md5

这行代码表示所有IP地址的所有用户可以通过md5加密的方式远程登录。
●打开opt/PostgreSQL/8.4/data/postgresql.conf

按照下面的写:
listen_addresses = ‘*‘

port = 5432

max_connections = 100

这里表示监听来自所有IP的响应。


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/william_zheng2010/archive/2010/07/12/5728333.aspx

postgreSQL在linux中安装详解

标签:

人气教程排行