Managing Postgres with PgAdmin GUI
General Overview
When you first connect you will have to set up the PgAdmin master password. This is separate from the Database password
It will also set up the default postgres database connection
The password that you have to enter, is the password that you have set up during the installation
Now you are connected to the database
Creating an the instance to connect in PgAdmin
Right Click Servers
Click Register --> Click Server
Under the
General
Tab provide the Name
Under the
Connection
Tab specifylocalhost
andpassword
Note: If the instance would run on AWS or other cloud provider, you would specify the IP or Domain Name to connect to under Hostname/address
Create a new Database
Go under Databases
Click Create --> Database
Add Database name (Usually good to be after the app name)
Note: If you go under the SQL tab, it will provide you with the SQL statement to create the database
Database has been created successfully
Create a Table
Connect to the Database
Click Schemas --> Public --> Tables
Right Click --> Create --> Table
Add Table Name under the
General
tab
We need to define a column as well under the
Columns
tab
Columns --> Click
+
--> Add Name --> Add DataType --> Think if data can be NULLRepeat with new column for how the
PRODUCTS
table should be defined
To see the differences between the Data Types in Postgres:
Example:
We have 3 types of INTEGER
integer
bigint
smallint
The main difference between these is the amount of bits that we have
The maximum number to which we go to is going to be much higher or smaller depending on which you use
There is an additional DataType called
serial
which will create our IDs in a logical order without specifying the ID every timeThis will increment by
+1
How a PRODUCTS
table should look logically:
Better example would be something like this:
Click save and you've created the table
Interacting with Table
To fetch all Data in table:
Right Click Table --> View/Edit Data --> All Rows
This also returns the SQL for the query
To Add Row:
Click on +
--> Add Data --> Commit
Adding a brand new column
We will take a look if the product is on sale
Right Click Table --> Properties
Create a new Row as before but add the constraint to take the default value as False (so not on sale)
Because we provided a default value, it has autocompleted the previous entries with the default value
Adding a Timestamp to the Table
Realistically you would need timestamps to the Table as well - This is best practice
However we don't want the application to be responsible with this
We do want Postgres to do this
How it should look like at the end:
Last updated