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
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 )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉
