How do I create a new role in PostgreSQL?

To create a role in Postgres, use the CREATE ROLE statement followed by the new role name. CREATE ROLE new_role; The new_role in the above example is the name of the role created using the CREATE ROLE statement in PostgreSQL. The only information we see about the _newrole is that it has no login privileges.

How do I log into Postgres as a different user?

There are two ways to login PostgreSQL:
  1. By running the “psql” command as a UNIX user which is also configured as PostgreSQL user using so-called IDENT/PEER authentication, e.g., ” sudo -u postgres psql “.
  2. Via TCP/IP connection using PostgreSQL’s own managed username/password (using so-called MD5 authentication).

How do I create a user and grant privilege in PostgreSQL?

PostgreSQLCreate User, Create Database, Grant privileges/access.
  1. Switch to postgres user. sudo su postgres.
  2. Enter the the interactive terminal for working with Postgres. psql.
  3. Create the database (change database_name)
  4. Create user (change my_username and my_password)
  5. Grant privileges on database to user.