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
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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With