91

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.

alko989
  • 7,688
  • 5
  • 39
  • 62
yaron
  • 1,283
  • 1
  • 11
  • 21

6 Answers6

44

On Ubuntu 18.04:

sudo systemctl restart postgresql.service

Ali
  • 6,808
  • 3
  • 37
  • 47
15

The below command worked for me

sudo service postgresql restart

Shahid Hussain Abbasi
  • 2,508
  • 16
  • 10
9

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

Community
  • 1
  • 1
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.

Tombart
  • 30,520
  • 16
  • 123
  • 136
TeTeT
  • 2,044
  • 20
  • 30
  • 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. – yaron May 13 '13 at 16:08
  • 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. – TeTeT May 14 '13 at 12:17
  • thanks the rc was the right directions, i found the solution in the rcX files. which govern the startup order – yaron May 15 '13 at 07:18
6

restart postgresql

$ sudo service postgresql restart
CHAVDA MEET
  • 777
  • 8
  • 14
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
CHAVDA MEET
  • 777
  • 8
  • 14