设为首页 收藏本站
查看: 1184|回复: 0

[经验分享] PostgresQL安装与配置(win2003测试通过)

[复制链接]

尚未签到

发表于 2016-11-21 09:14:03 | 显示全部楼层 |阅读模式
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


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
$

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-303232-1-1.html 上篇帖子: PostgreSQL 错误码 下篇帖子: Oracle向PostgreSQL移植实例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表