CYBERTEC Logo

PostgreSQL 9.3: new functionality

09.2013 / Category: / Tags:

PostgreSQL 9.3 has just been released and we have already received a lot of positive feedback for the new release. Many people are impressed by what has been achieved recently and are already eager to enjoy those new features. As always, the new release brings a great deal of new functionality and many improvements.

Everybody has their favorite new functionality. In my case these top features are:

  • Reduced shared memory consumption
  • Materialized views
  • Auto-updatable view
  • Support for event triggers
  • Writable FDWs

Reduced shared memory consumption

In recent years many newbies to PostgreSQL and Linux / UNIX have suffered from kernel side shared memory settings. Before PostgreSQL 9.3 all the I/O cache resided in shared memory. The problem here was that most Linux distros (and most other UNIX systems) restricted the use of shared memory to a fairly small amount of RAM.

Many users might be familiar with the following message:

I am glad to say that those messages are a thing of the past. This will significantly reduce the pain and newbies will have a better time getting started with PostgreSQL.

Materialized views

One thing many people have been asking for is materialized views. A materialized view is actually a cool thing to have. It allows people to store data in a pre-processed way. In fact, a materialized view is a database object storing the result of a query.

Here is an example:

We can turn this into a shiny materialized view storing the result of the query:

The materialized view can now be accessed inside your PostgreSQL database just like you would access any normal table:

Keep one thing in mind: A materialized view is read-only. There is no way to actually add a row to it. PostgreSQL will issue an error in case you try:

You can of course modify the underlying table – the materialized view will be unchanged, however:

To make sure that the materialized view is updated, you have to call REFRESH:

PostgreSQL will execute the query once again and update the content of the materialized view:

Materialized views are a pretty comfortable way to store pre-aggregated data.

Auto-Updatable views

Materialized views are not the only area in which PostgreSQL got some new features. “Normal” views also got a pretty nice facelift. PostgreSQL allows simple views to be updated directly. Previously you had to write a trigger so that a view could change its underlying tables. This was painful and if it was done for many views, it was even a lot of work to get this done. In PostgreSQL 9.3 “simple” views can be updated directly.

Here is how it works:

Our data is inserted into t_test directly through the view. Again, this reduces the amount of work for developers in many cases.

Support for event triggers

One more feature many people have been waiting for are so called “event triggers”. Up to now it was only possible to write triggers firing on INSERT / UPDATE / DELETE / TRUNCATE. With event triggers you can write a trigger firing on any event such as CREATE TABLE, ALTER TABLE and so on. Event triggers will be a REAL relief for many logical replication solutions such as Slony and Londiste because it will be possible to add newly created tables to replication automatically for the first time without having to add them manually.

Here is the syntax of CREATE EVENT TRIGGER:

As of 9.3 there is just one issue: Event triggers must be written in C, but I assume that this will change in the future.

Writable FDWs

One more major enhancement is the ability to actually INSERT data into a foreign table. Up to PostgreSQL 9.2 it was only possible to read a foreign table. To many users this was a serious issue because it limited the ability to use a foreign table just like a normal table.

Countless other improvements

Of course the features I have presented in this post are just a brief summary of the most important new features of PostgreSQL 9.3. There are countless more improvements in the code which help people to use PostgreSQL a lot more efficiently.

There is still more to come from PostgreSQL – stay tuned.

Comments are closed.

CYBERTEC Logo white
CYBERTEC PostgreSQL International GmbH
Römerstraße 19
2752 Wöllersdorf
Austria

+43 (0) 2622 93022-0
office@cybertec.at

Get the newest PostgreSQL Info & Tools


    This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.

    ©
    2024
    CYBERTEC PostgreSQL International GmbH
    phone-handsetmagnifiercrosscross-circle linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram