8. Oct 2021 |

PostgreSQL create db and user

I need it quite often during development (mainly school work) that I need to create new database together with new user that can only use this specific database. Here are three simple commands that do just that.

CREATE DATABASE robert_db;
CREATE USER robert WITH ENCRYPTED PASSWORD 'x1y2z3';
GRANT ALL PRIVILEGES ON DATABASE robert_db TO robert;

In development I usually keep db name and user name the same so that I have less variables to remember.

Leave a Reply

Your email address will not be published. Required fields are marked *