🎯On this module we’ll discover learn how to set up postgreSQL in your laptop computer/PC and the additionally the widespread methods used to connect with postgres database.
This module is the very first step in the direction of our PostgreSQL journey.
Sit again, Calm down, and comply with the steps.
INSTALLATION
PostgreSQL might be put in from any web browser offered you could have a steady web connection.
Comply with the steps to put in PostgreSQL:
- Obtain from https://www.postgresql.org/download/windows/
- Run installer (EXE) from EDB.
- Click on Subsequent, select elements (choose pgAdmin).
- Set password for “postgres” person.
- Select port (default is
5432
). - End set up.
- Launch pgAdmin or use SQL Shell (psql)
Yesss you probably did it! PostgreSQL is efficiently put in in your system.
POSTGRES DATABASE & CONNECTING TO POSTGRES DATABASE
🔸Postgres database
Connecting to the Postgres database is the primary, vital and crucial step to be carried out in your venture .
Connecting to the Postgres databases lets you use the elements and privilages offered by PostgreSQL. It lets you:
- Ship queries (e.g., SELECT, INSERT, UPDATE)
- Create/handle databases and tables
- Learn/write information
- Management entry and settings
Postgres database additionally acts as a bridge of communication between your app/software( pgAdmin, psql, python and so on.) and the postgres database server.
For instance, the under command is used to connect with postgreSQL by way of psql
psql -U postgres -d dvdrental -h localhost -p 5432
This command tells PostgreSQL:
“Hey, I’m the person
postgres
, attempting to connect with the databasedvdrental
on my native machine (localhost
) by way of port5432
. Please let me in.”
🔸Methods to Hook up with postgres databases
Now let’s see the 4 widespread methods which we use to connect with a postgres database.
1. Utilizing psql (Command Line Software)
bash
psql -U postgres -d your_database_name -h localhost -p 5432
-U postgres
: username (default ispostgres
)-d your_database_name
: your DB title (e.g.,dvdrental
)-h localhost
: host (default is native)-p 5432
: port (default PostgreSQL port)
You’ll be prompted for a password.
2. From SQL Shell (psql) on Home windows
- Open SQL Shell (psql)
- Enter:
- Server:
localhost
- Database:
your_database_name
- Port:
5432
- Username:
postgres
- Password: [enter the password]
- You’ll get the
your_database_name=#
immediate
3. Utilizing pgAdmin (GUI Software)
- Open pgAdmin
- Proper-click on Servers → Register → Server
- Fill in:
- Title: any title
- Host:
localhost
- Username:
postgres
- Password: your password
4. Click on Save and join
4. Programmatically (e.g Python)
Utilizing psycopg2
:
python
import psycopg2
conn = psycopg2.join(
dbname="your_database_name",
person="postgres",
password="your_password",
host="localhost",
port="5432"
)
print("Linked efficiently")
psycopg (usually pronounced “sigh-co-pg”) is a widespread PostgreSQL adapter for Python. It allows you to to:
- Hook up with a PostgreSQL database
- Ship SQL queries
- Retrieve information from the database
- Carry out insert/replace/delete operations
These are the favored methods by which you’ll hook up with a postgres database and begin your postgreSQL journey with me.
🏁Abstract:
On this module we coated learn how to set up PostgreSQL and the way to connect with a postgres databases to begin working.
Blissful Studying!!🥇🎀
Keep tuned for additional classes.