3

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.

user3705832
  • 47
  • 1
  • 6
  • I try to install Postgres by using NSIS. Because I've an application which used Postgres and is important to install Postgre with my application during the installation. Otherwise my application doesn't work – user3705832 Jul 08 '14 at 09:10
  • I want just write a little NSIS script (.nsi) to install PostgreSQL. I've edit my topic with my different research about this installation. – user3705832 Jul 08 '14 at 09:20
  • 2
    Postgres does not need its own account any more. And it's probably better to use `pg_ctl -register` to create the service. –  Jul 08 '14 at 09:22
  • Ok, I will see this. But why I've a problem during the creation of the account ? – user3705832 Jul 08 '14 at 09:26
  • No idea, but as you don't need it, just leave it out (you also might want to rephrase the question to "CreateAccountEx using the NSIS installer not working" or something similar. This is not directly related to Postgres. –  Jul 08 '14 at 09:28
  • Ok. So I replace `nsExec::ExecToLog '"$INSTDIR\pgsql\bin\initdb.exe" --username=postgres --locale=C --encoding=UTF8 -D "$INSTDIR\pgsql\data"'` by ` nsExec::ExecToLog '"$INSTDIR\pgsql\bin\pg_ctl.exe register -U postgres -P ****** -D c:/project-open/pgsql/data"'` something like this ? – user3705832 Jul 08 '14 at 09:40
  • A quick request: **Please** don't use the default PostgreSQL port `5432`. Use a different port, so it won't conflict with a standard install of PostgreSQL. – Craig Ringer Jul 08 '14 at 14:07

2 Answers2

9

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.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • 3
    I wouldn't recommend putting application data into `%PROGRAMFILES%` (that is something that really bothers me about the regular Postgres installer as well). That directory is only writable for Administrators and should not be used to store application data. –  Jul 08 '14 at 14:13
  • 1
    @a_horse_with_no_name Good point - and Windows has ProgramData now. I'll look up the env var... – Craig Ringer Jul 08 '14 at 14:14
  • 1
    It's `%ProgramData%`. `%ALLUSERSPROFILE%` might also work. Anything is better than `%PROGRAMFILES%` –  Jul 08 '14 at 14:15
  • 1
    @a_horse_with_no_name Yeah, I argued with the EDB installer guys about that a while ago. Got nowhere with that - though I *did* get them to switch to using `NETWORKSERVICE` so we don't have to explain endlessly that there's the `postgres` db user account password and unrelated `postres` service user account password. Phew. Now that nobody cares about XP anymore I should try again on the datadir location, because I agree that the location is awful. – Craig Ringer Jul 08 '14 at 14:17
  • 3
    I stopped using the EDB installer for Windows. I just download the binaries, unzip them and run `initdb` and `pg_ctl -register` manually. –  Jul 08 '14 at 14:18
  • 1
    @a_horse_with_no_name Please poke the EDB folks about installer issues. They're reasonable guys. Though I'm hoping we can return to a "community" installer that's open source and MSI based (on Windows) or .mpkg based (on Mac). With no installer for Linux, because anyone sane uses apt.postgresql.org or yum.postgresql.org anyway. We'll see. – Craig Ringer Jul 08 '14 at 14:20
  • thanks Craig , but I wanted to know is there any postgres installer lite version that comes without pgadmin , in case any one wants to use a silent install by using the installer not binaries.? – Dragon Jan 03 '21 at 18:24
  • @Dragon EnterpriseDB publishes a .zip bundle that you can use in any manner you wish. Otherwise you're stuck with the installer as shipped, and any configuration options it exposes. – Craig Ringer Jan 12 '21 at 09:21
  • @a_horse_with_no_name, do you know if I need only bin folder in order the server will work properly? Could you please advise which other folders are mandatory? Thanks. – noszone Apr 14 '21 at 04:46
  • 1
    @noszone You can omit the .pdb files for Windows, they're debug info. You can omit the documentation if you don't need it. You can remove extensions you don't use. Keep everything else. – Craig Ringer Apr 15 '21 at 13:28
0

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.

noszone
  • 190
  • 1
  • 14