If complex data types or mul­ti­me­dia content have to be managed in addition to al­phanu­mer­ic content (e.g. letters, numbers, special char­ac­ters), classic re­la­tion­al database man­age­ment systems will quickly reach their limits. However, object-re­la­tion­al databases or database man­age­ment systems, which expand the tra­di­tion­al model with object-oriented ap­proach­es, provide the perfect answer to this problem: object-re­la­tion­al mapping enables objects to be stored in re­la­tion­al systems using ap­pli­ca­tions based on object-oriented pro­gram­ming languages. One of the most popular and oldest solutions in this context is the open source database, Post­greSQL, also known as Postgres.

What is Post­greSQL?

Post­greSQL has a 30-year de­vel­op­ment history. The origins of the object-re­la­tion­al database man­age­ment system (ORDBMS) can be traced back to the POSTGRES project from the Uni­ver­si­ty of Cal­i­for­nia at Berkeley. This began in 1986 under the lead­er­ship of Michael Stone­brak­er and was sponsored by the Defense Advanced Research Project Agency (DARPA) and the National Science Foun­da­tion (NSF), among others. In 1994, students Andrew Yu and Jolly Chen expanded the basic code to include an SQL in­ter­preter. This new and around 30-50% faster mod­i­fi­ca­tion was released as an open source solution under the name Postgres95 (under their own license, which is similar to the BDS and MIT licenses). Two years later, the database ap­pli­ca­tion with version 6.0 was given the name Post­greSQL, under which it is still known today.

Note

Besides the new name Post­gresSQL, the original name Postgres (now rarely written in capital letters anymore) is still used for the database system, probably due to the fact that it makes it easier to pronounce.

The POSTGRES project did valuable pi­o­neer­ing work and developed numerous concepts that only found their way into other (and mainly com­mer­cial) database systems much later. Post­greSQL is not only a SQL-compliant database, but also offers the following modern features:

  • Pos­si­bil­i­ty of complex queries
  • Foreign keys for linking data in two tables
  • Triggers that are au­to­mat­i­cal­ly triggered on input and check, confirm, change, delete, or elec­tive­ly use reference data
  • Updatable views
  • Com­pre­hen­sive trans­ac­tion concept
  • Multi-version con­cur­ren­cy control (MVCC) for efficient execution of si­mul­ta­ne­ous database access

Thanks to the free licensing, users can highly modify and extend Post­greSQL, adding new data types, functions, operators, indexing methods, or pro­ce­dur­al languages (pro­gram­ming languages for writing functions and triggers), for example.

Postgres: key data and system re­quire­ments

Post­greSQL’s flex­i­bil­i­ty is not only shown by its func­tion­al­i­ty, ex­pand­abil­i­ty, and adapt­abil­i­ty: the database also provides plenty of scope for software and hardware setup. Postgres is already included in most UNIX/Linux dis­tri­b­u­tions and has been delivered by Apple as a standard database since Mac OS X Lion (10.7). The only re­quire­ment is that a current “gmake version (3.80 or higher) has to be installed (already included in the finished binary files). Windows operating systems can also be selected as a platform for the system thanks to the cor­re­spond­ing in­stal­la­tion packages. The required computing power and storage capacity depend only on the size of the planned database system – the open source software itself only requires about 20 MB.

The following key data of the object-re­la­tion­al database shows that you are more limited by your own storage ca­pac­i­ties than by the limits of Post­greSQL in practice:

Maximum database size unlimited
Maximum table size 32 terabytes
Maximum size of data set 1.6 terabytes
Maximum field size 1 gigabyte
Maximum number of columns 250 to 1,600 (depending on data type)
Maximum number of rows unlimited
Maximum number of indexes unlimited

How does Post­greSQL work?

Postgres is based on the typical client-server model: The central server component called “post­mas­ter” manages all database files and all con­nec­tions that are es­tab­lished for com­mu­ni­ca­tion (input and output) with the database server. Users only need a suitable client program to establish the con­nec­tion, whereby the Post­greSQL software package with psql already has a native solution in­te­grat­ed for operation via the command line or the terminal. Al­ter­na­tive­ly, you can use different ap­pli­ca­tions with a graphical user interface such as pgAdmin or ph­pP­gAd­min, which can be op­tion­al­ly installed and used. With in­ter­ac­tive websites, the web server usually takes on the role of the client.

Tip

Many Linux dis­tri­b­u­tions include their own graphical Postgres client with pgAccess.

What projects is Post­greSQL suitable for?

As a proven and extremely flexible database man­age­ment system, Postgres is used in numerous in­dus­tries and scenarios. The object-re­la­tion­al database is a first-class basis for the safe operation of a wide variety of ap­pli­ca­tions. For example, the open source project is the perfect solution for online banking software, due to its in­te­grat­ed trans­ac­tion concept and support for MVCC (multi-version con­cur­ren­cy control: procedure for efficient per­for­mance of competing access). Analysis programs such as Matlab or R also work well with the database, which is why Post­greSQL is often used in com­bi­na­tion with these programs. In com­bi­na­tion with the extension PostGIS (which provides hundreds of functions for working with geodata), Postgres also impresses when it comes to working with spatial and ge­o­graph­i­cal data.

Post­greSQL is also in demand as a solution for web projects: The object-re­la­tion­al system works with various modern frame­works such as Django, Node.js or Ruby on Rails, and supports classic web languages such as PHP. Support for syn­chro­nous and asyn­chro­nous repli­ca­tion also makes it easy to dis­trib­ute the stored data across multiple servers for high re­silience and minimal access time to critical data.

Note

The useful support of JSON also makes Post­greSQL an excellent database solution for scaling NoSQL workloads.

How to install Post­greSQL

If you want to use Postgres for your project, you can install the database man­age­ment system yourself in a few steps without having to purchase a license or something similar. The download portal of the official Post­greSQL website offers binary files and links to the repos­i­to­ries of source packages for BSD, Linux, macOS, Solaris, and Windows, which can be installed and used free of charge under the open source license. Root rights are not required for this: simple ad­min­is­tra­tor rights are enough for execution. The following two sections show how Post­greSQL should be installed on Linux (Ubuntu 17.10) and Windows.

In­stalling Post­greSQL on Linux (Ubuntu 17.10)

Postgres’ APT repos­i­to­ry of­fi­cial­ly supports the LTS version of Ubuntu (from 14.04 onwards) as well as others such as Ubuntu 17.04. The source packages often work with other versions as well. However, the Post­greSQL team rec­om­mends using the most up-to-date LTS variant to ensure that users get the best possible long-term benefit from the database man­age­ment system. Since the packages are already included in the standard repos­i­to­ry on Ubuntu, you can easily install them with the package manager, APT.

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

Post­greSQL is installed using this command. The software au­to­mat­i­cal­ly creates a Linux user named “postgres” for database access. For security reasons, this should only be used for working with the database. It is also advisable to assign a password to this profile in the first step (since there isn’t one entered by default). All you have to do is enter the following command and then enter the password of your choice twice:

sudo passwd postgres

As well as the “postgres” Linux user, there is also a database user with the same name, which is needed for database ad­min­is­tra­tion and should also be protected with a strong password. This can be done by entering the following terminal commands (“new-password” is a place­hold­er for the desired password and must be replaced ac­cord­ing­ly):

su - postgres
psql -d template1 -c "ALTER USER postgres WITH PASSWORD 'neues-passwort';"

To check if the in­stal­la­tion was suc­cess­ful, you should create a database (here: testdb) with the “postgres” Linux account and manage it with the terminal client, psql:

su - postgres
createdb testdb
psql testdb

In the terminal you can see this output of the psql client shell, which can be operated with any SQL commands:

In­stalling Post­greSQL on Windows

In­stalling Postgres on Windows computers is easy, thanks to the in­ter­ac­tive installer certified by En­ter­priseDB. The free in­stal­la­tion assistant of the software man­u­fac­tur­er, which offers ad­di­tion­al tools as well as com­mer­cial support for Post­greSQL, is available to download from the company’s own website. Simply select the desired version of the database man­age­ment system and the target platform and then click on “DOWNLOAD NOW.

The down­loaded installer can be started by double-clicking. First of all, it installs the Microsoft compiler Visual C++, as long as it isn’t already installed on the system. Select the Post­greSQL location, then you have the option of excluding in­di­vid­ual com­po­nents of the in­stal­la­tion package from being installed. In any case, the Post­greSQL server and command line tools are required – the graphical client pgAdmin and the Stack Builder (for simple downloads and in­stalling ex­ten­sions) are not mandatory, but make it a lot easier to work with the database man­age­ment system.

If the storage location for the data was also specified, a password for the “Postgres“ database ad­min­is­tra­tor profile has not yet been assigned. You can keep the default port and lo­cal­iza­tion settings like this before finally starting the in­stal­la­tion in the last step.

After suc­cess­ful in­stal­la­tion, a con­nec­tion to the Post­greSQL server can be es­tab­lished in a few steps via the pgAdmin user interface (if installed). To do this, right-click on the con­fig­ured Postgres version in the server list and then click on “Connect Server.”

After entering the pre­vi­ous­ly assigned password for the “Postgres” ad­min­is­tra­tor account, the client initiates the con­nec­tion.

The ad­van­tages and dis­ad­van­tages of Post­greSQL at a glance

Ad­van­tages Dis­ad­van­tages
Open source Not available on all hosts by default
Highly ex­pand­able Ex­pand­able doc­u­men­ta­tion only available in English
Largely compliant with SQL standard Com­par­a­tive­ly low reading speed
Possible to process complex data types (e.g. ge­o­graph­i­cal data)  
Flexible full text search  
Creation of own functions, triggers, data types, etc. possible  
Good language support (Python, Java, Perl, PHP, C, C++, etc.)  
Supports JSON  
Cross-platform  
Go to Main Menu