Обсуждение: running postgres
may this be a silly doubts but , i am new to postgres, please answer to these:: /usr/local/pgsql/bin/psql test test=# sudo su postgres -c psql template1 template=# what is the difference between the above two and, why is the path different in both cases which should i use now 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? Thanks & Regards kusuma.p
On Thu, Feb 5, 2009 at 15:35, Kusuma Pabba <kusumap@ncoretech.com> wrote: > > may this be a silly doubts but , i am new to postgres, please answer to > these:: > > /usr/local/pgsql/bin/psql test > test=# > > > sudo su postgres -c psql template1 > template=# > > > what is the difference between the above two and, > why is the path different in both cases > which should i use now first you connect to the database test in the second one you run the command "psql" on the database template1 -c COMMAND run only single command (SQL or internal) and exit > > 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? you can create a user with "createuser" commandline tool or use the CREATE ROLE sql command (http://www.postgresql.org/docs/8.3/static/sql-createrole.html) and then use the GRANT command (http://www.postgresql.org/docs/8.3/static/sql-grant.html) to give the user rights to the database you want. See the GRANT ... ON DATABASE part for this. -- [ Clemens Schwaighofer -----=====:::::~ ] [ IT Engineer/Manager ] [ E-Graphics Communications, TEQUILA\ Japan IT Group ] [ 6-17-2 Ginza Chuo-ku, Tokyo 104-8167, JAPAN ] [ Tel: +81-(0)3-3545-7703 Fax: +81-(0)3-3545-7343 ] [ http://www.tequila.jp ] Advertising Age Global Agency of the Year 2008 Adweek Global Agency of the Year 2008 This e-mail is intended only for the named person or entity to which it is addressed and contains valuable business information that is privileged, confidential and/or otherwise protected from disclosure. Dissemination, distribution or copying of this e-mail or the information herein by anyone other than the intended recipient, or an employee or agent responsible for delivering the message to the intended recipient, is strictly prohibited. All contents are the copyright property of TBWA Worldwide, its agencies or a client of such agencies. If you are not the intended recipient, you are nevertheless bound to respect the worldwide legal rights of TBWA Worldwide, its agencies and its clients. We require that unintended recipients delete the e-mail and destroy all electronic copies in their system, retaining no copies in any media.If you have received this e-mail in error, please immediately notify us via e-mail to disclaimer@tbwaworld.com. We appreciate your cooperation. We make no warranties as to the accuracy or completeness of this e-mail and accept no liability for its content or use. Any opinions expressed in this e-mail are those of the author and do not necessarily reflect the opinions of TBWA Worldwide or any of its agencies or affiliates.
Quoth Kusuma Pabba <kusumap@ncoretech.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
On Thu, Feb 05, 2009 at 08:12:48AM +0000, Sebastian Tennant wrote: > This is why you need to type 'sudo su postgres -c psql template1'. A little shortcut, you can do the above from sudo as: sudo -u postgres psql template1 This was pointed out to me by another kind soul on this list, but I can't, for the life of me, remember who though! Sorry -- Sam http://samason.me.uk/
On Thu, Feb 05, 2009 at 12:05:31PM +0530, Kusuma Pabba wrote: > 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? Users are associated with the "cluster" and not with any specific database. I tend to add users by directly entering the SQL, but, as others have noted, there's a program called "createuser" that you can use instead. Only a few users can normally create new users (or "roles" as they have recently been changed to) and you can see who by typing \du into psql and looking for the "Create role" column. Normally only the database owner (i.e. the "postgres" user) can create new users by default, which is probably where you got the "su postgres" command from. Once you've logged in with somebody whose capable of creating users, you need to type something like: CREATE USER furble; GRANT CONNECT ON DATABASE test TO furble; This will create the user "furble" and allow them to connect to the "test" database. I believe it's generally preferable to use groups to control permission and add users to groups rather than granting them specific rights. But use cases vary. The manual pages for these things are: http://www.postgresql.org/docs/current/static/user-manag.html http://www.postgresql.org/docs/current/static/sql-createrole.html http://www.postgresql.org/docs/current/static/sql-grant.html http://www.postgresql.org/docs/current/static/app-createuser.html You will probably need to think about authentication, at which point the following section will help: http://www.postgresql.org/docs/current/static/client-authentication.html -- Sam http://samason.me.uk/