Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Overview of this book

Table of Contents (19 chapters)
PostgreSQL 9 Administration Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a new user


In this recipe, we will show you two ways of creating a new database user, one with a dedicated command-line utility, and one using SQL commands.

Getting ready

To create new users, you must either be a superuser or have the CREATEROLE or CREATEUSER privilege.

How to do it…

From the command line, you can run the createuser command:

pguser@hvost:~$ createuser bob

If you add the --interactive command-line option, you activate the interactive mode, which means you will be asked some questions, as follows:

pguser@hvost:~$ createuser --interactive alice
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n

Without --interactive, the preceding questions get "no" as the default answer; you can change that with the -, -d, and -r command-line options.

In interactive mode, questions are asked only if they make sense. One example is the case when the user will be a superuser...