Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Windows X64中使用inno安装程序和postgreSQL创建安装程序_Postgresql_Inno Setup - Fatal编程技术网

在Windows X64中使用inno安装程序和postgreSQL创建安装程序

在Windows X64中使用inno安装程序和postgreSQL创建安装程序,postgresql,inno-setup,Postgresql,Inno Setup,我已经为我的应用程序创建了一个安装程序,它也安装了postgreSQL 第一个问题: 配置数据库的最佳方式是什么?我的意思是,使用postgres默认用户帐户是否更好?或者我应该创建一个新用户。另外,使用默认公共模式还是创建新模式更好?正如大家所看到的,我正在寻找使用数据库的最佳实践。另外,对于任何其他应用程序中可能已安装的postgreSQL版本,我需要采取何种措施 第二个问题: 如何使用安装程序创建用户? 我正在尝试创建一个不同于默认用户的新用户,但如何为该用户设置密码?我希望这样做时不在命

我已经为我的应用程序创建了一个安装程序,它也安装了postgreSQL

第一个问题:

配置数据库的最佳方式是什么?我的意思是,使用postgres默认用户帐户是否更好?或者我应该创建一个新用户。另外,使用默认公共模式还是创建新模式更好?正如大家所看到的,我正在寻找使用数据库的最佳实践。另外,对于任何其他应用程序中可能已安装的postgreSQL版本,我需要采取何种措施

第二个问题:

如何使用安装程序创建用户? 我正在尝试创建一个不同于默认用户的新用户,但如何为该用户设置密码?我希望这样做时不在命令shell中提示用户


如果有帮助的话,我很乐意发布我的任何代码

让我们来看一下你在问题中提出的几点

配置数据库的最佳方式是什么?我的意思是,使用postgres默认用户帐户是否更好

这一点都不重要,只要您为用户定义了一个strong密码,用户就可以安装它了

使用默认公共模式更好还是创建新模式更好

这取决于你的软件。如果您想在使用数据库时对所有内容进行良好的定义和组织,请为您的系统创建一个模式。如果您的系统将是唯一一个使用PostgreSQL的系统,为什么要使用botter?从DBA论坛上阅读此问题的答案

另外,对于任何其他应用程序的可能已安装版本的postgreSQL,我应该采取什么样的措施

这是个诀窍,也是你遇到的第一个问题。我发现,如果您之前已经安装了PostgreSQL数据库,那么您就无法安装它。即使卸载它也不行(在这种情况下,您必须从PostgreSQL的windows注册表中删除所有关联的注册表)

我的建议是,您在安装程序上显示一条消息,即您的系统需要在目标计算机上重新安装PostgreSQL,并且不能在其上安装以前安装的PostgreSQL,否则安装将失败。我知道那很糟糕,但我在这里找不到任何事可做。我做的另一件事是在安装程序消息中向用户添加一条注释,如果用户仍想在该机器上安装系统,则必须联系“支持人员”手动完成

如何使用安装程序创建用户

在这里,我将添加一些命令,以便在无人参与模式下安装PostgreSQL

我正在尝试创建一个不同于默认用户的新用户,但如何为该用户设置密码

使用不同于默认用户的用户安装PostgreSQL所需的命令为:

postgresqlInstallFile[withversion].exe --mode unattended --superaccount super_user_name --superpassword yourStrongPassowordHere 
如果您可以在安装程序中请求密码,并在上面的命令中使用一个变量,这将非常好

仅此一项就可以使用您定义的用户安装数据库。以下是有关的所有参数的文档

第二个问题是关于您系统的数据库。我能找到的最好的方法是从我需要安装的数据库中创建一个转储文件(这个数据库是空的,只有结构),将这个转储文件添加到安装程序中,这样我就可以将它导入到数据库的新安装中

这种方法的问题是,如果不输入超级帐户的密码,就无法创建数据库或将其还原到PostgreSQL。我所做的是

  • 向用户添加消息,说明他应该注意安装程序的消息和步骤,以免出错
  • 安装PostgreSql数据库后,将执行创建数据库的步骤,因此我使用以下命令:
[path\U for\U postgresq]/createdb.exe-U user\U your\U created-W-E UTF8-O user\U your\U created“nameofyour数据库”

  • 在我运行上述命令之前,我向用户显示了一条消息,他将看到一个提示屏幕,要求输入密码,因此他必须输入密码并按enter键。您不能将其添加为参数(PostgreSQL称其用于安全措施)

  • 创建数据库后,是时候导入我在安装程序中添加的转储文件了,因此我使用了:

[path\U for\U postgresq]/pg\U restore-U user\U your\U创建的-c-d name of your database dumpfileof your database.backup

在此命令之前,我再次向用户显示了一条消息,要求输入数据库还原命令的密码

在这里,我将添加为NSIS安装程序编写的代码。只是PostgreSQL的一部分。我的安装程序还有很多,你可能需要更多的东西

;--------------------------------
;Include Modern UI
!include "MUI.nsh"
;Include Process checker
!include nsProcess.nsh
;Include ZipDLL
!include zipdll.nsh
; include for some of the windows messages defines
!define ALL_USERS
!include winmessages.nsh

;--------------------------------
;General Configuration
    Name "Name of your Installer"
    OutFile "fileNameOfYourInstaller.exe"

    ShowInstDetails "show"

    InstallDir $PROFILE\FolderWhereToInstallYourSystem

    ; Request application privileges for Windows Vista
    RequestExecutionLevel admin

    ; HKLM (all users) vs HKCU (current user) defines
    !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
    !define env_hkcu 'HKCU "Environment"'

;--------------------------------
;Interface Settings
    !define MUI_ABORTWARNING

;--------------------------------
;Pages
    !insertmacro MUI_PAGE_DIRECTORY
    !insertmacro MUI_PAGE_INSTFILES

;--------------------------------
;Languages
    !insertmacro MUI_LANGUAGE "English"

Function .onInit
    SetOutPath $TEMP
    # the plugins dir is automatically deleted when the installer exits
    InitPluginsDir
    File /oname=re.bmp re.bmp  #here is an image for a splash screen of the installer

    splash::show 2000 re

    Pop $0  ; $0 has '1' if the user closed the splash screen early,
            ; '0' if everything closed normally, and '-1' if some error occurred.
FunctionEnd

Function verifyInstallationDIR
    IfFileExists $INSTDIR PathGood
        MessageBox MB_OK "The chosen directory is not valid for installation.$\r$\nPlease start again and inform a valid path."
        Quit ;if $INSTDIR wasn't created the installer will close
    PathGood:
FunctionEnd

Section
    SetOutPath $TEMP
    CreateDirectory $INSTDIR

    #Message to the user to PAY ATTENTIOM
    MessageBox MB_OK "Please carefully read all messages through installation steps!"

    Call verifyInstallationDIR
    #Files needed to the installer
    File "resources\DatabaseDumpFile.backup"
    File "resources\postgresql-9.3.9-3-windows-x64.exe"

    #Call postgresql installation in an unattended mode
    ExecWait 'postgresqlInstallFile[withversion].exe --mode unattended --superaccount super_user_name --superpassword yourStrongPassowordHere'

    Postgresql_Running_Check: 
        ; is app.exe process running? result is stored in $R0 
        ${nsProcess::FindProcess} "postgres.exe" $R0
        ${If} $R0 > 0
            MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "PostgreSQL process is not running yet. Wait 30 seconds and click Retry or Cancel to cancel installation." /SD IDCANCEL IDRETRY Postgresql_Running_Check
            Quit
        ${EndIf}

    ;Create the database
    MessageBox MB_OK "The System DataBase will be created. A console window will appear asking for a password. Please when it happens type:$\r$\n$\r$\nyourStrongPassowordHere"
    ExecWait '$PROGRAMFILES64\PostgreSQL\9.3\bin\createdb.exe -U user_you_created -W -E UTF8 -O user_you_created "NameOfYourDatabase"'

    MessageBox MB_OK "The System Installer will import the configuration data to the database. It will ask again for the password. Please when it happens type:$\r$\n$\r$\nyourStrongPassowordHere"
    ExecWait '$PROGRAMFILES64\PostgreSQL\9.3\bin\pg_restore -U user_you_created -c -d NameOfYourDatabase DatabaseDumpFile.backup'

SectionEnd

希望能有所帮助。

让我们看看你在问题中提出的一些观点

配置数据库的最佳方式是什么?我的意思是,使用postgres默认用户帐户是否更好

这一点都不重要,只要您为用户定义了一个strong密码,用户就可以安装它了

使用默认公共模式更好还是创建新模式更好

这取决于你的软件。如果您想在使用数据库时对所有内容进行良好的定义和组织,请为您的系统创建一个模式。如果您的系统将是唯一一个使用PostgreSQL的系统,为什么要使用botter?从DBA论坛上阅读此问题的答案

另外,对于任何其他应用程序的可能已安装版本的postgreSQL,我应该采取什么样的措施

这是个诀窍,也是你遇到的第一个问题。我发现,如果您之前已经安装了PostgreSQL数据库,那么您就无法安装它。即使卸载它也不行(在这种情况下,您必须从PostgreSQL的windows注册表中删除所有关联的注册表)

我的广告