You are here
PostgreSQL teaching and research databases
What PostgreSQL resources are available?
The school maintains two PostgreSQL servers, one for teaching and one for research. Staff and students can be granted access to either server as appropriate.
Generally there is no limit on research database use, but where consumption of resources becomes detrimental to other users of the server we may request that you source dedicated server hardware.
What versions are installed?
On DICE desktops and servers we usually carry two versions of PostgreSQL, one older version as maintained by our upstream Scientific Linux distribution, and a newer version maintained for use by servers and clients connecting to those servers. You can see which versions are available with something like:
$ ls /usr/bin/psql* /usr/bin/psql /usr/bin/psql95 $ psql --version psql (PostgreSQL) 9.2.15 $ psql95 --version psql (PostgreSQL) 9.5.1
note that while clients are usually compatible with servers of different versions, a warning is given:
$ psql -h pgteach WARNING: psql version 9.2, server version 9.3. Some psql features might not work. SSL connection (cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256) Type "help" for help.
and it is usually best to use the matching version. Indeed, tools such as
and features like psql's tab-completion functionality will not function at all unless a matching version (e.g.
) is used.
How do I get a PostgreSQL account / database?
For most students and teaching users this is entirely automatic. You will receive an account if you are taking any courses which requires one. Once you drop this course, your access will be suspended and, ultimately, any stored data removed (unless you request otherwise). You can check if you have an account by following the instructions below. If you do not have an account but feel you are entitled to one, please get in touch with support noting any course or supervisor details you think are relevant.
If you are a member of staff and would like an account, you may request one using the support form. Please state whether the account is to be used for teaching or research, and if it is to be shared with anybody.
How long can I keep my account?
If you are an undergraduate student, and have been granted a postgresql database as part of a course you are taking, your account and database will be made available in time for your coursework, and removed when it ends. If you wish to retain your account for longer than this, please contact support.
How do I access my database?
From any DICE machine (except certain research group servers), simply type the following:
psql -h pgteach
psql -h pgresearch
You will be connected to your database on the database server. If you have been given access to a named database (for example a shared group database) then you may access it by specifying the name of the database at the shell:
psql -h pgresearch databasename
If you are not on a DICE machine, the only recommended connection method is to use SSH to connect to a DICE machine, and then to use psql.
While attempting to connect to your database you may receive the following error:
psql: krb5_sendauth: Ticket expired
This is most likely because you have been logged in for a long time, or perhaps left your computer locked overnight. The solution is simply to issue the following command at a terminal:
You will be prompted for your DICE password.
A similar error can be found if you clear out the contents of /tmp on your machine:
psql: pg_krb5_init: krb5_cc_get_principal: No credentials cache found
This can be avoided by not deleting files named /tmp/krb5cc_*, and is solved by the renc procedure described above.
If you have any other problems, feel free to contact support. Copy or write the error message into the form if possible.
Can I install my own extensions?
No, but we will be able to install some extensions on your behalf. Generally we should be able to add any of the standard "contrib" extensions on a per-account basis. We might also grant permission to install some third-party extensions where we're confident that they will not be detrimental to the server. Extensions won't typically be installed for students unless needed for a course or project.
Can I use PostGIS?
Yes, PostGIS is a good example of a well-supported third-party extension. We will install this on request.
Are there any catches with third-party extensions?
The continued operation and compatibility of third-party extensions can't be guaranteed across major database upgrades (which, typically, happen annually at most). If we encounter problems with third-party extensions on a shared server we may have to arrange alternative hosting with you.
How do I use my database with scripts or other applications?
Your regular database access is granted using Kerberos; this means that, while using PSQL, you will not need to enter your password to access databases. Non-interactive Kerberos authentication is not supported for this service. For this reason you also have the ability to set a password for scripting purposes.
If you have not set a password, your account will have have none. This denies all password attempts. To create a password, follow the instructions for resetting your password below.
Why is my script's SSL connection breaking?
Sorry, but at present, SSL is only supported over interactive psql sessions. You will have to use a regular, unsecured connection, unless you are on a known DICE web server.
Exceptions have been made for a number of web servers, including homepages.inf, so that both SSL and non-SSL connections will work.
You can force PHP not to use SSL by adding "sslmode=disable" to your list of pg_connect options, for example using PHP:
<?php $dbconn = pg_connect ("host=$server dbname=$db user=$username password=$password sslmode=disable") >
(Thanks to neilb for the tip)
If you are using the interactive psql client in a script, setting the
$PGSSLMODE environment variable to 'disable' before running psql will have a similar effect.
I'm using a shared database. How can I give access to another user?
You can use the SQL
REVOKE commands to give access to other users. You must do this on each table to which you want to grant (or revoke) access. You can check who has permission to access your tables using the postgresql
PostgreSQL provides documentation on all of the above: a good starting point might be the GRANT command.
myuser=> \z Access privileges Schema | Name | Type | Access privileges --------+-------------+-------+------------------- public | foo | table | myuser=> GRANT INSERT, DELETE, UPDATE, SELECT ON foo TO another; GRANT myuser=> \z Access privileges Schema | Name | Type | Access privileges --------+-------------+-------+------------------------- public | foo | table | another=arwd/myuser
Note that in this example
myuser has implicit access to the database: it's the owner.
I am trying to empty a table but it is taking ages. Should I just keep trying until the database server breaks?
This shouldn't happen, but massive
DELETE FROM ... statements can take ages due to a quirk of the combination of PostgreSQL version and file system used on DICE servers.
It will help you (and please Support) greatly if you empty very large tables in a more efficient way:
myuser=> TRUNCATE TABLE tablename
But it would be wise to read the postgresql documentation on the TRUNCATE command and to please make sure you have a copy of any important data before deciding to TRUNCATE it.
I left my scripting password on a post-it note in a lab/at a conference. How can I change it?
Note your password is your responsibility, and should be secret. Don't write it down.
Most users can change their own passwords in postgres. (note the quotes in the commands below; they are important)
- Log in to your account on
pgresearchfrom any desktop DICE machine. You will not be required to enter a password.
- Now change your main account password to match:
myuser=> ALTER ROLE username WITH password 'new password here';
Alternatively, if you have no Kerberos access to your account, and no password, support can reset the password on your behalf. Be sure to change it (using the above) as soon as you have received the new password.
I've forgotten my password, and lost the post-it note. How can I reset it?
Your password is not stored in accessible form anywhere, but you don't need to know your password to change it. Simply reset it as above.
I'm still stuck. How can I get help?
Please visit the Informatics support form. Ensure you have read all relevant FAQs before continuing.