Skip to content

Instantly share code, notes, and snippets.

@sirodoht
Last active July 30, 2021 09:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirodoht/0666e232e1baf76f76bac43eb2600e2b to your computer and use it in GitHub Desktop.
Save sirodoht/0666e232e1baf76f76bac43eb2600e2b to your computer and use it in GitHub Desktop.
How to create new database and new user with password on PostgreSQL (the easiest way)

How to create new database and new user with password on PostgreSQL

First, create db:

$ createdb avocado

Then, create user:

$ createuser avocado

Then, login to psql with admin user (usually postgres) and change password of new user:

$ sudo -u postgres psql
psql (9.6.2, server 9.4.4)
Type "help" for help.

postgres=# \password avocado
Enter new password:
Enter it again:
postgres=# \q

Give create db permission to new user

$ sudo -u postgres psql
psql (9.6.2, server 9.4.4)
Type "help" for help.

postgres=# ALTER USER avocado CREATEDB;
ALTER ROLE
postgres-# \q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment