一、软件需求

  1. Windows 7 旗舰版 sp1 X64

  2. ActivePerl-5.22.3.2204-MSWin32-x64-401627.exe

  3. diffutils-2.8.7-1.exe, 编译之后回归测试使用,需要手工添加bin路径到PATH

  4. visual studio ultimate 2013,VS2013_RTM_ULT_CHS.iso

  5. visual assist,代码格式化工具

  6. postgresql-9.6.2.tar.gz,pg源码

二、安装IDE工具

1.安装Perl

  下载ActivePerl-5.22.3.2204-MSWin32-x64-401627.exe,双击安装

   单击"next",选择"接受协议",

   单击"next",安装类型"Type",

   安装选项"Add Perl to the PATH environment variable","create Perl file extension association"

   单击"next",单击"install",单击"finish"

   添加 bin目录"C:\Perl64\bin",配置到系统环境变量PATH.

2.安装Windows 平台 diff工具,回归测试使用

    下载diffutils-2.8.7-1.exe安装包,双击安装

    单击"next",选择"接受协议",默认配置,单击"next",...,单击"install",单击"finish"

    把软件安装的bin目录"C:\Program Files (x86)\GnuWin32\bin",配置到系统环境变量PATH中.


 3.安装visual studio ultimate 2013

    下载VS2013_RTM_ULT_CHS.iso,并解压到VS2013_RTM_ULT_CHS目录,解压完成进入这个目录

    双击"vs_ultimate.exe"进行安装,提示IE 8 不兼容建议IE 10 ,单击"继续",

    选择"同意许可",单击"下一步"

    选择安装功能,只选择"用于C++的Microsoft基础类",单击"安装"

    安装成功后,单击"启动",程序界面加载完成,帮助->注册产品,输入产品序列号

4.安装visual assist

  双击"VA_X_Setup2001.exe",只选择"Microsoft visual studio 2013 RC",单击"install"

  单击"确定",安装成功

  5.获取postgresql源码

   解压postgresql-9.6.2.tar.gz到F 盘根目录

  6. 编译安装数据库

开始->所有程序->visual studio 2013->visual studio tools

  目录中双击"VS2013 x64 本机工具命令提示",打开visual studio 2013命令行窗口

   转到"F:\postgresql-9.6.2\src\tools\msvc"目录,

   1) 编译数据库

   执行perl build.pl DEBUG(DEBUG,代表调试模式,如果不加表示非调试模式)

    2) 回归测试,

 perl vcregress.pl check

   .............

test event_trigger            ... ok

test stats                    ... ok

============== shutting down postmaster               ==============

============== removing temporary instance            ==============


=======================

 All 167 tests passed.

=======================


  3) 安装数据库

F:\postgresql-9.6.2\src\tools\msvc>perl install.pl f:\pg962

Installing version 9.6 for debug in f:\pg962

Copying build output files......................................................

..........................................................................

Copying config files......

Copying Import libraries...

Copying contrib data files......................................................

................................................................................

...........................................................................

Copying Public headers......

Copying Libpq headers..

Copying Libpq internal headers..

Copying Internal headers...

Copying Server headers....

Copying Grammar header.

......................

Copying PL/pgSQL header.

复制了 63 个文件

复制了 1 个文件

复制了 78 个文件

复制了 33 个文件

复制了 9 个文件

复制了 1 个文件

复制了 48 个文件

复制了 6 个文件

复制了 2 个文件

复制了 7 个文件

复制了 13 个文件

复制了 1 个文件

复制了 19 个文件

复制了 25 个文件

复制了 21 个文件

复制了 41 个文件

复制了 2 个文件

复制了 10 个文件

复制了 5 个文件

复制了 14 个文件

复制了 7 个文件

复制了 34 个文件

复制了 50 个文件

复制了 6 个文件

复制了 7 个文件

复制了 77 个文件

Copying ECPG headers...............

Copying ECPG informix headers...

Copying timezone names..........

Copying timezone sets...

Copying BKI files...

Copying SQL files..

Copying Information schema data.

Generating conversion proc script...

Generating timezone files...

Generating tsearch script..................

Copying Stopword files..............

Copying Dictionaries sample files.........

Copying PL Extension files...

Installation complete.

F:\postgresql-9.6.2\src\tools\msvc>


4) 初始化数据库

F:\postgresql-9.6.2\src\tools\msvc>cd /d f:\pg962\bin

f:\pg962\bin>initdb.exe -D ../data

The files belonging to this database system will be owned by user "Administrator

".

This user must also own the server process.


The database cluster will be initialized with locale "Chinese (Simplified)_Peopl

e's Republic of China.936".

Encoding "GBK" implied by locale is not allowed as a server-side encoding.

The default database encoding will be set to "UTF8" instead.

initdb: could not find suitable text search configuration for locale "Chinese (S

implified)_People's Republic of China.936"

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


Data page checksums are disabled.


creating directory ../data ... ok

creating subdirectories ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 128MB

selecting dynamic shared memory implementation ... windows

creating configuration files ... ok

running bootstrap script ... ok

performing post-bootstrap initialization ... ok

syncing data to disk ... ok


WARNING: enabling "trust" authentication for local connections

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

--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:


    "pg_ctl" -D "../data" -l logfile start

f:\pg962\bin>


5) 启动数据库


f:\pg962\bin>pg_ctl.exe -D "../data" -l logfile start

server starting


pg数据库已经编译安装并运行起来了,可以正常使用.

执行select version();查看下版本


f:\pg962\bin>psql postgres

psql (9.6.2)

Type "help" for help.

postgres=# \du

                                     List of roles

   Role name   |                         Attributes                         | Me

mber of

---------------+------------------------------------------------------------+---

--------

 Administrator | Superuser, Create role, Create DB, Replication, Bypass RLS | {}


postgres=# select version();

                           version

-------------------------------------------------------------

 PostgreSQL 9.6.2, compiled by Visual C++ build 1800, 64-bit

(1 row)

postgres=#



问题解答:


装上后再跑执行 perl build.pl报如下错误: Unable to determine Visual Studio version: The nmake version could not be determined. at src/tools/msvc/Mkvcbuild.pm line 86.  这是perl脚本中不能正常识别vs版本造成,该问题历史悠久,不知道pg为什么不修复,要修正很简单,打开msvc目录中 VSObjectFactory.pm文件,把该文件最下面的 DetermineVisualStudioVersion 函数中  if ($output =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/m) 这行改成if ($output =~ /(\d+)\.(\d+)\.\d+(\.\d+).*$/m)  ,实际就是将 ? 改成.* 即可。