postgres, ubuntu how to restart service on startup? get stuck on clustering after instance reboot
Asked Answered
C

6

93

I have a Postgres db 9.1 running on AWS EC2, with ubuntu 12.04.

I messed a lot with the instance (i.e installed all kinds of postgres X.X before i settled on 9.1).

Now after a month working on that db, I discovered that if I restart my instance postgres doesn't load correctly, its status says "Running clusters". this will last forever until I

sudo service postgresql restart

from terminal, and then it works again.

How do I add this line, to ubuntu startup so that each time it loads, it will restart this service, and hopefully solve my problem?

Also any other solution which might solve this.

Calcifuge answered 13/5, 2013 at 6:4 Comment(3)
If you came here by google (like me) looking for the command to restart postgresql, in my case it was service postgresql-9.3 restartEvictee
I made Albert's comment a Question and Answer: #52610985Ait
Came just to get that restart command, got what I want, thanksHydrometer
W
7

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.

Without answered 13/5, 2013 at 9:53 Comment(3)
thanks, but either that rc.local is not running, or the command executed before whatever postgres is doing, or the db overrides it somehow, il look into the logs for info, but off the bat that does not work.Calcifuge
Maybe there is a race condition, so rc.local gets executed before the regular postgres start process is finished, probably due to the error. Maybe you can add a sleep before the restart and see if that is a valid work around.Without
thanks the rc was the right directions, i found the solution in the rcX files. which govern the startup orderCalcifuge
R
45

On Ubuntu 18.04:

sudo systemctl restart postgresql.service

Recollect answered 14/12, 2018 at 13:24 Comment(2)
You need to provide the cluster version as well: sudo systemctl start postgresql-9.5.serviceSoke
@Aarvy strangely, on Ubuntu 20 with Postrges 13, the version isn't needed for systemctlDescend
S
17

The below command worked for me

sudo service postgresql restart
Shannanshannen answered 17/3, 2020 at 11:40 Comment(1)
Worked for me on Ubuntu 22.04, via WSL 2 on WindowsResponsiveness
N
10

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

Nonstriated answered 5/12, 2019 at 15:27 Comment(2)
maybe i think this is for enable....Mammoth
@CHAVDAMEET the question was How do I add this line, to ubuntu startup so that each time it loads, it will restart this service, and hopefully solve my problem?Nonstriated
W
7

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.

Without answered 13/5, 2013 at 9:53 Comment(3)
thanks, but either that rc.local is not running, or the command executed before whatever postgres is doing, or the db overrides it somehow, il look into the logs for info, but off the bat that does not work.Calcifuge
Maybe there is a race condition, so rc.local gets executed before the regular postgres start process is finished, probably due to the error. Maybe you can add a sleep before the restart and see if that is a valid work around.Without
thanks the rc was the right directions, i found the solution in the rcX files. which govern the startup orderCalcifuge
M
6

restart postgresql

$ sudo service postgresql restart
Mammoth answered 30/10, 2021 at 11:1 Comment(0)
M
1

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
Mammoth answered 8/2, 2022 at 5:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.