Question

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.

Was it helpful?

Solution

First I run the command sudo su _postgres, then I run the command create 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';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top