22
22
23
23
!include " WinVer.nsh"
24
24
!include " Ports.nsh"
25
+ !include " x64.nsh"
25
26
!insertmacro VersionCompare
26
27
27
28
; --------------------------------
@@ -106,6 +107,8 @@ Var rButton2
106
107
Var checkBoxEnvVar
107
108
Var isEnvVar
108
109
110
+ Var LogFile
111
+ Var effective_cache_size
109
112
; Set 'install service' variable
110
113
; Var service
111
114
@@ -191,6 +194,7 @@ Section "Microsoft Visual C++ ${REDIST_YEAR} Redistributable" secMS
191
194
SectionEnd
192
195
193
196
Section $(PostgreSQLString) sec1
197
+
194
198
${if} $PG_OLD_DIR != " " ; exist PG install
195
199
MessageBox MB_YESNO |MB_ICONQUESTION " $(MESS_STOP_SERVER)" IDYES doitStopIDNO noyetStop
196
200
noyetStop:
@@ -216,6 +220,9 @@ Section $(PostgreSQLString) sec1
216
220
File " License.txt"
217
221
File " 3rd_party_licenses.txt"
218
222
223
+ FileOpen $LogFile $INSTDIR \install.log w; Opens a Empty File an fills it
224
+
225
+
219
226
CreateDirectory " $INSTDIR\scripts"
220
227
File " /oname=$INSTDIR\scripts\pg-psql.ico" " pg-psql.ico"
221
228
File " /oname=$INSTDIR\doc\pg-help.ico" " pg-help.ico"
@@ -224,9 +231,13 @@ Section $(PostgreSQLString) sec1
224
231
WriteRegStr HKLM " ${PRODUCT_DIR_REGKEY}" " " $INSTDIR
225
232
226
233
; Create uninstaller
234
+ FileWrite $LogFile " Create uninstaller$\r$\n "
235
+
227
236
WriteUninstaller " $INSTDIR\Uninstall.exe"
228
237
229
238
; write uninstall strings
239
+ FileWrite $LogFile " Write to register\r$\n "
240
+
230
241
WriteRegExpandStr HKLM " Software\Microsoft\Windows\CurrentVersion\Uninstall\${PG_DEF_BRANDING}" " InstallLocation" " $INSTDIR"
231
242
WriteRegStr HKLM " Software\Microsoft\Windows\CurrentVersion\Uninstall\${PG_DEF_BRANDING}" " DisplayName" " $StartMenuFolder"
232
243
WriteRegStr HKLM " Software\Microsoft\Windows\CurrentVersion\Uninstall\${PG_DEF_BRANDING}" " UninstallString" ' "$INSTDIR\Uninstall.exe"'
@@ -240,6 +251,7 @@ Section $(PostgreSQLString) sec1
240
251
IntFmt $0 " 0x%08X" $0
241
252
WriteRegDWORD HKLM " Software\Microsoft\Windows\CurrentVersion\Uninstall\${PG_DEF_BRANDING}" " EstimatedSize" " $0"
242
253
254
+ FileWrite $LogFile " Create BAT files$\r$\n "
243
255
ClearErrors
244
256
FileOpen $0 $INSTDIR \scripts\reload.bat w
245
257
IfErrors creatBatErr
@@ -309,6 +321,8 @@ Section $(PostgreSQLString) sec1
309
321
SetShellVarContext all
310
322
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
311
323
324
+ FileWrite $LogFile " Create shortcuts$\r$\n "
325
+
312
326
; Create shortcuts
313
327
CreateDirectory " $SMPROGRAMS\$StartMenuFolder"
314
328
CreateShortCut " $SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" " $INSTDIR\Uninstall.exe"
@@ -320,6 +334,7 @@ Section $(PostgreSQLString) sec1
320
334
${endif}
321
335
322
336
; set font Lucida Console for shortcut psql
337
+ FileWrite $LogFile " set font Lucida Console for shortcut psql$\r$\n "
323
338
ReadRegStr $0 HKCU " Console\SQL Shell (psql)" " FaceName"
324
339
${if} $0 == " "
325
340
WriteRegStr HKCU " Console\SQL Shell (psql)" " FaceName" " Consolas"
@@ -363,11 +378,15 @@ Section $(PostgreSQLString) sec1
363
378
364
379
!insertmacro MUI_STARTMENU_WRITE_END
365
380
; Create data dir begin
381
+ FileWrite $LogFile " Create data dir begin$\r$\n "
382
+
366
383
${if} $isDataDirExist == 0
367
384
CreateDirectory " $DATA_DIR"
368
385
; AccessControl::GrantOnFile "$DATA_DIR" "(BU)" "FullAccess" ;GenericWrite
369
386
; Pop $0 ;"ok" or "error" + error details
370
387
388
+ FileWrite $LogFile " GRANT Access$\r$\n "
389
+
371
390
DetailPrint " GRANT FullAccess ON $DATA_DIR TO $loggedInUser"
372
391
AccessControl::GrantOnFile " $DATA_DIR" " $loggedInUser" " FullAccess" ; GenericWrite
373
392
DetailPrint " GRANT FullAccess ON $DATA_DIR TO $loggedInUserShort"
@@ -390,12 +409,22 @@ Section $(PostgreSQLString) sec1
390
409
AccessControl::GrantOnFile " $DATA_DIR" " $0" " FullAccess" ; GenericWrite
391
410
Pop $0 ; "ok" or "error" + error details
392
411
System::Call ' Kernel32::SetEnvironmentVariable(t, t)i ("LC_MESSAGES", "C").r0'
412
+ FileWrite $LogFile " Database initialization ...$\r$\n "
413
+
393
414
${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 '
394
418
; Initialise the database cluster, and set the appropriate permissions/ownership
395
419
nsExec::ExecToLog /TIMEOUT= 90000 ' "$INSTDIR\bin\initdb.exe" $tempVar \
396
420
--encoding=$Coding_text -U "$UserName_text" \
397
421
-D "$DATA_DIR"'
398
422
${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 '
399
428
nsExec::ExecToLog /TIMEOUT= 60000 ' "$INSTDIR\bin\initdb.exe" $tempVar \
400
429
--locale="$Locale_text" \
401
430
--encoding=$Coding_text \
@@ -408,10 +437,16 @@ Section $(PostgreSQLString) sec1
408
437
${if} $0 != 0
409
438
DetailPrint " initdb.exe return $0"
410
439
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
+
411
444
MessageBox MB_OK |MB_ICONINFORMATION $(MESS_ERROR_INITDB)
445
+
412
446
Abort
413
447
${else}
414
448
DetailPrint " Database initialization OK"
449
+ FileWrite $LogFile " Database initialization OK$\r$\n "
415
450
${endif}
416
451
; Delete the password file
417
452
${if} " $Pass1_text" != " "
@@ -421,6 +456,7 @@ Section $(PostgreSQLString) sec1
421
456
${EndIf}
422
457
${endif}
423
458
; Create data dir end
459
+ FileWrite $LogFile " Create postgresql.conf$\r$\n "
424
460
${if} $isDataDirExist == 0
425
461
${if} $checkNoLocal_state == ${BST_CHECKED}
426
462
!insertmacro _ReplaceInFile" $DATA_DIR\postgresql.conf" " #listen_addresses = 'localhost'" " listen_addresses = '*'"
@@ -445,21 +481,76 @@ Section $(PostgreSQLString) sec1
445
481
; #work_mem = 4MB# min 64kB
446
482
!insertmacro _ReplaceInFile" $DATA_DIR\postgresql.conf" " #work_mem = 4MB" " work_mem = $work_mem"
447
483
${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*/
448
530
${endif}
449
531
${EndIf}
532
+ Delete " $DATA_DIR\postgresql.conf.old"
533
+
450
534
; # Add line to pg_hba.conf
451
535
Call WriteInstallOptions
452
536
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
+
453
540
nsExec::ExecToStack /TIMEOUT= 60000 ' "$INSTDIR\bin\pg_ctl.exe" register -N "$ServiceID_text" -U "$ServiceAccount_text" -D "$DATA_DIR" -w'
454
541
Pop $0 # return value/error/timeout
455
542
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
456
543
457
544
${if} $0 != 0
458
545
DetailPrint " pg_ctl.exe register return $0"
459
546
DetailPrint " Output: $1"
547
+ FileWrite $LogFile " pg_ctl.exe register return $0$\r$\n "
548
+ FileWrite $LogFile " Output: $1$\r$\n "
549
+
460
550
Sleep 5000
461
551
${else}
462
552
DetailPrint " Service registration OK"
553
+ FileWrite $LogFile " Service registration OK$\r$\n "
463
554
${endif}
464
555
465
556
; Write the DisplayName manually
@@ -517,6 +608,9 @@ Section $(PostgreSQLString) sec1
517
608
${endif}
518
609
519
610
DetailPrint " Start server service..."
611
+ FileWrite $LogFile " Start server service...$\r$\n "
612
+ FileWrite $LogFile ' sc start "$ServiceID_text"$\r$\n '
613
+
520
614
Sleep 1000
521
615
522
616
nsExec::ExecToStack /TIMEOUT= 60000 ' sc start "$ServiceID_text"'
@@ -527,9 +621,13 @@ Section $(PostgreSQLString) sec1
527
621
${if} $0 != 0
528
622
DetailPrint " Start service return $0"
529
623
DetailPrint " Output: $1"
624
+ FileWrite $LogFile " Start service return $0$\r$\n "
625
+ FileWrite $LogFile " Output: $1$\r$\n "
530
626
Sleep 5000
531
627
${else}
532
628
DetailPrint " Start service OK"
629
+ FileWrite $LogFile " Start service OK$\r$\n "
630
+
533
631
${endif}
534
632
535
633
${if} $isDataDirExist == 0
@@ -540,17 +638,23 @@ Section $(PostgreSQLString) sec1
540
638
${endif}
541
639
542
640
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 '
543
643
Sleep 5000
544
644
nsExec::ExecToStack /TIMEOUT= 60000 ' "$INSTDIR\bin\psql.exe" -p $TextPort_text -U "$UserName_text" -c "CREATE EXTENSION adminpack;" postgres'
545
645
pop$0
546
646
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
547
647
${if} $0 != 0
548
648
DetailPrint " Create adminpack return $0"
549
649
DetailPrint " Output: $1"
650
+ FileWrite $LogFile " Create adminpack return $0$\r$\n "
651
+ FileWrite $LogFile " Output: $1$\r$\n "
652
+
550
653
; MessageBox MB_OK "Create adminpack error: $1"
551
654
MessageBox MB_OK |MB_ICONSTOP " $(MESS_ERROR_SERVER)"
552
655
${else}
553
656
DetailPrint " Create adminpack OK"
657
+ FileWrite $LogFile " Create adminpack OK$\r$\n "
554
658
${endif}
555
659
${if} " $Pass1_text" != " "
556
660
StrCpy $R0 " "
@@ -565,6 +669,8 @@ Section $(PostgreSQLString) sec1
565
669
WriteRegExpandStr HKLM " SYSTEM\CurrentControlSet\Control\Session Manager\Environment" " PGLOCALEDIR" " $INSTDIR\share\locale\"
566
670
AddToPath::AddToPath " $INSTDIR\bin"
567
671
${endif}
672
+ FileClose $LogFile ; Closes the filled file
673
+
568
674
SectionEnd
569
675
570
676
; Uninstaller Section
@@ -587,6 +693,8 @@ Section "Uninstall"
587
693
Delete " $INSTDIR\Uninstall.exe"
588
694
Delete " $INSTDIR\license.txt"
589
695
Delete " $INSTDIR\3rd_party_licenses.txt"
696
+ Delete " $INSTDIR\install.log"
697
+
590
698
591
699
RMDir /r " $INSTDIR\bin"
592
700
RMDir /r " $INSTDIR\doc"
@@ -1576,7 +1684,19 @@ Function makeOptimization
1576
1684
; 768MB = 98304 = 805306368
1577
1685
; 512MB = 65536 = 536870912
1578
1686
; 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}
1579
1693
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}
1580
1700
${if} $AllMem > 4090 ; >4gb
1581
1701
StrCpy $work_mem " 128MB"
1582
1702
StrCpy $shared_buffers " 512MB"
@@ -1635,6 +1755,7 @@ FunctionEnd
1635
1755
1636
1756
Function nsDialogsOptimizationPageLeave
1637
1757
${NSD_GetState} $rButton2 $0
1758
+
1638
1759
${if} $0 == ${BST_CHECKED}
1639
1760
StrCpy $needOptimiztion " 1"
1640
1761
${else}
@@ -1657,6 +1778,13 @@ FunctionEnd
1657
1778
Function .onInit
1658
1779
Call CheckWindowsVersion
1659
1780
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
1660
1788
1661
1789
!insertmacro MUI_LANGDLL_DISPLAY; select language
1662
1790
StrCpy $PG_OLD_DIR " "