16

I am new to Ubuntu and I would like to know how to make postgresql start automatically on boot and how to configure my setup so that I can start the postgres server if need be.

I am working on a small rails project and I have been having difficulties with postgres starting correctly. I have had to resort to uninstalling and reinstalling postgres to just get the project up and running just to get work done. I have been using these commands.

sudo apt-get -y update
sudo apt-get purge postgresql* # ending * is important
sudo apt-get install postgresql libpq-dev

from this post

https://stackoverflow.com/questions/17934055/postgresql-cannot-connect-to-server-locally

skipping

sudo add-apt-repository ppa:pitti/postgresql

as it appears it is out of date and there's a comment below about not needing it.

If it helps my pg_hba.conf file appears to be located at

/etc/postgresql/9.1/main

I am running Ubuntu 12.04 on top of chrome os

Thanks all for the help and sorry for the newb question!

  • Why are you using some random person's PPI? Use apt.postgresql.org if you want current PostgreSQL releases on older platforms. – Craig Ringer Oct 20 '14 at 7:43
  • Craig thanks for the response. Just to clarify the what would the command be to pull from the apt.postgresql.org be? – cwmacken Oct 22 '14 at 4:05
  • @cwmacken there are instructions in the linked page (including commands). – muru Oct 22 '14 at 4:18
  • @Craig haha sorry missed that it was a link. Thanks for the help! Cheers – cwmacken Oct 22 '14 at 4:20
27

If you want to start postgres on startup so that you wont have to restart is all the time simply do:

sudo update-rc.d postgresql enable

this will always start your postgres on boot startup. hope it helps someone

  • I get error: update-rc.d: error: cannot find a LSB script for postgrsql But I installed postgresql from other repo (1c.postgrespro.ru/deb) because it has special patches I need. – Alexander Kuzin Sep 22 '16 at 16:10
  • Thank you! My problem was: I disabled the service with systemctl disable postgresql.service. But I was no longer able to enable it with systemctl. Your answer was the solution. My system: Debian 8.8 x64 with PostgreSQL 9.4. – mfreiholz Dec 13 '17 at 6:51
13

From Ubuntu 15.04 onwards do:

sudo systemctl enable [SERVICE]

Which in your case is:

sudo systemctl enable postgresql
  • it works, however; after starting ubuntu a popup asks for admin password, anyway to get rid of it? – tolgayilmaz Mar 16 '17 at 12:03
  • Sorry, I've been only using a headless ubuntu on a server-system, so I never encountered that issue :-( Maybe someone else ran into the same problem and can help. – Kim Mar 16 '17 at 13:20
3

So I figured out how to boot postgresql so i dont need to do the reinstall newb move.

sudo service postgresql start

you will then need to switch to the postgres user to do any changes within Postgresql

sudo -u postgres -i

I'm sure there are much better answers to this question than mine but this might help someone in my position in the future.

I still need to make Postgresql start on boot. Anyone got the answer to that? Ill gladly mark it as correct.

Cheers

  • There is an answer to start automatically upon boot – Anwar Apr 28 '16 at 14:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.