Re: running postgres

From: Sebastian Tennant <sebyte(at)smolny(dot)plus(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: running postgres
Date: 2009-02-05 08:12:48
Message-ID: vdrpcnen.fsf@vps203.linuxvps.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Quoth Kusuma Pabba <kusumap(at)ncoretech(dot)com>:
> /usr/local/pgsql/bin/psql test
> test=#

> sudo su postgres -c psql template1
> template=#

> why is the path different in both cases?

Type:

$ which psql

and

$ sudo which psql

The answer is the same, yes?

$ /usr/local/pgsql/bin/psql test
|___________________|
|
absolute path

$ cd /usr/local/pgsql
$ bin/psql test
|__|
|
relative path

When you provide an absolute path (or a relative path), your shell does
not search your $PATH environment variable for the program - it just
runs the program in the directory you specified.

When you don't provide a path of any sort, your shell looks for the
program in the directories specified in your $PATH environment variable.

Check the value of your $PATH by typing:

$ echo $PATH

If there is only one executable file called 'psql' in the directories in
your PATH, it makes no difference whether you specify a path, or no path
at all.

Note that different users may have different directories in their $PATH.
Your can alter your $PATH variable (if you need to) in your ~/.profile.

> what is the difference between the above two and,

'sudo <command>' is a command for running a single command with
superuser privileges, i.e., 'as root'.

'su <user>' (without the -c switch) is a command for 'becoming' <user>
until you type 'exit'.

'su <user> -c <command>' is similar to 'sudo' in that the single command
<command> is run as <user>.

If you type:

$ su postgres -c psql template1

you will be asked for a password, and if you haven't setup any user
accounts and passwords in postgres you won't know what the password is,
and therefore you won't be able to connect.

This is why you need to type 'sudo su postgres -c psql template1'. sudo
temporarily makes you root, and root is never asked for passwords (root
is God in the UNIX world) so you are able to connect as user 'postgres'.

> how can i create a user in test or template?

> when i give create user it is asking for create role , how should i
> create role?

Others with a better understanding of users and roles should answer this
question.

Sebastian
--
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thom Brown 2009-02-05 09:49:38 Automatic database upgrade
Previous Message Alban Hertroys 2009-02-05 07:58:30 Re: Moving between major versions easily (Was: Vacuums taking forever :()