简体   繁体   English

如何使用所有参数安装带有NSIS的postgres?

[英]How to install postgres with NSIS with all parameters?

We have a C# program which uses postgres as its database, so we want to bundle the postgres in the installer as a semi-silent install, ie the user will be notified about the mandatory installation, but the installation itself will be automatically performed without the need for user input. 我们有一个使用postgres作为其数据库的C#程序,因此我们希望将安装程序中的postgres捆绑为半静默安装,即用户将收到有关强制安装的通知,但安装本身将自动执行而不会需要用户输入。

After researching opinions on WiX, Inno Setup and NSIS we decided to use NSIS. 在研究了对WiX,Inno Setup和NSIS的意见后,我们决定使用NSIS。 As I see it the easiest way will be to include the binary .zip distibution of postgres and perform the following in the script: 我认为最简单的方法是包含postgres的二进制.zip分配并在脚本中执行以下操作:

  1. Copy the pgsql folder to the installation dir 将pgsql文件夹复制到安装目录
  2. Run initdb.exe with the appropriate arguments to create the database itself in InstallDir/pgsql/data 使用适当的参数运行initdb.exe,以在InstallDir / pgsql / data中创建数据库本身
  3. Run pg_ctl.exe to register as a service with application specific name 运行pg_ctl.exe以注册为具有应用程序特定名称的服务
  4. Use the NSIS Simple Service Plugin to start the service 使用NSIS Simple Service Plugin启动该服务
  5. Install our program 安装我们的程序

I have several questions about this scenario: 我对这个场景有几个问题:

Q1: Am I on the right track at all? Q1:我在正确的轨道上吗?

Q2: Can I pass the superuser password somehow to initdb.exe, so it doesn't ask the user to enter it trough the console? Q2:我可以以某种方式将超级用户密码传递给initdb.exe,因此它不会要求用户通过控制台输入吗?

Q3: Where and how do I change the port on which postgres will listen, so that I don't conflict with other installed instances? 问题3:在哪里以及如何更改postgres将侦听的端口,以便我不与其他已安装的实例冲突?

Q4: When uninstalling is it enough to just unregister the service with pg_ctl.exe and delete all folders? 问题4:卸载时是否只需使用pg_ctl.exe取消注册服务并删除所有文件夹即可?

PS: I feel the questions are connected to each other so I've put them all together here. PS:我觉得这些问题是相互关联的,所以我把它们放在一起。 But if needed I can separate them in different questions. 但如果需要,我可以在不同的问题中将它们分开。

This is about right. 这是对的。

Please do not use port 5432 for PostgreSQL. 不要使用端口5432对PostgreSQL。 Pick a non-default port well outside that range, like 5599 or something. 选择一个远离该范围的非默认端口,如5599或其他东西。 Change the port by modifying postgresql.conf and setting the port directive. 通过修改postgresql.conf并设置port指令来更改port You might find it useful to simply append include_dir = conf.d or similar in your main postgresql.conf then create a datadir\\conf.d\\myapp.conf with your configuration overrides. 您可能会发现在主postgresql.conf简单地附加include_dir = conf.d或类似内容然后使用您的配置覆盖创建一个datadir\\conf.d\\myapp.conf用。

To set the password for initdb without a prompt, pass the --pwfile=/path/to/file option. 要在没有提示的情况下为initdb设置密码,请传递--pwfile=/path/to/file选项。 The first line will be read as the password. 第一行将被读作密码。 See initdb . 请参见initdb

Your uninstall plan is reasonable and correct. 您的卸载计划是合理和正确的。

Think about upgrades though - don't paint yourself into a corner. 想想升级 - 不要把自己画成一个角落。 You'll want to be able to install 9.5 in parallel to 9.4 and pg_upgrade , unless you want to just use dump and restore. 您希望能够并行安装9.5到9.4和pg_upgrade ,除非您只想使用转储和恢复。

I suggest installing the PostgreSQL binaries into %PROGRAMFILES%\\MyApp\\PostgreSQL\\9.4 . 我建议将PostgreSQL二进制文件安装到%PROGRAMFILES%\\MyApp\\PostgreSQL\\9.4 You should probably put the database into %PROGRAMDATA%\\MyApp\\PostgreSQL\\9.4 instead of your app's %PROGRAMFILES% directory. 您应该将数据库放入%PROGRAMDATA%\\MyApp\\PostgreSQL\\9.4而不是应用程序的%PROGRAMFILES%目录中。 (The PostgreSQL installer should do the same; its current behaviour is a historical artifact that should be fixed). (PostgreSQL安装程序也应该这样做;它的当前行为是一个应该修复的历史工件)。

Please document that your application bundles PostgreSQL so that nobody "cleans" it up, and so we don't have yet another app spewing confused users onto pgsql-general. 请记录您的应用程序捆绑PostgreSQL,以便没有人“清理”它,因此我们没有另一个应用程序喷出混淆用户到pgsql-general。 It gets tiring explaining to angry users that "we" didn't install PostgreSQL on their system, we can't remove it, it's probably there because it was installed by something they use, and if they delete it then that'll stop working. 向愤怒的用户解释“我们”没有在他们的系统上安装PostgreSQL,我们无法删除它,它可能在那里,因为它是由他们使用的东西安装,如果他们删除它然后那将停止工作。 Similarly, it gets tiring explaining to users who just killed the PostgreSQL processes and deleted their PostgreSQL data dir that we can't get their Poker Tracker (or whatever) database back because they just deleted it... 同样地,对刚刚杀死PostgreSQL进程并删除了他们的PostgreSQL数据目录的用户来说很难解释我们无法获得他们的Poker Tracker(或其他)数据库因为他们刚刚删除它...

Make sure your app exposes functionality to do PostgreSQL dumps and restores for users. 确保您的应用程序公开了为用户执行PostgreSQL转储和还原的功能。

The user manual must clearly explain that they need to take extra backup steps to protect data in your app. 用户手册必须清楚地说明他们需要采取额外的备份步骤来保护应用中的数据。 You can't just use Windows Backup to get a reliable PostgreSQL backup because it's multiple files that must be copied together; 您不能只使用Windows备份来获得可靠的PostgreSQL备份,因为它是必须一起复制的多个文件; it'll copy each file OK, but the combined result will be unusable unless PostgreSQL was stopped before the backup. 它会复制每个文件,但除非PostgreSQL在备份之前停止,否则组合结果将无法使用。 To do a live backup you need to take special steps - pg_start_backup() , copy, pg_stop_backup() and archive the extra WAL segments, or use pg_basebackup . 要进行实时备份,您需要采取特殊步骤 - pg_start_backup() ,copy, pg_stop_backup()并存档额外的WAL段,或使用pg_basebackup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM