Difference between revisions of "PostgreSQL: CREATE USER"

From wikieduonline
Jump to navigation Jump to search
Line 1: Line 1:
 
<code>[[create user]]</code>, creates a new user in PostgreSQL
 
<code>[[create user]]</code>, creates a new user in PostgreSQL
* Official documentation: https://www.postgresql.org/docs/13/sql-createuser.html
+
* Official documentation: https://www.postgresql.org/docs/15/sql-createuser.html
  
 
== Examples ==
 
== Examples ==

Revision as of 14:22, 15 December 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 user your_username;
Output:
ERROR: permission denied to 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
CREATE USER your_username WITH ENCRYPTED PASSWORD 'your_pass';
Output:
ERROR:  role "your_username" already exists
Solution:
ALTER USER user_name WITH PASSWORD 'new_password';
Assign a role with GRANT command:
GRANT your_defined_role TO your_username;
Output:
GRANT ROLE
  • CREATE USER username WITH CREATEUSER

Related terms

See also

Advertising: