Experiment No.
4 Installation Of Database Software
Installing PostgreSQL
• Follow the instructions below to install and configure PostgreSQL:
Installation can be from binaries or from source.
Download a postgresql-14.0-1-windows-x64 application file online.
Install the application file by double click on postgresql-14.0-1-windows-x64 application
file.
Give UserName and Password and remember it.
It install all packages – SQL shell and pgAdmin 4
Administering PostgreSQL and Creating Users
Once you have set up PostgreSQL as detailed in an earlier page, you need to set up the
administrative password, and create users. This page explains how to do so.
Administration using the SQL shell: To administer the PostgreSQL database, perform the
following tasks:
1. Go to windows → All Programs → PostgreSQL 14 → SQL Shell(psql).
2. It opens a new SQL Shell command window.
Enter following things:
o Server [localhost] : localhost
o Database [postgres] : postgres
o Port [5432] : 5432
o Username [postgres] : postgres
o Password for user postgres: enter password whatever you assign at the time of
installation.
3. Type \ q to exit the SQL Shell(psql).
• Administrative tasks
1. Changing the password:
Type \password postgres in the PSQL database shell and enter a new password. In general
the command \password <username> can be used to change the password for <username>.
*DON'T FORGET THE ABOVE PASSWORD*; but if you do, follow the above steps
of logging into the postgres account to change the password.
2. Creating a new Database:
A default database called postgres is created when you install PostgreSQL. Create a new
database called dbms2010, using the command: o CREATE DATABASE dbms2010;
3. Connect to a database:
Run the below command. Once connected to a database, all schemas and tables are created
in that database.
o \c dbms2010
4. Creating Schemas and Users:
To create a schema and users in the database 'dbms2010', run the following commands:
1. \c dbms2010
2. CREATE USER user1 WITH PASSWORD 'user123'; (You can use any name and
password you wish.)
3. CREATE SCHEMA AUTHORIZATION user1;
(This creates a schema where the tables created by the user1 will be stored; the schema
will be named user1).
4. Perform steps 2 and 3 for each user you need to create in your resource center.
Connecting to PostgreSQL
You can connect to postgresql using using pgAdmin3
1. Go to windows → All Programs → PostgreSQL 14 →pgAdmin 4. You will be presented
with the pgAdmin 4 interface.
2. Click on File > "Add server" to open the "New server registration dialog".
• Enter the following information and click OK:
o Name: Can be any name (say 'dbserver')
o Host: localhost
▪ (if the database is on another computer, use its IP address here) 3. Port:
5432
▪ (this is the default port for PostgreSQL)
• Username: user1
▪ (or any other user name as appropriate; use "postgres" user only for admin
work, do NOT create tables or run queries using the postgres user) 5.
Password: user123
▪ (or whatever password you created for this user)
Steps 2 and 3 are to be done only on the first use of pgadmin 4. Subsequently, the database name
(eg. dbserver) can be double-clicked to connect to it.
In the 'Object browser', navigate to Servers > dbserver (localhost:5432) > Databases >
dbms2010 > Schemas > user1. This is necessary to run the queries in the specific schema. Open
the SQL query window by pressing <Ctrl>+E or through the "Tools > Query tool" menu item.In
the query window, you can type any SQL query and run it using F5 or by clicking the "Execute
query" toolbar button. You may have to first clear the contents of the window if there are any.
NOTE: If you are using a netbook, the add connection screen may be too big for your tiny screen.
In that case, follow the menu sequence File > Options, choose the preferences tab, go to font, and
change font size
Name-Anjali Ameetkumar Wadekar
Roll No.C-55
PRN-2324001109