# How to Install PostgreSQL on Ubuntu 20.04  Server

#### Install software certificates for a secure SSL connection   
    
`$ sudo apt install wget ca-certificates`   
  

![pgsql_1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648112334211/rSRJzNL9B.png)
   
   
#### Add it to apt-key management utility and create a new configuration file with an official PostgreSQL repository address          
   
`$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -`    
 
`$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'`     
   

![pgsql_2.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648112456765/B6-luP6G2.png)
     

![pgsql_3.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648112467673/jRHmlJg33.png)
    
    
#### Install PostgreSQL    
    
`$ sudo apt update`     
     

![pgsql_4.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648112549112/-h4Finv68.png)
     
  
`$ apt install postgresql postgresql-contrib`    
   

![pgsql_5.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648112594603/iyshIHYVQ.png)
    
  
#### Check PostgreSQL status   
`$ service postgresql status`    
   

![pgsql_6.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648112787123/522_nQ91j.png)
    
   
#### Command Line Tool   
   
A default admin user “postgres” is created by the default.  A “psql” command-line client tool is used to interact with the database engine.      
  
`$ sudo -u postgres psql`    

![pgsql_7.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648113009989/MeKQb-8Mg.png)
   
 PostgreSQL installation also creates a default database named “postgres” and connects you to it automatically when you first launch psql.    
  
#### Check the connection    
  
`$ \conninfo`  
  

![pgsql_8.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648113109279/_PRaN2jKG.png)
   
  If you want to see a list of all the databases that are available on a server, use \l command.    
   
`$  \l `   
   

![pgsql_9.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648113181526/6qX9V8GPh.png)
     
    
 list of all the users with their privileges use   
  
`$ \du` 
   

![pgsql_10.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648113245133/6Dt0f_X8s.png)
    
  
Since the default “postgres” user does not have a password, you should set it yourself.    
  
`$ \password postgres`    
   

![pgsql_11.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648113441457/xFB38IiZf.png)

