PostgreSQL

Скачать в pdf «PostgreSQL»


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 demouserl, 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


Figure 20.1: Examples of user administration


PostgreSQL user names do not have to be operating system users. For installations using database password authentication, a ereateuser 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
20.1 shows examples of user administration commands. 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 20.4.


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.

Скачать в pdf «PostgreSQL»