简体   繁体   English

使用 NSIS 安装 postgresql

[英]Installation of postgresql with NSIS

I would install postgresql with the NSIS installer, but I don't know how.我会用 NSIS 安装程序安装 postgresql,但我不知道如何。

Can you help me please ?你能帮我吗 ?

I've find this code我找到了这个代码

outfile "C:\project-open\installer\install_postgres.exe"
Name "Install PostgreSQL"

!include Registry.nsh
!include LogicLib.nsh
!include MultiUser.nsh
!include Sections.nsh
!include MUI2.nsh`

!define TARGET c:\project-open

Function .onInit
   StrCpy $INSTDIR "c:\project-open"
FunctionEnd

section
    UserMgr::CreateAccountEx "postgres" "*******" "PostgreSQL" "PostgreSQL Database      User" "Database user created by ]po[ installer" "UF_PASSWD_NOTREQD|UF_DONT_EXPIRE_PASSWD"
pop $R0
DetailPrint "After creating account: result=$R0"`

UserMgr::AddPrivilege "postgres" "SeBatchLogonRight"
pop $R0
DetailPrint "SeBatchLogonRight: result=$R0"

UserMgr::AddPrivilege "postgres" "SeServiceLogonRight"
pop $R0
DetailPrint "SeServiceLogonRight: result=$R0"

nsExec::ExecToLog '"$INSTDIR\pgsql\bin\initdb.exe" --username=postgres --locale=C --encoding=UTF8 -D "$INSTDIR\pgsql\data"'
pop $R0
DetailPrint "After initializing database: result=$R0"

nsExec::ExecToLog 'sc create postgresql-9.2 binpath= "c:\project-open\pgsql\bin\pg_ctl.exe runservice -N postgresql-9.2 -D c:/project-open/pgsql/data -w" DisplayName= "PostgreSQL 9.2" start= "demand" type= own obj= ".\postgres" password= "******" '
pop $R0
DetailPrint "After registering the service: result=$R0"sectionEnd`

but I have a problem with UserMgr::CreateAccountEx but I've imported all files required.但是UserMgr::CreateAccountEx有问题,但我已经导入了所有需要的文件。

All you need to do is create a data dir:您需要做的就是创建一个数据目录:

initdb -D %PROGRAMDATA%\MyApp\data

then install your PostgreSQL config file and pg_hba.conf or make any required edits to the files generated automatically by initdb at %PROGRAMDATA%\\MyApp\\data\\postgresql.conf and %PROGRAMDATA%\\MyApp\\data\\pg_hba.conf .然后安装您的 PostgreSQL 配置文件和pg_hba.conf或对%PROGRAMDATA%\\MyApp\\data\\postgresql.conf%PROGRAMDATA%\\MyApp\\data\\pg_hba.conf处的initdb自动生成的文件进行任何必要的编辑。

Then:然后:

pg_ctl register -D %PROGRAMDATA%\MyApp\data -S auto -N postgres-MyApp -U NETWORKSERVICE

net start postgres-MyApp

Please do not use the default port 5432. Run on a non-default port that won't conflict with any existing or future PostgreSQL install.不要使用默认端口 5432。在不会与任何现有或未来 PostgreSQL 安装冲突的非默认端口上运行。 Also, do not use the "standard" service names like postgresql-9.2 .另外,不要使用“标准”服务名称,例如postgresql-9.2

(NSIS may offer a command to start a service, instead of using net start . If it does, use the appropriate NSIS command). (NSIS 可能会提供启动服务的命令,而不是使用net start 。如果是,请使用适当的 NSIS 命令)。

Note that %PROGRAMDATA% is only defined for Windows Vista and higher (where it points to %SYSTEMDRIVE%\\ProgramData by default).请注意, %PROGRAMDATA%仅针对 Windows Vista 及更高版本定义(默认情况下它指向%SYSTEMDRIVE%\\ProgramData )。 You can use %ALLUSERSPROFILE% on Windows XP, but really, who cares about XP now?你可以在 Windows XP 上使用%ALLUSERSPROFILE% ,但真的,现在谁在乎 XP?


Personally, I suggest using MSI installers with WiX.就个人而言,我建议将 MSI 安装程序与 WiX 结合使用。

For those who looking for the very minimal Postgresql 13 installation package, it's following folders only:对于那些寻找非常小的 Postgresql 13 安装包的人来说,它只是以下文件夹:

bin
lib
share

It's not taking to account any special cases.它没有考虑任何特殊情况。 Each individual setup have to be tested, in my case above working fine.每个单独的设置都必须进行测试,在我上面的例子中工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM