在 linux 系统启动时启动 postgresql 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11713580/
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-08-06 13:57:50  来源:igfitidea点击:

start postgresql server on linux system boot

linuxpostgresql

提问by othman

I want to make the postgresql server on my linux machine to start automatically at system boot. i added the following line in ~/.profile file:

我想让我的 linux 机器上的 postgresql 服务器在系统启动时自动启动。我在 ~/.profile 文件中添加了以下行:

su -c 'pg_ctl start -D /var/lib/pgsql/data ' postgres

however the postgres server doesn't start untill i lauch the console command . i'm then prompted to input password of user 'postgres' and then the server starts up correctly.

但是 postgres 服务器在我启动控制台命令之前不会启动。然后提示我输入用户“postgres”的密码,然后服务器正确启动。

i want to avoid the two extar steps of lauching the linux console and entering the password for 'postgres' user. How can i do that?

我想避免启动 linux 控制台和输入“postgres”用户的密码这两个额外的步骤。我怎样才能做到这一点?

回答by Tom Anderson

Normally, you would do this with your system's initialisation framework. On traditional unixes, that means /etc/init.dscripts, but on modern ones, including the major Linux distributions, it is often something different.

通常,您会使用系统的初始化框架来执行此操作。在传统的 Unix 上,这意味着/etc/init.d脚本,但在现代的Unix上,包括主要的 Linux 发行版,它通常是不同的。

Having said that, on modern unixes, installing PostgreSQL using the package manager will typically cause it to be launched on startup, so you shouldn't even need to do that.

话虽如此,在现代 unix 上,使用包管理器安装 PostgreSQL 通常会导致它在启动时启动,因此您甚至不需要这样做。

What distribution of Linux are you using, and how have you installed PostgreSQL?

您使用的是什么 Linux 发行版,您是如何安装 PostgreSQL 的?

回答by Edmon

Here is an excerpt from the 8.0 manual that shows you how to do this with 8.* and for different distributions:

以下是 8.0 手册的摘录,向您展示了如何使用 8.* 以及针对不同的发行版执行此操作:

http://www.postgresql.org/docs/8.0/static/postmaster-start.html

http://www.postgresql.org/docs/8.0/static/postmaster-start.html

and here is for the most recent released version: http://www.postgresql.org/docs/9.1/static/server-start.html

这是最新发布的版本:http: //www.postgresql.org/docs/9.1/static/server-start.html

On Linux systems either add
/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data
to /etc/rc.d/rc.localor /etc/rc.local
or look at the file
contrib/start-scripts/linuxin the PostgreSQL source distribution.

在Linux系统或者添加
/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data
/etc/rc.d/rc.local/etc/rc.local
在文件或看看
contrib/start-scripts/linuxPostgreSQL源代码分发。

Check paragraph starting with "Different systems have different conventions for starting up daemons at boot time."

检查以“不同的系统在启动时启动守护程序有不同的约定”开头的段落。

Hope this helps.
Edmon

希望这可以帮助。
埃德蒙