Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ac9dba4

Browse files
committed
nsis patch: optimization, install.log, checks for 32 bit Windows
1 parent 7215d6c commit ac9dba4

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

build/helpers/postgres.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ rm -rf %BUILD_UDIR%/distr_%ARCH%_%PGVER%/postgresql/lib/*python3* || GOTO :ERROR
112112

113113
IF EXIST ..\..\..\doc\buildinfo.txt COPY ..\..\..\doc\buildinfo.txt %BUILD_DIR%\distr_%ARCH%_%PGVER%\postgresql\doc
114114
rem now actually copy DLLs of dependencies into our bindir
115+
116+
SET DEPENDENCIES_BIN_DIR=%DEPENDENCIES_BIN_DIR:\=/%
117+
115118
cp -va %DEPENDENCIES_BIN_DIR%/libintl/lib/*.dll %BUILD_DIR%\distr_%ARCH%_%PGVER%\postgresql\bin || GOTO :ERROR
116119
cp -va %DEPENDENCIES_BIN_DIR%/libintl/lib/*.lib %BUILD_DIR%\distr_%ARCH%_%PGVER%\postgresql\lib || GOTO :ERROR
117120
cp -va %DEPENDENCIES_BIN_DIR%/iconv/lib/*.dll %BUILD_DIR%\distr_%ARCH%_%PGVER%\postgresql\bin || GOTO :ERROR

nsis/postgresql.nsi

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
!include "WinVer.nsh"
2424
!include "Ports.nsh"
25+
!include "x64.nsh"
2526
!insertmacro VersionCompare
2627

2728
;--------------------------------
@@ -106,6 +107,8 @@ Var rButton2
106107
Var checkBoxEnvVar
107108
Var isEnvVar
108109

110+
Var LogFile
111+
Var effective_cache_size
109112
; Set 'install service' variable
110113
;Var service
111114

@@ -191,6 +194,7 @@ Section "Microsoft Visual C++ ${REDIST_YEAR} Redistributable" secMS
191194
SectionEnd
192195

193196
Section $(PostgreSQLString) sec1
197+
194198
${if} $PG_OLD_DIR != "" ; exist PG install
195199
MessageBox MB_YESNO|MB_ICONQUESTION "$(MESS_STOP_SERVER)" IDYES doitStop IDNO noyetStop
196200
noyetStop:
@@ -216,6 +220,9 @@ Section $(PostgreSQLString) sec1
216220
File "License.txt"
217221
File "3rd_party_licenses.txt"
218222

223+
FileOpen $LogFile $INSTDIR\install.log w ;Opens a Empty File an fills it
224+
225+
219226
CreateDirectory "$INSTDIR\scripts"
220227
File "/oname=$INSTDIR\scripts\pg-psql.ico" "pg-psql.ico"
221228
File "/oname=$INSTDIR\doc\pg-help.ico" "pg-help.ico"
@@ -224,9 +231,13 @@ Section $(PostgreSQLString) sec1
224231
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" $INSTDIR
225232

226233
;Create uninstaller
234+
FileWrite $LogFile "Create uninstaller$\r$\n"
235+
227236
WriteUninstaller "$INSTDIR\Uninstall.exe"
228237

229238
; write uninstall strings
239+
FileWrite $LogFile "Write to register\r$\n"
240+
230241
WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PG_DEF_BRANDING}" "InstallLocation" "$INSTDIR"
231242
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PG_DEF_BRANDING}" "DisplayName" "$StartMenuFolder"
232243
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PG_DEF_BRANDING}" "UninstallString" '"$INSTDIR\Uninstall.exe"'
@@ -240,6 +251,7 @@ Section $(PostgreSQLString) sec1
240251
IntFmt $0 "0x%08X" $0
241252
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PG_DEF_BRANDING}" "EstimatedSize" "$0"
242253

254+
FileWrite $LogFile "Create BAT files$\r$\n"
243255
ClearErrors
244256
FileOpen $0 $INSTDIR\scripts\reload.bat w
245257
IfErrors creatBatErr
@@ -309,6 +321,8 @@ Section $(PostgreSQLString) sec1
309321
SetShellVarContext all
310322
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
311323

324+
FileWrite $LogFile "Create shortcuts$\r$\n"
325+
312326
;Create shortcuts
313327
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
314328
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
@@ -320,6 +334,7 @@ Section $(PostgreSQLString) sec1
320334
${endif}
321335

322336
; set font Lucida Console for shortcut psql
337+
FileWrite $LogFile "set font Lucida Console for shortcut psql$\r$\n"
323338
ReadRegStr $0 HKCU "Console\SQL Shell (psql)" "FaceName"
324339
${if} $0 == ""
325340
WriteRegStr HKCU "Console\SQL Shell (psql)" "FaceName" "Consolas"
@@ -363,11 +378,15 @@ Section $(PostgreSQLString) sec1
363378

364379
!insertmacro MUI_STARTMENU_WRITE_END
365380
; Create data dir begin
381+
FileWrite $LogFile "Create data dir begin$\r$\n"
382+
366383
${if} $isDataDirExist == 0
367384
CreateDirectory "$DATA_DIR"
368385
;AccessControl::GrantOnFile "$DATA_DIR" "(BU)" "FullAccess" ;GenericWrite
369386
;Pop $0 ;"ok" or "error" + error details
370387

388+
FileWrite $LogFile "GRANT Access $\r$\n"
389+
371390
DetailPrint "GRANT FullAccess ON $DATA_DIR TO $loggedInUser"
372391
AccessControl::GrantOnFile "$DATA_DIR" "$loggedInUser" "FullAccess" ;GenericWrite
373392
DetailPrint "GRANT FullAccess ON $DATA_DIR TO $loggedInUserShort"
@@ -390,12 +409,22 @@ Section $(PostgreSQLString) sec1
390409
AccessControl::GrantOnFile "$DATA_DIR" "$0" "FullAccess" ;GenericWrite
391410
Pop $0 ;"ok" or "error" + error details
392411
System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("LC_MESSAGES", "C").r0'
412+
FileWrite $LogFile "Database initialization ...$\r$\n"
413+
393414
${if} "$Locale_text" == "$(DEF_LOCALE_NAME)"
415+
FileWrite $LogFile '"$INSTDIR\bin\initdb.exe" $tempVar \
416+
--encoding=$Coding_text -U "$UserName_text" \
417+
-D "$DATA_DIR" $\r$\n'
394418
; Initialise the database cluster, and set the appropriate permissions/ownership
395419
nsExec::ExecToLog /TIMEOUT=90000 '"$INSTDIR\bin\initdb.exe" $tempVar \
396420
--encoding=$Coding_text -U "$UserName_text" \
397421
-D "$DATA_DIR"'
398422
${else}
423+
FileWrite $LogFile '"$INSTDIR\bin\initdb.exe" $tempVar \
424+
--locale="$Locale_text" \
425+
--encoding=$Coding_text \
426+
-U "$UserName_text" \
427+
-D "$DATA_DIR" $\r$\n'
399428
nsExec::ExecToLog /TIMEOUT=60000 '"$INSTDIR\bin\initdb.exe" $tempVar \
400429
--locale="$Locale_text" \
401430
--encoding=$Coding_text \
@@ -408,10 +437,16 @@ Section $(PostgreSQLString) sec1
408437
${if} $0 != 0
409438
DetailPrint "initdb.exe return $0"
410439
DetailPrint "Output: $1"
440+
FileWrite $LogFile "initdb.exe return $0 $\r$\n"
441+
FileWrite $LogFile "Output: $1 $\r$\n"
442+
FileClose $LogFile ;Closes the filled file
443+
411444
MessageBox MB_OK|MB_ICONINFORMATION $(MESS_ERROR_INITDB)
445+
412446
Abort
413447
${else}
414448
DetailPrint "Database initialization OK"
449+
FileWrite $LogFile "Database initialization OK $\r$\n"
415450
${endif}
416451
;Delete the password file
417452
${if} "$Pass1_text" != ""
@@ -421,6 +456,7 @@ Section $(PostgreSQLString) sec1
421456
${EndIf}
422457
${endif}
423458
; Create data dir end
459+
FileWrite $LogFile "Create postgresql.conf $\r$\n"
424460
${if} $isDataDirExist == 0
425461
${if} $checkNoLocal_state == ${BST_CHECKED}
426462
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#listen_addresses = 'localhost'" "listen_addresses = '*'"
@@ -445,21 +481,76 @@ Section $(PostgreSQLString) sec1
445481
;#work_mem = 4MB # min 64kB
446482
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#work_mem = 4MB" "work_mem = $work_mem"
447483
${endif}
484+
${if} $effective_cache_size != ""
485+
;#work_mem = 4MB # min 64kB
486+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#effective_cache_size = 4GB" "effective_cache_size = $effective_cache_size"
487+
${endif}
488+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#temp_buffers = 8MB" "temp_buffers = 32MB"
489+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#maintenance_work_mem = 64MB" "maintenance_work_mem = 128MB"
490+
491+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#autovacuum_max_workers = 3" "autovacuum_max_workers = 6"
492+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#autovacuum_naptime = 1min" "autovacuum_naptime = 20s"
493+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#autovacuum_vacuum_cost_limit = -1" "autovacuum_vacuum_cost_limit = 400"
494+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#bgwriter_delay = 200ms" "bgwriter_delay = 20ms"
495+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#bgwriter_lru_multiplier = 2.0" "bgwriter_lru_multiplier = 4.0"
496+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#bgwriter_lru_maxpages = 100" "bgwriter_lru_maxpages = 400"
497+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#synchronous_commit = on" "synchronous_commit = off"
498+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#checkpoint_completion_target = 0.5" "checkpoint_completion_target = 0.9"
499+
500+
;!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#effective_io_concurrency = 0" "effective_io_concurrency = 2"
501+
502+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#random_page_cost = 4.0" "random_page_cost = 1.5"
503+
504+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "max_connections = 100" "max_connections = 500"
505+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#escape_string_warning = on" "escape_string_warning = off"
506+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#standard_conforming_strings = on" "standard_conforming_strings = off"
507+
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#max_locks_per_transaction = 64" "max_locks_per_transaction = 256"
508+
;!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#shared_preload_libraries = ''" "shared_preload_libraries = 'online_analyze, plantuner'"
509+
;!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "" ""
510+
511+
ClearErrors
512+
FileOpen $0 $DATA_DIR\postgresql.conf a
513+
IfErrors ErrFileCfg1
514+
FileSeek $0 0 END
515+
FileWrite $0 "#shared_preload_libraries = 'online_analyze, plantuner'$\r$\n"
516+
FileWrite $0 "#online_analyze.table_type = 'temporary'$\r$\n"
517+
FileWrite $0 "#online_analyze.verbose = 'off'$\r$\n"
518+
FileWrite $0 "#online_analyze.local_tracking = 'on'$\r$\n"
519+
FileWrite $0 "#plantuner.fix_empty_table = 'on' $\r$\n"
520+
FileWrite $0 "#online_analyze.enable = off$\r$\n"
521+
FileClose $0
522+
523+
ErrFileCfg1:
524+
/* shared_preload_libraries = 'online_analyze, plantuner'
525+
online_analyze.table_type = 'temporary'
526+
online_analyze.verbose = 'off'
527+
online_analyze.local_tracking = 'on'
528+
plantuner.fix_empty_table = 'on'
529+
online_analyze.enable = off */
448530
${endif}
449531
${EndIf}
532+
Delete "$DATA_DIR\postgresql.conf.old"
533+
450534
;# Add line to pg_hba.conf
451535
Call WriteInstallOptions
452536
DetailPrint "Service $ServiceID_text registration ..."
537+
FileWrite $LogFile "Service $ServiceID_text registration ... $\r$\n"
538+
FileWrite $LogFile '"$INSTDIR\bin\pg_ctl.exe" register -N "$ServiceID_text" -U "$ServiceAccount_text" -D "$DATA_DIR" -w $\r$\n'
539+
453540
nsExec::ExecToStack /TIMEOUT=60000 '"$INSTDIR\bin\pg_ctl.exe" register -N "$ServiceID_text" -U "$ServiceAccount_text" -D "$DATA_DIR" -w'
454541
Pop $0 # return value/error/timeout
455542
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
456543

457544
${if} $0 != 0
458545
DetailPrint "pg_ctl.exe register return $0"
459546
DetailPrint "Output: $1"
547+
FileWrite $LogFile "pg_ctl.exe register return $0 $\r$\n"
548+
FileWrite $LogFile "Output: $1 $\r$\n"
549+
460550
Sleep 5000
461551
${else}
462552
DetailPrint "Service registration OK"
553+
FileWrite $LogFile "Service registration OK $\r$\n"
463554
${endif}
464555

465556
;Write the DisplayName manually
@@ -517,6 +608,9 @@ Section $(PostgreSQLString) sec1
517608
${endif}
518609

519610
DetailPrint "Start server service..."
611+
FileWrite $LogFile "Start server service... $\r$\n"
612+
FileWrite $LogFile 'sc start "$ServiceID_text" $\r$\n'
613+
520614
Sleep 1000
521615

522616
nsExec::ExecToStack /TIMEOUT=60000 'sc start "$ServiceID_text"'
@@ -527,9 +621,13 @@ Section $(PostgreSQLString) sec1
527621
${if} $0 != 0
528622
DetailPrint "Start service return $0"
529623
DetailPrint "Output: $1"
624+
FileWrite $LogFile "Start service return $0 $\r$\n"
625+
FileWrite $LogFile "Output: $1 $\r$\n"
530626
Sleep 5000
531627
${else}
532628
DetailPrint "Start service OK"
629+
FileWrite $LogFile "Start service OK $\r$\n"
630+
533631
${endif}
534632

535633
${if} $isDataDirExist == 0
@@ -540,17 +638,23 @@ Section $(PostgreSQLString) sec1
540638
${endif}
541639

542640
DetailPrint "Create adminpack ..."
641+
FileWrite $LogFile "Create adminpack ... $\r$\n"
642+
FileWrite $LogFile '"$INSTDIR\bin\psql.exe" -p $TextPort_text -U "$UserName_text" -c "CREATE EXTENSION adminpack;" postgres $\r$\n'
543643
Sleep 5000
544644
nsExec::ExecToStack /TIMEOUT=60000 '"$INSTDIR\bin\psql.exe" -p $TextPort_text -U "$UserName_text" -c "CREATE EXTENSION adminpack;" postgres'
545645
pop $0
546646
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
547647
${if} $0 != 0
548648
DetailPrint "Create adminpack return $0"
549649
DetailPrint "Output: $1"
650+
FileWrite $LogFile "Create adminpack return $0 $\r$\n"
651+
FileWrite $LogFile "Output: $1 $\r$\n"
652+
550653
;MessageBox MB_OK "Create adminpack error: $1"
551654
MessageBox MB_OK|MB_ICONSTOP "$(MESS_ERROR_SERVER)"
552655
${else}
553656
DetailPrint "Create adminpack OK"
657+
FileWrite $LogFile "Create adminpack OK $\r$\n"
554658
${endif}
555659
${if} "$Pass1_text" != ""
556660
StrCpy $R0 ""
@@ -565,6 +669,8 @@ Section $(PostgreSQLString) sec1
565669
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "PGLOCALEDIR" "$INSTDIR\share\locale\"
566670
AddToPath::AddToPath "$INSTDIR\bin"
567671
${endif}
672+
FileClose $LogFile ;Closes the filled file
673+
568674
SectionEnd
569675

570676
;Uninstaller Section
@@ -587,6 +693,8 @@ Section "Uninstall"
587693
Delete "$INSTDIR\Uninstall.exe"
588694
Delete "$INSTDIR\license.txt"
589695
Delete "$INSTDIR\3rd_party_licenses.txt"
696+
Delete "$INSTDIR\install.log"
697+
590698

591699
RMDir /r "$INSTDIR\bin"
592700
RMDir /r "$INSTDIR\doc"
@@ -1576,7 +1684,19 @@ Function makeOptimization
15761684
;768MB = 98304 = 805306368
15771685
;512MB = 65536 = 536870912
15781686
;256MB = 32768 = 268435456
1687+
${if} $AllMem > 16000 ;>16gb
1688+
StrCpy $work_mem "128MB"
1689+
StrCpy $shared_buffers "1GB"
1690+
StrCpy $effective_cache_size "16GB"
1691+
return
1692+
${endif}
15791693

1694+
${if} $AllMem > 8090 ;>8gb
1695+
StrCpy $work_mem "128MB"
1696+
StrCpy $shared_buffers "1GB"
1697+
StrCpy $effective_cache_size "8GB"
1698+
return
1699+
${endif}
15801700
${if} $AllMem > 4090 ;>4gb
15811701
StrCpy $work_mem "128MB"
15821702
StrCpy $shared_buffers "512MB"
@@ -1635,6 +1755,7 @@ FunctionEnd
16351755

16361756
Function nsDialogsOptimizationPageLeave
16371757
${NSD_GetState} $rButton2 $0
1758+
16381759
${if} $0 == ${BST_CHECKED}
16391760
StrCpy $needOptimiztion "1"
16401761
${else}
@@ -1657,6 +1778,13 @@ FunctionEnd
16571778
Function .onInit
16581779
Call CheckWindowsVersion
16591780
Call SetDefaultTcpPort
1781+
1782+
!ifdef PG_64bit
1783+
${IfNot} ${RunningX64}
1784+
MessageBox MB_OK|MB_ICONSTOP "This version can be installed only on 64-bit Windows!"
1785+
Abort
1786+
${EndIf}
1787+
!endif
16601788

16611789
!insertmacro MUI_LANGDLL_DISPLAY ;select language
16621790
StrCpy $PG_OLD_DIR ""

0 commit comments

Comments
 (0)