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.
-
voting to close with no explanation?Leahcim– Leahcim2013年06月08日 20:43:55 +00:00Commented Jun 8, 2013 at 20:43
-
@Leahcim Closevote off topic with migration pretty much is a comment, IMO.Craig Ringer– Craig Ringer2013年06月09日 02:18:43 +00:00Commented Jun 9, 2013 at 2:18
2 Answers 2
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.
-
when you say "it is most often configured to just work" does that mean I don't have to run the
initdb
that I had to run after installing pg on my local machine? If I have to run it, I'm not sure what path to include after it. I tried to dosudo su postgres -c "psql -c 'show data_directory'"
but I screwed up the password somehow and it's saying unauthorized, so even if there is a data directory i'm not able to find it. Please let me know about the initdb command and then I'll accept your answer, because it's unclear to me exactly what 'it is most often configured to just work means'Leahcim– Leahcim2013年06月08日 23:33:43 +00:00Commented Jun 8, 2013 at 23:33 -
initdb is run automatically with correct settings when you start
postgresql
service for the first time after installation. You can stop postgres, remove data directory contents and start it again to reset it to distribution defaults. Warning: It will delete all data from the database.Tometzky– Tometzky2013年06月09日 07:42:14 +00:00Commented Jun 9, 2013 at 7:42
When you install PostgreSQL from packages on Ubuntu it's automatically set up with a single cluster (server) running. initdb
has already been run and the server is already running.
The postgres
user account is the only user account and is set up with no password and with peer
authentication from the postgres
unix user account, meaning that you can connect to the postgres
PostgreSQL account if you run the client program from the postgres
unix account.
This means that you start with:
sudo -u postgres psql
from whence you can create users, databases, etc. sudo -u postgres createdb
etc also work if you prefer the shell wrapper commands to CREATE USER
, CREATE DATABASE
etc SQL commands.
To learn more read the Ubuntu PostgreSQL documentation, which sets all this out.