Difference between revisions of "PostgreSQL-Database/C2/Installation-of-PostgreSQL-in-Linux/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "'''Title of the script''': '''Installation of PostgreSQL in Linux ''' '''Author''': '''EduPyramids''' '''Keywords: '''PostgreSQL, pgAdmin, Database, psql, RDBMS, EduPyraids,...")
 
 
(One intermediate revision by the same user not shown)
Line 14: Line 14:
  
 
'''Title Slide'''
 
'''Title Slide'''
|| Welcome to the Spoken tutorial on '''Installation of PostgreSQL in Linux '''.
+
|| Welcome to the Spoken tutorial on '''Installation of PostgreSQL in Linux'''.
 
|-
 
|-
 
||'''Slide 2'''
 
||'''Slide 2'''
Line 59: Line 59:
  
  
This file is provided in the Code Files link of this tutorial page.
+
This file is provided in the '''Code Files''' link of this tutorial page.
 
|-
 
|-
 
|| '''Slide 6'''
 
|| '''Slide 6'''
Line 68: Line 68:
 
* It supports complex queries and large applications.
 
* It supports complex queries and large applications.
 
* Developers use it for secure, scalable data handling.
 
* Developers use it for secure, scalable data handling.
* It runs on''' Linux''',''' Windows '''and '''Mac OS'''.
+
* It runs on ''' Linux''',''' Windows '''and '''Mac OS'''.
  
 
|-
 
|-
Line 87: Line 87:
 
Enter the administrative password.
 
Enter the administrative password.
 
|| In the '''terminal''' window, type the following command and press '''Enter'''.
 
|| In the '''terminal''' window, type the following command and press '''Enter'''.
 
  
 
Enter the administrative password if prompted.
 
Enter the administrative password if prompted.
Line 111: Line 110:
 
To add the official '''Postgre S Q L A p t''' repository,
 
To add the official '''Postgre S Q L A p t''' repository,
  
Type the following command and press '''Enter'''.
+
type the following command and press '''Enter'''.
  
 
If prompted, type the admin password to authenticate.
 
If prompted, type the admin password to authenticate.
Line 127: Line 126:
 
This refreshes the package list and includes the new '''Postgre S Q L''' repository.
 
This refreshes the package list and includes the new '''Postgre S Q L''' repository.
  
Let us search '''PostgreSQL''' '''18 point 1''' Package.
+
Let us search '''PostgreSQL 18 point 1''' Package.
  
Type: '''a p t space search space postgre s q l hyphen 18 '''and press''' Enter.'''
+
Type '''a p t space search space postgre s q l hyphen 18 '''and press''' Enter'''.
 
|-
 
|-
 
|| '''Type: sudo apt install postgresql-18'''
 
|| '''Type: sudo apt install postgresql-18'''
|| Now let’s Install '''Postgre S Q L''' '''18 point 1'''
+
|| Now let’s Install '''Postgre S Q L 18 point 1'''.
  
 
For that type: '''sudo space a p t space install space postgre s q l hyphen 18 '''and press''' Enter.'''
 
For that type: '''sudo space a p t space install space postgre s q l hyphen 18 '''and press''' Enter.'''
Line 149: Line 148:
  
 
'''psql (PostgreSQL) 18.1 '''
 
'''psql (PostgreSQL) 18.1 '''
|| Let’s verify the version of Postgres.
+
|| Let’s verify the version of '''Postgres'''.
  
'''Type: p s q l space hyphen hyphen version '''and''' '''press''' Enter.'''
+
'''Type: p s q l space hyphen hyphen version''' and press''' Enter.'''
  
 
We can see that '''Postgre S Q L '''18 point 1 is the installed version.
 
We can see that '''Postgre S Q L '''18 point 1 is the installed version.
 
|-  
 
|-  
 
|| Press '''Ctrl + L''' to clear the screen.  
 
|| Press '''Ctrl + L''' to clear the screen.  
|| Press '''control '''and '''L '''keys to clear the screen.  
+
|| Press '''control''' and '''L '''keys to clear the screen.  
 
|-
 
|-
 
|| Highlight the line:
 
|| Highlight the line:
Line 175: Line 174:
 
|| Enter your system password if prompted.  
 
|| Enter your system password if prompted.  
  
Notice that the prompt has changed to '''postgres''' equal to hash.  
+
Notice that the prompt has changed to '''postgres equal to hash'''.  
 
|-
 
|-
 
||'''Type: \password postgres'''
 
||'''Type: \password postgres'''
 
|| At the prompt,  
 
|| At the prompt,  
  
type backslash '''password space postgres '''and press '''Enter'''.
+
type '''backslash password space postgres''' and press '''Enter'''.
 
|-
 
|-
 
|| Type the password  
 
|| Type the password  
Line 199: Line 198:
 
|-
 
|-
 
||Type: '''Postgres=#> select version(); '''
 
||Type: '''Postgres=#> select version(); '''
|| Now type, '''select space version(); ''' and press '''Enter'''.  
+
|| Now type, '''select space version();''' and press '''Enter'''.  
  
 
Please remember to add a semicolon at the end of each statement.
 
Please remember to add a semicolon at the end of each statement.
Line 211: Line 210:
 
|| Press '''q''' key to exit.  
 
|| Press '''q''' key to exit.  
 
|-
 
|-
||
+
||Cursor on the terminal.
 
|| Now let us see how to disconnect from the server.  
 
|| Now let us see how to disconnect from the server.  
 
|-
 
|-
Line 217: Line 216:
  
 
Point to the $ prompt
 
Point to the $ prompt
|| Type ''' back slash q''' and press '''Enter''' to disconnect from the server.
+
|| Type '''back slash q''' and press '''Enter''' to disconnect from the server.
  
 
Notice that we are back at the command prompt of the terminal.  
 
Notice that we are back at the command prompt of the terminal.  
 
|-
 
|-
||  
+
|| Cursor on terminal.
 
|| Please note that we require a server connection to work with '''PostgreSQL'''.
 
|| Please note that we require a server connection to work with '''PostgreSQL'''.
  
Line 232: Line 231:
 
|| '''Psql''' is an interactive '''terminal''' program provided by '''PostgreSQL'''.
 
|| '''Psql''' is an interactive '''terminal''' program provided by '''PostgreSQL'''.
  
We can execute '''SQL''' statements, manage '''database objects '''using the '''psql''' tool.
+
We can execute '''SQL''' statements, manage '''database objects''' using the '''psql''' tool.
  
 
|-
 
|-
Line 240: Line 239:
 
|| Let us connect to a database using the pgAdmin 4 GUI application.  
 
|| Let us connect to a database using the pgAdmin 4 GUI application.  
  
We can interact with '''PostgreSQL database server '''through this interface.
+
We can interact with '''PostgreSQL database server''' through this interface.
  
 
|-
 
|-
Line 251: Line 250:
 
|| For this, type this command and press '''Enter''' to connect to the server.
 
|| For this, type this command and press '''Enter''' to connect to the server.
  
'''-h '''is the hostname or IP of the local server.  
+
'''-h ''' is the hostname or IP of the local server.  
 
|-
 
|-
 
|| Enter the password for postgres user.  
 
|| Enter the password for postgres user.  
  
 
'''Type password:''' '''postgres'''
 
'''Type password:''' '''postgres'''
|| Enter the password for postgres user which you have set after installation.
+
|| Enter the password for '''postgres''' user which you have set after installation.
 
|-
 
|-
 
||Prompt changes to '''Postgres=#'''  
 
||Prompt changes to '''Postgres=#'''  
|| We can see the prompt changes to '''Postgres'''. Press '''Ctrl + L''' to clear the screen.  
+
|| We can see the prompt changes to '''Postgres'''.  
 +
 
 +
Press '''Ctrl + L''' to clear the screen.  
 
|-
 
|-
 
||
 
||
Line 265: Line 266:
 
|-
 
|-
 
|| '''Type: Select current_user, now(); '''Highlight the output  
 
|| '''Type: Select current_user, now(); '''Highlight the output  
|| Type, '''select current_user, now(); '''and press '''Enter.'''
+
|| Type, '''select current_user, now();''' and press '''Enter.'''
  
 
We can see the user name and current date as output.
 
We can see the user name and current date as output.
Line 282: Line 283:
  
 
Press''' q''' to Exit.
 
Press''' q''' to Exit.
|| We can see the below database names that are available in PostgreSQL server by default.  
+
|| We can see the below database names that are available in '''PostgreSQL server''' by default.  
  
 
At the colon prompt press''' q''' to Exit.
 
At the colon prompt press''' q''' to Exit.
Line 291: Line 292:
  
 
Highlight the message.
 
Highlight the message.
|| To change a database, I will type, '''\c postgres;''' and press '''Enter.'''
+
|| To change a database, I will type, '''\c postgres;''' and press '''Enter'''.
  
Then type the postgres password.  
+
Then type the '''postgres''' password.  
  
We can see a message saying ‘You are now connected to database “postgres” as user “postgres”
+
We can see a message saying '''You are now connected to database “postgres” as user “postgres”'''.
 
|-
 
|-
 
||
 
||
Line 313: Line 314:
  
 
(copy paste both the commands together) and press '''Enter.'''
 
(copy paste both the commands together) and press '''Enter.'''
|| let’s first, update our system packages. Type:
+
|| let’s first, update our system packages.  
  
'''sudo apt update '''and press '''Enter.'''Enter the administrative password if prompted.
+
Type:
 +
 
 +
'''sudo apt update''' and press '''Enter.
 +
 
 +
Enter the administrative password if prompted.
  
 
'''type sudo apt install curl ca-certificates gnupg -y''' and press '''Enter'''.
 
'''type sudo apt install curl ca-certificates gnupg -y''' and press '''Enter'''.
Line 327: Line 332:
  
  
|| Next, we will add the '''pgAdmin''' repository key. Type the following command:
+
|| Next, we will add the '''pgAdmin''' repository key.  
 +
 
 +
Type the following command.
  
 
This command downloads and stores the repository key securely on your system.
 
This command downloads and stores the repository key securely on your system.
Line 348: Line 355:
 
|| After adding the repository, update the package list again.  
 
|| After adding the repository, update the package list again.  
  
Type: '''sudo apt update'''
+
Type: '''sudo apt update'''.
  
  
This refreshes the list and includes pgAdmin packages.
+
This refreshes the list and includes '''pgAdmin''' packages.
 
|-
 
|-
 
|| '''Type: sudo apt install pgadmin4 -y'''
 
|| '''Type: sudo apt install pgadmin4 -y'''
Line 368: Line 375:
 
|| To launch the '''pgAdmin4''',  
 
|| To launch the '''pgAdmin4''',  
  
Go to Show Apps, and search '''pgAdmin4''' and click on it.
+
Go to '''Show Apps''', and search '''pgAdmin4''' and click on it.
  
  
Line 393: Line 400:
  
 
'''Thank you'''
 
'''Thank you'''
|| This Spoken Tutorial is brought to you by EduPyramids Educational Services Private limited SINE IIT Bombay.
+
|| This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited, SINE, IIT Bombay.
  
  

Latest revision as of 11:19, 6 February 2026

Title of the script: Installation of PostgreSQL in Linux

Author: EduPyramids

Keywords: PostgreSQL, pgAdmin, Database, psql, RDBMS, EduPyraids, video tutorial.


Visual Cue Narration
Slide 1

Title Slide

Welcome to the Spoken tutorial on Installation of PostgreSQL in Linux.
Slide 2

Learning Objectives

In this tutorial we will learn to,
  • Install PostgreSQL in Linux
  • Connect to PostgreSQL database
  • Set password for the database and
  • Install pgAdmin 4
Slide 3

System Requirements

To record this tutorial, I am using
  • Ubuntu 24 point 04 L T S and
  • A working internet connection.


Slide 4

Pre-requisites

https://EduPyramids.org

To follow this tutorial,
  • Learners should be familiar with Linux terminal.
  • For the pre-requisite PostgreSQL tutorials, please visit this website.


Slide 5

Code Files

The following code file is required to practice this tutorial.

  1. ipl-commands.txt

This file is provided in the code files link of this tutorial page.

The following code file is required to practice this tutorial.


This file is provided in the Code Files link of this tutorial page.

Slide 6

What is PostgreSQL?

  • PostgreSQL is a powerful, open-source relational database system.
  • It supports complex queries and large applications.
  • Developers use it for secure, scalable data handling.
  • It runs on Linux, Windows and Mac OS.
Open and show the ipl-commands.txt file. I will copy and paste the commands from this text document on the terminal.
Let’s first see how to install PostgreSQL on Linux.
Press CTRL + Alt + T keys simultaneously. Press control, ALT and T keys to open the terminal.
Type:sudo apt update && sudo apt upgrade -y

press Enter.


Enter the administrative password.

In the terminal window, type the following command and press Enter.

Enter the administrative password if prompted.

This command updates the system and installs any pending upgrades.

This may take some time.

Type:

sudo apt install -y curl ca-certificates

curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgresql-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/postgresql-archive-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list

(copy paste the entire block of code together)

PostgreSQL 18.1 is not available in Ubuntu’s default repositories.

So, we need to add the official Postgre S Q L repository.

To add the official Postgre S Q L A p t repository,

type the following command and press Enter.

If prompted, type the admin password to authenticate.

This will give us access to newer PostgreSQL versions like 18 point 1.

Type: clear and press Enter. Type clear and press Enter to clear the terminal screen.
Type: sudo apt update and press Enter

Type: apt search postgresql-18

Type: sudo space a p t space update and press Enter.

This refreshes the package list and includes the new Postgre S Q L repository.

Let us search PostgreSQL 18 point 1 Package.

Type a p t space search space postgre s q l hyphen 18 and press Enter.

Type: sudo apt install postgresql-18 Now let’s Install Postgre S Q L 18 point 1.

For that type: sudo space a p t space install space postgre s q l hyphen 18 and press Enter.

A prompt, Do you want to continue? is displayed.

Type y and press Enter to continue.

This may take sometime.

The installation is now successfully completed.

Type: psql --version

Highlight the version psql

psql (PostgreSQL) 18.1

Let’s verify the version of Postgres.

Type: p s q l space hyphen hyphen version and press Enter.

We can see that Postgre S Q L 18 point 1 is the installed version.

Press Ctrl + L to clear the screen. Press control and L keys to clear the screen.
Highlight the line:

Adding user postgres to group ssl-cert

By default, a user account called postgres is created during installation.

But the password is not set for this user account.

Type:sudo -u postgres psql postgres To set the password, type the command and press Enter.
Enter the system password

Point to the change in the prompt

postgres=#

Enter your system password if prompted.

Notice that the prompt has changed to postgres equal to hash.

Type: \password postgres At the prompt,

type backslash password space postgres and press Enter.

Type the password


Password: postgres

You will be prompted to set a new password for the Postgres user.

I will type the password as postgres and press Enter.

You can type a password of your choice.

Re-type the password : postgres Let us type the same password one more time.
Please remember this password for future use.
Type: Postgres=#> select version(); Now type, select space version(); and press Enter.

Please remember to add a semicolon at the end of each statement.

Highlight the Version The terminal now displays the installed PostgreSQL version.

This indicates that we have successfully installed PostgreSQL.

Press 'q' Key to exit Press q key to exit.
Cursor on the terminal. Now let us see how to disconnect from the server.
Type:' \q and press Enter

Point to the $ prompt

Type back slash q and press Enter to disconnect from the server.

Notice that we are back at the command prompt of the terminal.

Cursor on terminal. Please note that we require a server connection to work with PostgreSQL.
Slide 7

Connect to PostgreSQL database using psql

pgadmin-image.png

Psql is an interactive terminal program provided by PostgreSQL.

We can execute SQL statements, manage database objects using the psql tool.

Slide 8

Connect to PostgreSQL database using pgAdmin4

Let us connect to a database using the pgAdmin 4 GUI application.

We can interact with PostgreSQL database server through this interface.

Let us reconnect to the postgreSQL database using the terminal.
Type:

sudo psql -U postgres -h localhost -W and press Enter.

For this, type this command and press Enter to connect to the server.

-h is the hostname or IP of the local server.

Enter the password for postgres user.

Type password: postgres

Enter the password for postgres user which you have set after installation.
Prompt changes to Postgres=# We can see the prompt changes to Postgres.

Press Ctrl + L to clear the screen.

Let us verify the PostgreSQL database and whether the server has been started by a simple query.
Type: Select current_user, now(); Highlight the output Type, select current_user, now(); and press Enter.

We can see the user name and current date as output.

During installation, some sample databases are created automatically.

Let us have a look at them.

Type: \list and press Enter. Type backslash list and press Enter.
Highlight the available databases


Press q to Exit.

We can see the below database names that are available in PostgreSQL server by default.

At the colon prompt press q to Exit.

Type: \c postgres;

Type password: postgres

Highlight the message.

To change a database, I will type, \c postgres; and press Enter.

Then type the postgres password.

We can see a message saying You are now connected to database “postgres” as user “postgres”.

We can create our own database and tables as per our requirement.

All the database commands can be executed from the command line.

Type: \q Type \q to disconnect from the server and clear the screen.
Now let us see how to install PgAdmin.
Type: sudo apt update press Enter.

Type: sudo apt install curl ca-certificates gnupg -y

(copy paste both the commands together) and press Enter.

let’s first, update our system packages.

Type:

sudo apt update and press Enter.

Enter the administrative password if prompted.

type sudo apt install curl ca-certificates gnupg -y and press Enter.

This installs the required tools, including curl, certificate support, and GnuPG.

Type:


curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/pgadmin-keyring.gpg


Next, we will add the pgAdmin repository key.

Type the following command.

This command downloads and stores the repository key securely on your system.

If you are prompted to enter a new file name, please enter the file name as: pgfile.gpg.

Otherwise continue with the next step.

Type: sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/pgadmin-keyring.gpg] https://

ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list'

Now, add the official pgAdmin repository by typing this code.

This allows Ubuntu to install the latest version of pgAdmin4.

Enter the administrative password if prompted.

Type: sudo apt update After adding the repository, update the package list again.

Type: sudo apt update.


This refreshes the list and includes pgAdmin packages.

Type: sudo apt install pgadmin4 -y Now install pgAdmin 4 by typing:

sudo apt install pgadmin4 -y and press Enter.

This installs both the desktop and web versions of pgAdmin4.

Go to the left button and click on Show Apps.

Go to search and type pgAdmin4 and click on the icon.


Point the cursor to the opened application.

To launch the pgAdmin4,

Go to Show Apps, and search pgAdmin4 and click on it.


The pgAdmin4 application opens.

With this we come to the end of this tutorial.
Slide 9

Summary


In this tutorial we learned to,

  • Install PostgreSQL in Linux
  • Connect to PostgreSQL database
  • Set password for the database and
  • Install pgAdmin4


Let us summarize.
Slide 10

Thank you

This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited, SINE, IIT Bombay.


Thank you for joining

Contributors and Content Editors

Madhurig