First I run the command:
sudo su _postgres
Then I run the command:
create role mixeddrinks with createdb login password 'password1'
But it comes back with:
-bash: create: command not found
I’m not very familiar with the Terminal and with PostgreSQL so I’m not sure what I am doing wrong I am trying to create a role and a database.
You can create new roles from the command line with the createuser command. Using the --interactive flag will prompt you for the name of the new role and also ask whether it should have superuser permissions. Logged in as the postgres account, you can create a new user by typing: createuser --interactive.
Users, groups, and roles are the same thing in PostgreSQL, with the only difference being that users have permission to log in by default. The CREATE USER and CREATE GROUP statements are actually aliases for the CREATE ROLE statement.
If you are using the psql command line client, you can take advantage of some helpful meta-commands which allow you to get role attribute information without a query. In this case, the postgres role is the default role with superuser privileges configured for this database cluster.
First I run the command
sudo su _postgres
, then I run the commandcreate role mixeddrinks with createdb login password 'password1'
You're mixing up shell commands and the psql
command line.
If you want to use SQL, you need to use the psql
command. sudo su _postgres
is an inefficient way of getting a unix command shell as the _postgres
user. It doesn't give you an SQL shell. You can run unix commands like psql
, createuser
, etc from the unix command shell. You can tell you're at the command shell because the prompt looks something like:
postgres$
If you want an SQL shell, so you can run commands like CREATE USER
, etc, you need to run psql
. If you want a superuser SQL shell, that'd be something like:
sudo -u _postgres psql
This will give you a prompt like:
postgres=#
where you can run SQL commands. Remember that SQL commands end with a semicolon.
postgres=# create role mixeddrinks with createdb login password 'password1';
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