Managing Postgres with PgAdmin GUI
Last updated
Last updated
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
Right Click Servers
Click Register --> Click Server
Under the General
Tab provide the Name
Under the Connection
Tab specify localhost
and password
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
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
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 NULL
Repeat with new column for how the PRODUCTS
table should be defined
To see the differences between the Data Types in Postgres:
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 time
This 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
Right Click Table --> View/Edit Data --> All Rows
This also returns the SQL for the query
Click on +
--> Add Data --> Commit
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
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: