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

222,100

Solution 1

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.

Solution 2

On Ubuntu 18.04:

sudo systemctl restart postgresql.service

Solution 3

The below command worked for me

sudo service postgresql restart

Solution 4

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

Solution 5

restart postgresql

$ sudo service postgresql restart
Share:
222,100

Related videos on Youtube

yaron
Author by

yaron

Updated on February 08, 2022

Comments

  • yaron
    yaron about 2 years

    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.

    • Albert Hendriks
      Albert Hendriks almost 9 years
      If you came here by google (like me) looking for the command to restart postgresql, in my case it was service postgresql-9.3 restart
    • Ismail Yavuz
      Ismail Yavuz over 5 years
      I made Albert's comment a Question and Answer: stackoverflow.com/questions/52610485/…
    • Ayoub Laazazi
      Ayoub Laazazi over 5 years
      Came just to get that restart command, got what I want, thanks
  • yaron
    yaron almost 11 years
    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.
  • TeTeT
    TeTeT almost 11 years
    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.
  • yaron
    yaron almost 11 years
    thanks the rc was the right directions, i found the solution in the rcX files. which govern the startup order
  • Rajan Verma - Aarvy
    Rajan Verma - Aarvy over 4 years
    You need to provide the cluster version as well: sudo systemctl start postgresql-9.5.service
  • Michael B.
    Michael B. about 3 years
    @Aarvy strangely, on Ubuntu 20 with Postrges 13, the version isn't needed for systemctl
  • CHAVDA MEET
    CHAVDA MEET over 2 years
    maybe i think this is for enable....
  • Nathan Smiechowski
    Nathan Smiechowski over 2 years
    @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?