Slide 1
Most trusted JOB oriented professional program
DevOps Certified Professional (DCP)

Take your first step into the world of DevOps with this course, which will help you to learn about the methodologies and tools used to develop, deploy, and operate high-quality software.

Slide 2
DevOps to DevSecOps – Learn the evolution
DevSecOps Certified Professional (DSOCP)

Learn to automate security into a fast-paced DevOps environment using various open-source tools and scripts.

Slide 2
Get certified in the new tech skill to rule the industry
Site Reliability Engineering (SRE) Certified Professional

A method of measuring and achieving reliability through engineering and operations work – developed by Google to manage services.

Slide 2
Master the art of DevOps
Master in DevOps Engineering (MDE)

Get enrolled for the most advanced and only course in the WORLD which can make you an expert and proficient Architect in DevOps, DevSecOps and Site Reliability Engineering (SRE) principles together.

Slide 2
Gain expertise and certified yourself
Azure DevOps Solutions Expert

Learn about the DevOps services available on Azure and how you can use them to make your workflow more efficient.

Slide 3
Learn and get certified
AWS Certified DevOps Professional

Learn about the DevOps services offered by AWS and how you can use them to make your workflow more efficient.

previous arrow
next arrow

postgresql Installation and Configuration Tutorial Guide

Spread the Knowledge

How To Install and Use PostgreSQL on Ubuntu?

Step 1 — Installing PostgreSQL


$ sudo apt update
$ sudo apt install postgresql postgresql-contrib
$ sudo systemctl start postgresql.service

Step 2 — Using PostgreSQL Roles and Databases

The installation procedure created a user account called postgres that is associated with the default Postgres role. In order to use Postgres, you can log into that account.


Switch over to the postgres account on your server by typing:

$ sudo -i -u postgres

You can now access a Postgres prompt immediately by typing:
$ psql

This will log you into the PostgreSQL prompt, and from here you are free to interact with the database management system right away.

Exit out of the PostgreSQL prompt by typing:
> \q
This will bring you back to the postgres Linux command prompt.

Accessing a Postgres Prompt Without Switching Accounts
$ sudo -u postgres psql
> \q

Step 3 — Creating a New Role

Currently, you just have the postgres role configured within the database. You can create new roles from the command line with the createrole command. The –interactive flag will prompt you for the name of the new role and also ask whether it should have superuser permissions.


Currently, you just have the postgres role configured within the database. You can create new roles from the command line with the createrole command. 

The --interactive flag will prompt you for the name of the new role and also ask whether it should have superuser permissions.

If you are logged in as the postgres account, you can create a new user by typing:
$ createuser --interactive

If, instead, you prefer to use sudo for each command without switching from your normal account, type:
$ sudo -u postgres createuser --interactive
Output
Enter name of role to add: sammy
Shall the new role be a superuser? (y/n) y

Step 4 — Creating a New Database

Another assumption that the Postgres authentication system makes by default is that for any role used to log in, that role will have a database with the same name which it can access.

This means that, if the user you created in the last section is called sammy, that role will attempt to connect to a database which is also called “sammy” by default. You can create the appropriate database with the createdb command.

If you are logged in as the postgres account, you would type something like:
$ createdb sammy.

If, instead, you prefer to use sudo for each command without switching from your normal account, you would type:
$ sudo -u postgres createdb sammy

Step 5 — Opening a Postgres Prompt with the New Role

To log in with ident based authentication, you’ll need a Linux user with the same name as your Postgres role and database.

If you don’t have a matching Linux user available, you can create one with the adduser command. You will have to do this from your non-root account with sudo privileges (meaning, not logged in as the postgres user):


$ sudo adduser sammy

Once this new account is available, you can either switch over and connect to the database by typing:

$ sudo -i -u sammy
psql
Or, you can do this inline:
$ sudo -u sammy psql

If you want your user to connect to a different database, you can do so by specifying the database like this:

psql -d postgres
Once logged in, you can get check your current connection information by typing:

\conninfo
Output
You are connected to database "sammy" as user "sammy" via socket in "/var/run/postgresql" at port "5432".
This is useful if you are connecting to non-default databases or with non-default users.

Rajesh Kumar
Latest posts by Rajesh Kumar (see all)
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x