注册并运行 PostgreSQL 9.0 作为 Windows 服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14484652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:58:50  来源:igfitidea点击:

Register and run PostgreSQL 9.0 as Windows Service

postgresql

提问by thclpr

For a while i have my db running on a command window because im not figuring out how to run it as a windows service.

有一段时间我让我的数据库在命令窗口上运行,因为我不知道如何将它作为 Windows 服务运行。

Since i have the zip file version downloaded. how can i register the pg_ctl command as a windows service?

因为我下载了 zip 文件版本。如何将 pg_ctl 命令注册为 Windows 服务?

By the way, im using the following line to start the server:

顺便说一句,我使用以下行来启动服务器:

"D:/Program Files/PostgreSQL/9.0.4/bin/pg_ctl.exe" -D "D:/Program Files/PostgreSQL/9.0.4/db_data" -l logfile start

Thanks in advance.

提前致谢。

回答by a_horse_with_no_name

Use the registerparameter for the pg_ctlprogram.

使用程序的register参数pg_ctl

The data directory should not be stored in Program Files, the location of %ProgramData%is e.g. a good choice.

数据目录不应存储在 中Program Files%ProgramData%例如的位置是一个不错的选择。

pg_ctl.exe register -N PostgreSQL -U some_windows_username -P windows_password -D "%ProgramData%/db_data" ...

In newer versions of Postgres, a separate Windows account is no longer necessary, so the following is also sufficient

在较新版本的 Postgres 中,不再需要单独的 Windows 帐户,因此以下内容也足够了

pg_ctl.exe register -N PostgreSQL -D "%ProgramData%/db_data" ...

Details are in the manual: http://www.postgresql.org/docs/current/static/app-pg-ctl.html

详细信息在手册中:http: //www.postgresql.org/docs/current/static/app-pg-ctl.html

You need to make sure the directory D:/Program Files/PostgreSQL/9.0.4/db_datahas the correct privileges for the windows user you specify with the -Uflag.

您需要确保该目录D:/Program Files/PostgreSQL/9.0.4/db_data对您使用该-U标志指定的 Windows 用户具有正确的权限。

Btw: it is a bad idea to store program data in Program Files. You should move the data directory somewhere outside of Program Filesbecause Program Filesis usually highly restricted for regular users - with a very good reason.

顺便说一句:将程序数据存储在Program Files. 您应该将数据目录移动到外面的某个地方,Program Files因为Program Files对于普通用户来说通常受到严格限制 - 有一个很好的理由。

回答by Geek669

Just run 'Command Prompt' as windows administrator and run the below command:

只需以 Windows 管理员身份运行“命令提示符”并运行以下命令:

pg_ctl.exe register -N PostgreSQL -D "D:/Program Files/PostgreSQL/9.0.4/db_data"

You don't need to specify a User and Password, as previous answers have suggested.

您不需要指定用户和密码,正如之前的答案所建议的那样。