Home Linux Postgresql React VR HTML/CSS PHP Blog T-Shirt Shop PHP Fiddle

Setup Postgresql









Postgresql › Setup Postgresql

In this lesson, I will use Ubuntu to switch to the postgres user, create a new role/user and create a database. I will then use psql to alter user, giving her a password.


Step 1: Switch to Postgres User

$ sudo -i -u postgres

Step 2: Create New User

$ createuser --interactive

... Next you will be asked:

✶ Enter the name of role to add:
✶ Is this a superuser?(y/n)

Username

I am using the username 'candy' to match my linux username.

Super User

A superuser has special privlidges. I made candy a super user.

Step 3: Create Database

$ createdb candy

Create a database with the same name as the user.

Step 4: psql

$ psql

Welcome to the psql interface!

Step 5: Give role/user a password

To give your user a password:

ALTER USER username WITH PASSWORD 'new_password';

➼ ALTER USER We are going to change something about the user
➼ username Here we will put the name of the user we wish to change.
➼ WITH PASSWORD We are giving her a password
➼ 'new_password' Here we put the password in quotes.
➼ ; (semi-colon) Statements end with a semi-colon;


So, to give Candy the password 'candy':

ALTER USER candy WITH PASSWORD 'candy';

Step 6: Quit and go back to your Linux user account.

\q

Exit psql by typing '\q'

$ su candy

I switched back to my candy linux user account.





Featured Blog:



Follow Coding Commanders on:

YouTube

Facebook

Instagram

Twitter

Previous Lesson | Continue to Next Lesson