658 CHAPTER (Web hosting ratings) 29 SECURING POSTGRESQL Adding New
658 CHAPTER 29 SECURING POSTGRESQL Adding New Users Adding new users to PostgreSQL is accomplished through the CREATE USER command. The CREATE USER command has the following syntax: CREATE USER username [ WITH SYSID uid | CREATEDB | NOCREATEDB | CREATEUSER | NOCREATEUSER | IN GROUP groupname [, …] | [ ENCRYPTED | UNENCRYPTED ] PASSWORD ‘password’ | VALID UNTIL ‘abstime’ ] The recommended practice is to leave the SYSID field blank, so that it will be autogenerated for you. The CREATEDB field corresponds to allowing the user to create, add, and drop databases within the database; by default, users do not get this privilege. Specifying the CREATEUSER option will create the user as an administrative-level account, allowing them to add and remove other users from the system; again, the default is to not give this privilege. You can also add the user to any groups you might have in the database, via the INGROUP parameter. Of course, you will normally want to store a password for each user as well. Finally, the VALIDUNTIL clause allows you to specify a time in which the account will expire automatically and disallow further logins. As an example, we might create the following user howard, who has permissions to create new databases, and will be able to log in until the end of the year: CREATE USER howard WITH PASSWORD ‘T3rc35′ CREATEDB VALID UNTIL ‘2005-12-31′; Manipulating Users To modify the attributes of a user, we use the ALTER USER command. Its syntax looks like: ALTER USER username [ WITH CREATEDB | NOCREATEDB | CREATEUSER | NOCREATEUSER | [ ENCRYPTED | UNENCRYPTED ] PASSWORD ‘password’ | VALID UNTIL ‘abstime’ The parameters to the ALTER USER command follow the same definitions as those of the CREATE USER command. For example, if we wanted to modify our previous user to remove the create database privileges, it would look like this: ALTER USER howard NOCREATEDB; Sometimes you may need to change the user s name, in which case the alternate syntax is provided: ALTER USER name RENAME TO newname Removing Users To remove a user, we use the DROP USER command. Its syntax is very straightforward:
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.