Session 2.3: Installing and using PostgreSQL (Postgres) - [Pre Lab]
1. To install PostgreSQL, go to the download page, and choose the version that fits your operating system.
2. After downloading the installer, run it.
3. During the installation, select the superuser password (try not to forget it, otherwise, you’ll not be able to connect to the database).
Note: I will be using postgres
as the username and the password in the code I will share.
4. Leave the port as it is "5432", and choose the default for the rest.
5. Uncheck the stack builder when the installation is finished, then, click finish.
6. Open the pgAdmin tool.
7. You will be asked to enter your password.
8. Expand the Servers, then, expand the Databases and you should see available databases.
9. You can create a database, by right-clicking on Databases, then, Create -> Database
. Choose "esi2023" as a name for your Database, and you can see that the superuser (postgres) is used as an owner by default.
Note: I will be using esi2023
as the name of the database in the code I will share.
10. Click on the "Save" button to create your Database, and you should be able to see it by expanding the databases.
11. To create a table, expand your database, expand Schemas, and expand "public". Navigate until you see Tables.
12. Right-click on tables, then, create. Choose a name for your table, and do not select a Tablespace.
13. You can specify the columns of your table by clicking on the column tab, then, press on the plus sign, choose the name of the column, its data type, and whether it is a primary key and can/cannot be null. When done, click on save and the table will be created.
Note: character varying is a good choice for containing string variables.
14. You can check the newly created table by expanding the Tables.
Note: I will briefly describe the SQL commands we are using in the lecture, but a good SQL Tutorial can be found at: https://www.w3schools.com/sql/.
16. If you want to insert data into your table, right-click on your table, then, Script -> insert SCRIPT. Insert some data (records) in the table to use it while connecting to the database, as shown in the figure.
Note: Use a single quotation when entering a string (character varying).
17. You can check the content of your table by querying it in the Query editor.