rabbar
rabbar

Reputation: 109

In postgresql: CREATE ROLE works but createuser doesn't

I'm new to PostgreSQL and was following this tutorial. I can create roles just fine but when I tried to use the createuser and dropuser commands, it just doesn't do anything and no new users are created or any deleted. I tried to use it with and without the semi colon at the end, the former gives a syntax error and the latter just doesn't do anything.

    postgres-# createuser joe;
ERROR:  syntax error at or near "createuser"
LINE 1: createuser 
        ^
postgres=# ;
postgres=# createuser joe;
ERROR:  syntax error at or near "createuser"
LINE 1: createuser joe;
        ^
postgres=# createuser joe
postgres-# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 admin     | Superuser, Create DB                                       | {}
 john      | Superuser, Create role, Create DB, Replication             | {}
 guest     |                                                            | {}
 guest3    |                                                            | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

I also tried this:

createuser --interactive joe 

This also didn't do anything.

What's the correct way to use createuser? I'm using the following version.

postgres (PostgreSQL) 11.1

Upvotes: 9

Views: 13433

Answers (4)

Constantine S
Constantine S

Reputation: 1

is created by the postgres user in the console above:

createuser joe

Upvotes: 0

Samkov Max
Samkov Max

Reputation: 31

Command createuser need to run in console(bash). No need to do it in psql. Example:

createuser -h localhost -p 5432 joe

Upvotes: 3

user330315
user330315

Reputation:

Inside the psql tool you need to enter SQL commands. To create a user from SQL, you need to use create user.

The tutorial probably was running the command line utility createuser (not the SQL command)

To understand why:

postgres=# createuser joe

did not do anything, see: In psql, why do some commands have no effect?

Upvotes: 11

Nathan
Nathan

Reputation: 8149

I think you need a space between your command, something like the following:

CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';
GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;

Upvotes: 8

Related Questions