9

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.

1 Answer 1

15

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';
Sign up to request clarification or add additional context in comments.

6 Comments

whenever I run 'sudo -u _postgres psql' command it throws an error saying 'could not identify current directory: Permission denied psql: FATAL: role "_postgres" does not exist'
@TylerRice Argh. I want to get everyone who packaged PostgreSQL for Mac OS X into a room, and let the one survivor out when they've sorted it out in there. sudo -u _postgres psql -U postgres on your particular weird packaging of PostgreSQL.
its throwing the same error still... If you don't know how to fix this i'll just accept your answer since it did answer the original question and I'll make another one
@TylerRice would be great if you could link to your follow-up question, having the same issue.
@TylerRice did you try either simply psql postgres or sudo psql postgres? That eventually cracked it for me.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.