Postgresql – finding the path to start postgres

postgresql

On my local machine, when I want to start the postgres server (postgres was installed via Homebrew), I do this

pg_ctl -D /usr/local/var/postgres -l logfile start

I just installed postgres on a ubuntu vps (without Homebrew and not on OSX obviously) and the files are obviously set up a little differently, however, based on what I did on the local machine to start pg, I tried to find the path to postgres folder on the vps. From my home/michael directory, I backed up two levels cd ../../ to a folder which contains these folders

bin   etc         lib         mnt   root  selinux  tmp  vmlinuz
boot  home        lost+found  opt   run   srv      usr
dev   initrd.img  media       proc  sbin  sys      var

Inside etc, there's a postgresql inside of which there's a 9.1 folder, inside of which is main that has all these files

environment  pg_hba.conf    postgresql.conf
pg_ctl.conf  pg_ident.conf  start.conf

Based on how I start pg on my local machine, I'm assuming pg_ctl.conf is the file I'm looking for. I tried to start pg this way

 pg_ctl -D /etc/postgresql/9.1/main -l logfile start

but I get the response

-bash: pg_ctl: command not found

I'm assuming that I have to start the server once before launch of the app and then let it run, but I can't get it started.

Update

Once I finished installing postgres, I ran this command

sudo service postgresql restart

I'm not sure if that starts postgres once and I never need to start it again (hence this question is moot), or if that was just something I do at install and then start it everytime I use it as I do on my local machine.

Best Answer

When you install a program in Linux it is most often configured to just work. So you would do service postgresql start to start it, service postgresql stop to stop, and service postgresql status to check if it's working etc.

You may need to set it up that it will start automatically on boot. How to do this depends on your system version, so you may need to Google it. On my system it is chkconfig postgresql on to enable, and chkconfig postgresql off to disable.

If you want to find where is data directory of a running postgres then you can use sudo su postgres -c "psql -c 'show data_directory'". You can find Postgres configuration files, logs and data there.