1

I want to create a database and a user for my project

# sudo su - postgres
# psql

Method 1:

CREATE DATABASE myproject;
CREATE USER myprojectuser WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;

Method 2:

CREATE USER myprojectuser WITH PASSWORD 'password';
CREATE DATABASE myproject OWNER myprojectuser

So which is the right way

1 Answer 1

1

First you create USER/ROLE:

CREATE ROLE myprojectuser createdb login password 'password';

After you've done that, you can check all users using command \du

Then CREATE DATABSE:

CREATE DATABASE myproject OWNER myprojectuser;

After you've created database,you can connect to your database as myprojectuser using:

\c myproject myprojectuser localhost
Sign up to request clarification or add additional context in comments.

Comments

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.