Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 547
zach Avatar asked Jan 09 '19 22:01

zach


Video Answer


2 Answers

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?

like image 112
a_horse_with_no_name Avatar answered Oct 24 '22 00:10

a_horse_with_no_name


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;
like image 8
Nathan Avatar answered Oct 23 '22 23:10

Nathan