Difference between revisions of "PostgreSQL: CREATE USER"

From wikieduonline
Jump to navigation Jump to search
Line 25: Line 25:
 
  Assign a role with <code>[[GRANT]]</code> command:
 
  Assign a role with <code>[[GRANT]]</code> command:
 
  GRANT [[your_defined_role]] TO your_username;
 
  GRANT [[your_defined_role]] TO your_username;
 +
Output:
 +
[[GRANT ROLE]]
  
 
* [[List users]]: <code>[[\du]]</code>
 
* [[List users]]: <code>[[\du]]</code>

Revision as of 12:11, 20 April 2022

create user, creates a new user in PostgreSQL

Examples

  • create user your_username

Create a new user

create user your_username;
Output:
CREATE ROLE

Create a new user with errors

create user your.username;
Output:
ERROR:  syntax error at or near "."
create user your_username;
ERROR:  cannot execute CREATE ROLE in a read-only transaction

Create a new user and assign a password

CREATE USER your_username WITH ENCRYPTED PASSWORD 'your_pass';
Output:
CREATE ROLE
Assign a role with GRANT command:
GRANT your_defined_role TO your_username;
Output:
GRANT ROLE

Related terms

See also

Advertising: