Create User
Define a new database user with automatic schema creation.Syntax
Parameters
The name of the new user.
Sets the user’s password.
Stores a comment about the user, e.g., the user’s real name. The comment can be viewed in psql using the
\du+ command.What CREATE USER Does
create user performs three operations:
- Creates a new database user
- Registers the user with the Metadb instance (enables privilege grants)
- Creates a user schema as a workspace for the user
The user schema has the same name as the user and serves as a personal workspace where the user can create tables, views, and other objects.
Example
Create a user with password and comment:Register User
Register an existing user to receive database privileges.Syntax
Parameters
The name of the user to register.
Description
register user associates an existing user with the Metadb instance. This allows the user to be granted privileges via the grant command.
Normally there is no need to issue
register user, because create user executes it automatically. However, if an existing user was created in some other way (e.g., directly in PostgreSQL), register user can enable it for the Metadb instance.Example
Register an existing PostgreSQL user:Create Schema for User
Create a user workspace schema for an existing registered user.Syntax
Parameters
The name of the user, which will also be the name of the new schema.
Description
create schema creates a user schema that serves as a workspace. The user automatically receives appropriate privileges on this schema.
Typically user schemas are created automatically by
create user. However, if a user already exists and is registered but does not have a user schema, create schema for user can be used to create it.Example
Register an existing user and create their schema:Deregister User
Remove a user’s ability to have database privileges.Syntax
Parameters
The name of the user to deregister.
Description
deregister user removes the ability to have database privileges from a user. It performs two operations:
- Automatically executes
revoke access on all - Prevents subsequent
grantcommands for this user
Example
Deregister a user:Drop User
Completely remove a database user.Syntax
Parameters
The name of the user to be removed.
Description
drop user removes a database user completely. Before doing so, it attempts to find and revoke most authorizations held by the user that would typically prevent removal.
Example
Remove a user:User Management Workflow
- New User (Recommended)
- Existing User
- Temporary Access Removal
- Complete User Removal
For a brand new user, use the all-in-one command:This creates the user, registers them, and creates their workspace schema.
View Users
List all registered users using the system function:See Also
Access Control
Grant and revoke access to data
System Functions
View users and system information
