Creating a Postgres database with an associated user of the same name
Published on 2020-05-27 • Modified on 2020-05-27
In this snippet, we will see how to create a PostgreSQL database with an associated user of the same name. We create a user then we create a database with the same name. We connect to Postgres to change the password of the new user with a stronger one. Eventually, we change the owner of the database for the user we just created.
sudo -u postgres createuser --interactive
sudo -u postgres createdb mynewdb
sudo -u postgres psql
ALTER USER mynewdb WITH PASSWORD 'new_password'
ALTER DATABASE mynewdb OWNER TO mynewdb
More on Stackoverflow Read the doc Random snippet