9

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
rabbar
  • 109
  • 1
  • 1
  • 9

4 Answers4

11

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?

  • Okay, I might have misunderstood the tutorial. I thought it meant that the utility came with the package and tried to use both in psql and command line. Thanks for clarifying! – rabbar Jan 10 '19 at 02:48
8

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;
Nathan
  • 7,853
  • 4
  • 27
  • 50
3

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

createuser -h localhost -p 5432 joe
Samkov Max
  • 31
  • 1
0

is created by the postgres user in the console above:

createuser joe
LinFelix
  • 1,026
  • 1
  • 13
  • 23