Postgre安装问题(转)

数据库(DB)   2009-05-20 16:29   阅读69   评论0  
字号:    

Package: One click installer of PostgreSQL 8.3Env: Windows XP SP2 (Traditional Chinese)

What's wrong:It says error reading c:\ProgramFiles\PostgreSQL\8.3\data\postgresql.conf during installation. Thatdata directory is empty.

Obviously, you can't start the serverlater.Fix:This error is caused by the failure of initdb in creating a DB. Itfails probably due to the locale.

To fix the problem:runas /user:postgres cmd

c:

cd "\Program Files\PostgreSQL\8.3\bin"

initdb -D "c:\Program Files\PostgreSQL\8.3\data" -E

UTF8--locale=EnglishIt is very important that you specify the encoding and the locale.Otherwise it will fail and report that the locale is invalid.--Kent TongSME accounting software package for just MOP30.See http://www.cpttm.org.mo/index_c.php?pg=cpttm/department/is/ispu/accsys/index.htm for more.

 

 

刚才去官方网站上下载了一份最新测试版的源代码,准备安装到我的FreeBSD上面。

下载好了源代码包,按照官方文档的步骤解压缩:

# gunzip postgresql-8.3beta2.tar.gz

# tar xf postgresql-8.3beta2.tar

然后进入解压后生成的目录:

# cd postgresql-8.3beta2

剩下的过程就很简单了:

首先进行安装前的配置,使用--prefix参数设定安装后的目录:

# ./configure --prefix=/usr/local/pgsql-8.3

接下来就是编译源代码了,由于编译 PostgreSQL 需要使用 GNU Make,所以编译之前要确保系统中安装了gmake。其实 FreeBSD 自带的 BSD Make 挺好用的,不知道遵循 BSD 协议的 PostgreSQL 为啥要使用 GNU 的 Make 工具。

# gmake

...

  All of PostgreSQL successfully made. Ready to install.

大概过了十分钟左右,编译完成。最后就可以开始安装了。不过在安装之前最好先建立 PostgreSQL 的相关用户:

#groupadd postgresql

建立用户组postgresql

#adduser –g postgresql postgres

建立数据库用户postgres

然后建立相关目录

#mkdir –p /usr/local/pgsql-8.3/data

如果没有指定 -p 标志,则每个新创建的目录的父目录必须已经存在。

#chown –R postgres /usr/local/pgsql-8.3/data

让用户postgres拥有数据库目录控制权限

这一切都做好后,就可以开始安装了:

# gmake install

  ...

  PostgreSQL installation complete.

现在就可以开始使用了,使用之前先要初始化数据库目录,可能是考虑到安全性,所以这些步骤不能使用root用户执行

# su - postgres

$ cd /usr/local/pgsql-8.3/bin

$ ./initdb --locale=C -E UNICODE -D ../data/

设置locale为C,并且编码为UNICODE,使数据库支持中文。

启动数据库

$ ./pg_ctl -D ../data/ start

停止数据库

$ ./pg_ctl -D ../data/ stop

很好,一切顺利,可以开始体验这个自由强大的开源数据库了。

如果要在网络上另外一台Windows电脑上使用pgAdminIII来管理使用这台 Postgresql 服务器,那么还需要进行一些修改,这些修改主要包括两方面的修改,一是修改Postgresql的两个配置文件,二是修改数据库的一些用户权限:

修改/usr/local/pgsql-8.3/data/postgresql.conf文件

把#listen_addresses = 'localhost'的#去掉,将localhost改成*或数据库服务器的IP地址。

将#port = 5432 前面的#去掉。

将#superuser_reserved_connections = 3 前面的#去掉。

#unix_socket_permissions = 0777改为

unix_socket_permissions = 0700

#authentication_timeout = 60改为

authentication_timeout = 60

#password_encryption = on改为

password_encryption = on

#db_user_namespace = off改为

db_user_namespace = off

   

另外还需要修改/usr/local/pgsql-8.3/data/pg_hba.conf文件,增加一行。

host all all 192.168.0.0/24 password

这句的意思是:同网络中192.168.0.*的机器可以以密码的形式使用所有的数据库。更具体的参数意义直接看该配置文件中的注释就可以了。

例如trust表示192.168.0.0整个网段都允许连接。

如果是远程使用用户名和密码的方式访问数据库,则需要建立相应的数据库用户:

在psql中使用

# CREATE USER admin PASSWORD '12345';

创建一个用户 admin 并设置密码为 12345

修改以后重新启动数据库服务,就可以使用pgAdmin III连接数据库了。

[[i] 本帖最后由 arust 于 2007-11-1 19:35 编辑 [/i]]

评论(?)
阅读(?)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
网易公司版权所有 ©1997-2009