Difference between revisions of "PostgreSQL: CREATE USER"

From wikieduonline
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
  
  
* <code>CREATE USER "your_username";</code>
+
* <code>[[CREATE]] USER "your_username";</code>
 
* <code>CREATE USER your_username WITH ENCRYPTED PASSWORD 'your_pass';</code>
 
* <code>CREATE USER your_username WITH ENCRYPTED PASSWORD 'your_pass';</code>
 
* <code>CREATE USER username WITH CREATEUSER;</code>
 
* <code>CREATE USER username WITH CREATEUSER;</code>
Line 82: Line 82:
 
== See also ==
 
== See also ==
 
* {{Role}}
 
* {{Role}}
* {{psql}}
+
* {{CREATE}}
 
* {{SQL}}
 
* {{SQL}}
  
  
 
[[Category:PostgreSQL]]
 
[[Category:PostgreSQL]]

Latest revision as of 10:21, 11 July 2023

create user, creates a new user in PostgreSQL


  • CREATE USER "your_username";
  • CREATE USER your_username WITH ENCRYPTED PASSWORD 'your_pass';
  • CREATE USER username WITH CREATEUSER;
  • CREATE USER username WITH CREATEROLE;


Synopsys[edit]

CREATE USER name [ [ WITH ] option [ ... ] ]

where option can be:

      SUPERUSER | NOSUPERUSER
    | CREATEDB | NOCREATEDB
    | CREATEROLE | NOCREATEROLE
    | INHERIT | NOINHERIT
    | LOGIN | NOLOGIN
    | REPLICATION | NOREPLICATION
    | BYPASSRLS | NOBYPASSRLS
    | CONNECTION LIMIT connlimit
    | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
    | VALID UNTIL 'timestamp'
    | IN ROLE role_name [, ...]
    | IN GROUP role_name [, ...]
    | ROLE role_name [, ...]
    | ADMIN role_name [, ...]
    | USER role_name [, ...]
    | SYSID uid


Examples[edit]

  • create user your_username

Create a new user[edit]

create user your_username;
Output:
CREATE ROLE
create user your_username;
Output:
ERROR: permission denied to create role

Create a new user with errors[edit]

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[edit]

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

Related terms[edit]

See also[edit]

Advertising: