fedora15安装使用postgresql
注:安装完pgsql后,一定要安装推荐的插件,否者初始化数据库是不会成功。
这个插件就是PostGIS 1.5
一.postgresql安装合适用
1.二进制文件安装PostgreSQL8.4
1.1二进制文件下载
1)下载地址:http://www.postgresql.org/download/
2)PostgreSQL是开源数据库,可以通过官方地址下载,选择Binary packages –>Linux –> Download for 64bit Linux选项
1.2安装步骤
1)创建相应的目录文件,存放安装文件 postgresql-8.4.0-1-linux.bin
2)通过ROOT权限用户运行安装文件,最好是ROOT用户
3)指定postgresql-8.4的安装目录,例如:/app/postgres/8.4
4)指定postgresql-8.4的DATA目录,例如:/app/postgres/8.4/data
5)指定超级用户postgres的登录密码
6)指定postgresql运行端口,默认port:5432
7)指定postgresql 的locale,通常为:C
8)进入安装过程
9)配置环境变量
10)配置远程连接:
11)启动数据库PostgreSQL
2.源文件安装PostgreSQL8.4
2.1源文件下载
1)下载地址:http://www.postgresql.org/download/
2)PostgreSQL是开源数据库,可以通过官方地址下载,选择Source code –>Source code –>v8.4 –>PostgreSQL-8.4.3.tar.gz,选择镜像下载
2.2安装步骤
1)root权限用户或root用户下解压下载文件
2)进行配置,指定PostgreSQL的安装目录
3)进行编译
4)进入安装
5)创建用户组和用户,目录
6)配置环境变量
7)配置数据库监听地址和端口
8)配置远程连接
9)初始化数据库目录:
10)启动数据库PostgreSQL
1.安装
yum install postgresql-server postgresql
安装完成后还有一个必须的步骤:初始化数据目录。由于postgresql是以postgres用户运行的,目录的属主必须指定为postgres。默认的数据目录是/var/lib/pgsql/data,如果不是则需要用-D参数指定。
<!–没有测试–>
首先需要切换为postgres用户才能运行initdb命令,另外要注意当前系统的locale,windows下ssh登录的zh_CN.GB18030就安装不了,把语言设置为en_US.UTF8就行了。
su postgres
initdb -D /var/lib/pgsql/data
如果指定的不是默认数据目录,需要更改/etc/init.d/postgresql启动脚本,把PGDATA,PGLOG目录指定新设置的目录。如果启动有问题,查看数据目录下的pgstartup.log日志文件
chkconfig postgresql on
service postgresql start
配置文件是数据目录下的postgresql.conf, 默认监听5432端口,所有IP地址。
listen_addresses=’192.168.1.11′ 改为只监听内网IP
netstat -nltp 看看有没有5432端口在监听
pgsql -U postgres 以postgres用户身份连接postgresql
<!–没有测试over–>
-
1,如果你的Postgresql已经运行了,跳到第5步. -
2,以root身份,在命令行中,输入service postgresql initdb.(根据路径的设置情况,你可能需要在命令行中使用/sbin/service).完成以后,你应该得到一个一切正常的反馈. -
3,仍以root身份,在命令行中,输入service postgresql start.等待,直到命令执行完成. -
4,为了让postgresql开机就启动, 以root身份,在命令行中,输入chkconfig –level 345 postgresql on.也有图形界面的方式,用于启动/停止服务,但是我喜欢使用命令行.
3.从当前用户切换到postgres用户
在postgres用户下输入以下指令:
例如创建名为ru的用户:
createuser -r -d -s ru
【可以通过createuser –help命令得到帮助信息】
(
Options:
Connection options:
If one of -d, -D, -r, -R, -s, -S, and ROLENAME is not specified, you will
be prompted interactively.
)
5.创建数据库
Usage:
Options:
Connection options:
By default, a database with the same name as the current user is created.
6.删除数据库
Options:
Connection options:
7.连接数据库
例如我的数据库是123
psql
Usage:
General options:
Input and output options:
Output format options:
Connection options:
For more information, type “\?” (for internal commands) or “\help” (for SQL
commands) from within psql, or consult the psql section in the PostgreSQL
documentation.
mydb=#
注:最后一行 mydb=#,这个提示符意味着您是数据库超级用户
二.Postgresql图形化管理工具pgAdmin3