what is the difference between ""psql"" and ""postgres"" commands?

I'm running mountain lion and I am getting very different responses when I run the psql or postgres commands.

For the former I get:

> psql
ovatsug25=#

For the latter I get:

> postgres
postgres does not know where to find the server configuration file.

You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

I installed postgres via homebrew and ran

rm /usr/bin/psql

after doing so.

My main problem is fixed (Rails starts and connects to the db) but I'm not sure where the difference lies between these commands or how that happened. Still trying to figure it out bun in the meantime...I'd appreciate any help.

Their locations

which psql
/usr/local/bin/psql

and which postgres

which postgres
/usr/local/bin/postgres

Solution 1:

postgres is the server itself, and runs separately from all of the client connections. It is almost never run by hand. Even if you want to start and stop it, this is normally done through pg_ctl or an init script if you installed a postgres package from your distribution. I'm not sure if the OSX version of Postgresql has any special ways of starting the server, but it needs to be started before any clients can connect to it.

psql is the command-line client, that connects to the server and allows you to execute individual queries by hand. No idea why you think you needed to rm it, but not having it is just annoying since without it you'll have to write your own programs to execute commands like "CREATE TABLE" or "CREATE USER".