Postgres,ubuntu 如何在启动时重新启动服务

我在 AWS EC2上运行 Postgres db 9.1ubuntu 12.04

我对这个实例做了很多修改(例如,在我选择9.1之前安装了各种 postgres X.X)。

现在,在处理该数据库一个月后,我发现如果重新启动我的实例 postgres不能正确加载,它的状态就是“运行集群”。这将永远持续下去,直到我

sudo service postgresql restart

从终端,然后它再次工作。

我如何添加这一行,到 ubuntu 启动,以便每次它加载,它将重新启动这个服务,并希望解决我的问题?

还有其他可能解决这个问题的解决方案。

239615 次浏览

I guess it would be best to fix the database startup script itself. But as a work around, you can add that line to /etc/rc.local, which is executed about last in init phase.

On Ubuntu 18.04:

sudo systemctl restart postgresql.service

ENABLE is what you are looking for

USAGE: type this command once and then you are good to go. Your service will start automaticaly at boot up

 sudo systemctl enable postgresql

DISABLE exists as well ofc

Some DOC: freedesktop man systemctl

The below command worked for me

sudo service postgresql restart

restart postgresql

$ sudo service postgresql restart

for ubuntu startup so that each time it loads, it will restart this service of Postgres on startup so that you won't have to restart it all the time

sudo update-rc.d postgresql enable