next up previous contents index
Next: Creating Databases Up: Administration Previous: Files

  
Creating Users

To create new users, you run createuser from an operating system prompt. Initially, only the POSTGRESQL superuser, typically postgres, can create new users. Other users can be given permission to create new users and databases.

POSTGRESQL user names do not have to be operating system users. For installations using database password authentication, a createuser flag allows passwords to be assigned.

Users are removed with dropuser. The CREATE USER, ALTER USER, and DROP USER commands are available in SQL.

POSTGRESQL also supports the creation of groups using CREATE GROUP  in SQL. GRANT  permissions can be specified using these groups.  

Figure [*] shows examples of user administration commands.

 

        $ createuser demouser1
        Shall the new user be allowed to create databases? (y/n) n
        Shall the new user be allowed to create more new users? (y/n) n
        CREATE USER
        $ psql test
        Welcome to psql, the PostgreSQL interactive terminal.
         
        Type:  \copyright for distribution terms
               \h for help with SQL commands
               \? for help on internal slash commands
               \g or terminate with semicolon to execute query
               \q to quit
         
        test=> CREATE USER demouser2;
        CREATE USER
        test=> ALTER USER demouser2 CREATEDB;
        ALTER USER
        test=> CREATE GROUP demogroup WITH USER demouser1, demouser2;
        CREATE GROUP
        test=> CREATE TABLE grouptest (col INTEGER);
        CREATE
        test=> GRANT ALL on grouptest TO GROUP demogroup;
        CHANGE
        test=> \connect test demouser2 
        You are now connected to database test as user demouser2.
        test=> \q
 

In the figure, one user is created from the command line, a second user is created in psql, and a user is modified. Next, a group is created and given table permissions. Finally, the program reconnects to the database as a different user, which is possible because the site has local users configured with trust access. This issue is covered in Section [*].

These commands can be performed only by a user with create user privileges. More information about each command can be found in the manual pages.  


next up previous contents index
Next: Creating Databases Up: Administration Previous: Files
Bruce Momjian
2001-05-09