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.
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.
For those who looking for the very minimal Postgresql 13 installation package, it's following folders only:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.