Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating role and database PostgreSQL not working

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.

like image 692
Tyler Avatar asked Jan 16 '14 01:01

Tyler


People also ask

How do I create a new role in PostgreSQL?

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.

Is role same as user in postgres?

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.

Which default role is created automatically with PostgreSQL?

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.


1 Answers

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';
like image 62
Craig Ringer Avatar answered Oct 28 '22 22:10

Craig Ringer