Difficulty: Intermediate
Estimated Time: 15 minutes

Basic Introduction to PGAdmin4

This class gives you a basic introduction to using PGAdmin4 - a GUI for working with your PostgreSQL database.

From the project site:

pgAdmin is the leading Open Source management tool for Postgres, the world’s most advanced Open Source database. pgAdmin 4 is designed to meet the needs of both novice and experienced Postgres users alike, providing a powerful graphical interface that simplifies the creation, maintenance and use of database objects.

In this scenario we will just get you started using the tool. We will cover topics such as :

  1. Connecting to a database
  2. Navigating in the interface
  3. Creating, editing, and executing some SQL
  4. Creating a table
  5. Creating and editing functions

We have already have spun up a PostgreSQL instance with a database. Inside that database we have created a spatially enabled table for storm event locations in the United States.

Here are the details on the database we are connecting to:

  1. Username: groot
  2. Password: password (same password for the postgres user as well)
  3. A database named: workshop

The credentials for PgAdmin4 are:

  1. username=admin
  2. password=password

    Let's get started

Final Notes

NOTE: All the programming langauges we used in these exercises are considered "trusted" by PostgreSQL. Trusted means the language does not give the developer access to the operating system file system and are much harder to do "bad things" with them. Because of this, functions written in trusted langauges can be written and used by non-superusers.

If we had done this class in, say Pl/Python, PostgreSQL would have prevented us from making functions since Python is an untrusted language. While we are not going to cover how to developer with an untrusted in this course, you need to be aware of this restriction.

I hope this scenario helped:

  1. Give you an idea how easy it is to get started with functions in PostgreSQL
  2. Get your hands dirty with some basic functions
  3. You understand how functions can help you produce better applications

The best way to get better at functions is to keep writing them and playing.
The container used in this class is available in Dockerhub. As long as you have Docker on your machine you can use the same version of PostgreSQL as the workshop. All the data from the workshop was intentionally chosen from public domain or permissive licenses so that you can use it for commercial and non-commercial purposes. Feel free to download it and play some more at your own pace on your own machine.

And with that, we are finished.

Basic Functions For Developers

Step 1 of 5

Connect To Your Database

Connecting to our Database

If you look at the second tab in our learning interface it says PgAdmin4. Go ahead and click that tab which should spawn a new browser window or tab. You may have to wait a few seconds while the PGAdmin4 interface gets rendered. You should now be able to login using username admin and password password.

First screen

You should be seeing a screen that looks like this:

Home Screen

This is the home page for PgAdmin4. Before we can do anything meaningful we need to connect to a PostgreSQL server. There are two ways to do this:

  1. Click on the "Add New Server" butting in the middle of the screen.
  2. Right click on the Servers icon in the top left of the left navigation panel.

Let's start by doing the right click option because it will give us more flexibility.

Right click options

Create Server

When you right click on the icon you should see a list of options. Go ahead and mouse over create. This will then show server group and server. If you are going to manage and interact with a lot of PostgreSQL servers then you might want to create server groups such as testing vs production. Server groups is just a logical organization in the PgAdmin interface.

In our case since we are only managing one server, go ahead and click server to bring up the new create server dialog.

Create Server Dialog

While there are quite a few boxes and tabs in this dialog, only a few of them are actually required to create a new server in PgAdmin.

First Tab

First Tab

On the general tab, the only field required is Name. This name represents the name YOU want to use to identify this PostgreSQL server in the PgAdmin interface. You could call it monkey if you want - it doesn't require any relation to a name in the real world.

For today's exercise let's name it "Workshop"

In the comment field you can put in some information about this server connection. The information can be brought up in the interface later and can help you remember facts about this server.

Once you are done filling in those fields go ahead and click on the second tab titled Connection.

Second Tab

This Connection tab contains most of the important information about your server.

Second Tab

Wrap Up

We just finished the basic skeleton of a function: declaration, function name, parameters, return type, code block, and language used. In our next exercise we will explore doing more with the function declaration and parameters.