You are on page 1of 16

Using pgAdmin

Using pgAdmin
A free database administration tool called pgAdmin is designed for PostgreSQL and available on our lab computers. It
provides both command-line and visual tools for administering the PostgreSQL databases. The following provides
basic instructions on how to use it to perform this week’s tutorial task.

Unfortunately, due to security restrictions, pgAdmin will only work on the campus wired network to access your
PostgreSQL database on our Computing server. It will not work with our Computing server from off-campus,
or via Wi-Fi on-campus. If you wish to work with your database off-campus or via Wi-Fi, you can use the Web-
based phppgadmin tool at http://computing.derby.ac.uk/phppgadmin by following the instructions in the
Using_phpPgAdmin.doc document.

Please read this document carefully and follow the instructions to create a user account on our Computing server if you
don’t have one, and to load the DEMOBLD.SQL database. Then do the exercises in the SQLPracticalExercises.doc
document.

1
Using pgAdmin

Step 0 – Creating an Account

Before you can work with a database on the Department of Electronics, Computing & Mathematics’ Linux server
(which is variously known as “the Computing server”, computing.derby.ac.uk, commerce3.derby.ac.uk, or just
“Commerce3”1) you’ll need an account. As long as you have a working unimail mail account, you can create an
account for yourself.

If you already have an account on Commerce3 and remember your password – perhaps because you followed the
instructions in the Using_phpPgAdmin document – please skip to Step 1.

Otherwise, go to http://computing.derby.ac.uk/accgen and follow the instructions to create your account, or to reset
your password if you already have an account and have forgotten it.

Your account details will be emailed to your unimail account and will look something like this:

Your commerce3.derby.ac.uk user name is st125125125 and your password is P3xT7dQ


You have a MySQL database st125125125 on localhost with user st125125125 and password 7rrACD2
You have a PostgreSQL database st125125125 on localhost with user st125125125 and password R745xtq

Obviously, you’ll have a different user name and passwords.

For these exercises, the important password is the one on the last line, the line that starts with “You have a
PostgreSQL database…”

Keep your passwords secret and safe. If you suspect anyone other than you knows any of your passwords, use the URL
above to reset your passwords and notify Dave Voorhis at d.voorhis@derby.ac.uk immediately.

You’ll need your user name and password for the following exercises. Please note that your user name and password
are case-sensitive.

1
The reason for this name has long been forgotten in the dim, distant mists of time. There used to be a commerce1, but
it’s gone now, and no one remembers whether there was ever a commerce2 or not.
2
Using pgAdmin

Step 1 – Using pgAdmin

The pgAdmin application is available via CloudPaging. If it isn’t already available in the CloudPaging player, use
AppsAnywhere to install it. Search for ‘pgadmin’ and launch it:

Once it starts up, you should see this:

3
Using pgAdmin

Close the yellow warning about a newer version being available.

4
Using pgAdmin

Step 2 – Connecting to your Database

You’ll need to connect to your PostgreSQL database on the commerce3 server. Click the “Add New Server” icon under
“Quick Links”. You should see this:

In the “Name” blank, put something memorable like “computing.derby.ac.uk”, though you can use any memorable
name you like. For example:

5
Using pgAdmin

Then click on the Connection tab to display the following:

6
Using pgAdmin

As shown above, in the “Host name/address” box, fill in ‘computing.derby.ac.uk’. Put your PostgreSQL account name
in the “Username” blank and your PostgreSQL password in the “Password” box.

Then click “Save”.

If the system fails to connect, please consult your tutor.

Do not ask the university technicians to help you with your database account or create an account for you! If
you’re having problems with your account, please email Dave Voorhis at d.voorhis@derby.ac.uk

7
Using pgAdmin

Step 3 – Accessing your database

Once you’ve successfully connected, you should see something like the following:

Click the expander (‘+’) symbol beside the “computing.derby.ac.uk” entry on the left. You should see a list of
databases like the following:

8
Using pgAdmin

There are a lot of databases!

You can see the names of all of them, but you can only effectively use your own, so you need to find its name. Scroll
down until you find it.

Please note that these are mainly student database accounts, so security is deliberately relaxed. Do not use your
database to store sensitive or private information!

Once you find the name of your database, click on it. You should see something like the following:

9
Using pgAdmin

10
Using pgAdmin

Step 4 – The command-line window

Click on the “Query Tool” from the “Tools” drop-down menu, as shown below:

You should see something like the following:

11
Using pgAdmin

In the example above, a simple query has been entered by the user. You can try entering the same query, if you like.

To execute a query, press the “lightning” icon, circled in red in the image below:

As shown above, when it completes it will announce its status in the Messages tab.

Queries that return data will show their output in the Data Output tab.

12
Using pgAdmin

Step 5 – Loading and Executing a SQL Script

Now we will attempt to load and execute the DEMOBLD.SQL script2.

It will create a number of tables, sequences, and a view that will be used in the SQL practical exercises.

If you have already done this step in the Using_phpPgAdmin document, you don’t need to do it again. Skip
straight to doing the exercises in the SQLPracticalExercises.doc document.

Download the DEMOBLD.SQL script from Course Resources and put it somewhere you can find it easily.

Click on the “load file” icon, circled in red below:

If you have done some typing in the SQL entry box, it will probably ask you to discard changes, as shown below. If so,
answer “Yes”:

2
Some of you will notice the distinctly American flavour of the sample data in the script. That’s because it’s based on
some classic Oracle Corporation (which is a USA-based international company) database examples and exercises
which are familiar to almost every database developer. Soon, you’ll be familiar with them too.
13
Using pgAdmin

Then you will almost certainly see a box that complains that there is no disk:

Press “Continue”. If it pops up the same error again, press “Continue” until you see the file dialog box:

14
Using pgAdmin

Use the file dialog box to load the DEMOBLD.SQL script. NOTE: You might have to type the full filename path
explicitly in the file name box, if the DEMOBLD.SQL file doesn’t show where you put it.

Once the file is loaded, it should look something like this:

See the red dot in front of “CREATE” in the first line of the file, as shown above?

If it appears in your query box, click beside it and delete the dot. If the red dot appears and you leave it in, the script
won’t work.

To run the script, click on the “lightning” icon to the right of the “No limit” drop-down combobox.

When it runs successfully, you should see output like the following:

15
Using pgAdmin

To clear the SQL entry box in preparation for running more queries, click on the edit drop-down list and select “Clear
Query Window”, as shown below:

Now do the exercises in the SQLPracticalExercises.doc document.

16

You might also like