Installation of postgresql with NSIS

你说的曾经没有我的故事 提交于 2019-11-26 18:38:54

问题


I would install postgresql with the NSIS installer, but I don't know how.

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.


回答1:


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.

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. Also, do not use the "standard" service names like 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).

Note that %PROGRAMDATA% is only defined for Windows Vista and higher (where it points to %SYSTEMDRIVE%\ProgramData by default). You can use %ALLUSERSPROFILE% on Windows XP, but really, who cares about XP now?


Personally, I suggest using MSI installers with WiX.



来源:https://stackoverflow.com/questions/24625490/installation-of-postgresql-with-nsis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!