PostgresQL安装与配置(win2003测试通过)

Cygwin + PostgreSQL
环境:
Cygwin 1.5.10-3 Cygipc 2.03-2 PostgreSQL 7.4.3-1 Windows 2003 cygwin安装目录:C:\cygwin\bin


假定您已下载并安装好cygwin,其中已包含PostgresQL,然后您还需要:

1.将cygserver 安装成NT服务并启动($是系统提示符,不需要输入
a.运行脚本:$ /usr/bin/cygserver-config
b.在win2003中设置环境变量:CYGWIN=server
c.重启win2003

2.新建用户帐号
$ net user postgres [password] /add
$ net user postgres /fullname:postgres  
$ net user postgres /comment:'PostgreSQL User Account'  
$ net user postgres /homedir:"$(cygpath -w /home/postgres)"

注意:请将以上[password]替换为你的密码

3.新建文件夹:C:\cygwin\home\postgres.

4.更新文件: /etc/passwd
$ mkpasswd -l -u postgres >> /etc/passwd
意思是:向/etc/passwd文件中加入用户postgres的信息

5.新建一个放数据的目录并设置postgres为该目录的所有者
a. $ mkdir /usr/share/postgresql/data
b. $ chown postgres /usr/share/postgresql
c. $ chown postgres /usr/share/postgresql/data


6.用户权限设置
a.打开[本地安全设置]\[用户权限分配]:$ cmd /c secpol.msc
b.选择“作为服务登录“的属性,添加用户postgres
postgres_secpol.png

7.初始化数据区域
a.注销administrator,以用户postgres进入win2003,不可以在控制台用su命令切换用户
b.$ initdb -D /var/postgresql/data

8.将postmaster(PostgreSQL的服务器)安装成NT服务并启动
$ cygrunsrv -I postmaster -p /usr/bin/postmaster  -a "-D /usr/share/postgresql/data -i"  -y cygserver  -s INT -u postgres –o
其参数含义如下:
-I postmaster:新建一个名为postmaster的服务
-p /usr/bin/postmaster:应用程序路径为/usr/bin/postmaster
-a "-D /usr/share/postgresql/data -i":postmaster 将目录 /usr/share/postgresql/data 做为数据目录,必须设置 -i(TCP/IP 连接) 和 -D 参数
-y cygserver  :指明postmaster依赖于cygserver  
-s INT :发送信号 INT when terminated is run by the user (-u) postgres
-o :在系统退出时停止服务

更详细的参数说明请用命令:cygrunsrv -h 以及 postmaster --help
Cygrunsrv 将会让你输入两次密码

9.登录postgresql数据库,template1是在数据库初始化时自动创建的测试数据库:
$ psql -U postgres template1

[参考]
安装cygwin:http://www.cnblogs.com/huqingyu/archive/2004/07/04/20976.aspx
http://discypus.jp/pc/cygwin/postgresql.shtml
有关cygserver:http://www.cygwin.com/cygwin-ug-net/using-cygserver.html
http://cygwin.com/ml/cygwin/2004-06/msg00457.html

[问题]
1.一开始,参照http://www.sitepoint.com/article/use-postgresql-php-windows做,发现开启服务ipc-daemon2 --install-as-service在win2003中是不行的,在接下来的initdb将会提示:selecting default max_connections... Signal 12
于是上网找资料:
http://www.cygwin.com/ml/cygwin/2004-06/msg00765.html说也出现类似问题,
http://www.cygwin.com/ml/cygwin/2004-06/msg00772.html提供了解决方案
解决方案:
http://cygwin.com/ml/cygwin/2004-06/msg00457.html文中提示:
    o build against cygserver instead of cygipc
    o upgrade to PostgreSQL 7.4.2
2.如果遇到提示:"psql: could not connect to server",那需要检查postmaster服务是否启动,若未启动则启动它:
$ net start postmaster



[界面信息]
1.确定cygwin下载包的版本:
$ cygcheck -c cygwin cygipc postgresql
Cygwin Package Information
Package              Version        Status
cygipc               2.03-1         OK
cygwin               1.5.10-3        OK
postgresql           7.4.3-1          OK


2.数据初始化时应当显示类似如下的信息
$ initdb -D /var/postgresql/data
The files belonging to this database system will be owned by user "username".
This user must also own the server process.
The database cluster will be initialized with locale C.
creating directory /var/postgresql/data... ok
creating directory /var/postgresql/data/base... ok
creating directory /var/postgresql/data/global... ok
creating directory /var/postgresql/data/pg_xlog... ok
creating directory /var/postgresql/data/pg_clog... ok
selecting default max_connections... 100
selecting default shared_buffers... 1000
creating configuration files... ok
creating template1 database in /var/postgresql/data/base/1... ok
initializing pg_shadow... ok
enabling unlimited row size for system tables... ok
initializing pg_depend... ok
creating system views... ok
loading pg_description... ok
creating conversions... ok
setting privileges on built-in objects... ok
creating information schema... ok
vacuuming database template1... ok
copying template1 to template0... ok
Success. You can now start the database server using:
    /usr/bin/postmaster -D /var/postgresql/data
or
    /usr/bin/pg_ctl -D /var/postgresql/data -l logfile start


3.查看postmaster服务的状态
$ cygrunsrv -Q postmaster
Service postmaster exists                   Type                : Own Process
Current State       : Stopped               停止中。
Controls Accepted   :

4.查看postmaster的日志
$ cat /var/log/postmaster.log           
LOG:  shmdt(0xd00000) failed: Invalid argument
LOG:  database system was shut down at 2003-11-29 13:28:49
LOG:  checkpoint record is at 0/A18780
LOG:  redo record is at 0/A18780; undo record is at 0/0; shutdown TRUE
LOG:  next transaction ID: 554; next OID: 17147
LOG:  database system is ready

5.进入postgresql控制台
$ psql -U postgres template1
Welcome to psql 7.4, the PostgreSQL interactive terminal.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help on internal slash commands
       \g or terminate with semicolon to execute query
       \q to quit
template1-# \q
$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值