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

  Work with me!


Call to action

Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )

Thank you for reading! And see you soon on Strangebuzz! 😉

COil