Jump to: navigation, search
Postgresql elephant.png
Developer(s) PostgreSQL Global Development Group
Stable release 8.4.3 /
8.3.10 /
8.2.16 /
8.1.20 /
8.0.24 /
7.4.28 /
2010-03-15; 13 years ago
Written in C
Operating system Cross-platform
License PostgreSQL licence[1][2][3]

PostgreSQL, often simply Postgres, is an object-relational database management system (ORDBMS).[4] It is released under an MIT-style license and is thus free and open source software. As with many other open source programs, PostgreSQL is not controlled by any single company, but has a global community of developers and companies to develop it.



Functions allow blocks of code to be executed by the server. Although these blocks can be written in SQL, the lack of basic programming operations which existed prior to version 8.4, such as branching and looping, has driven the adoption of other languages inside of functions. Some of the languages can even execute inside of triggers. Functions in PostgreSQL can be written in the following languages:

PostgreSQL supports row-returning functions, where the output of the function is a set of values which can be treated much like a table within queries. Custom aggregates and window functions can also be defined.

Functions can be defined to execute with the privileges of either the caller or the user who defined the function. Functions are sometimes referred to as stored procedures, although there is a slight technical distinction between the two.


PostgreSQL includes built-in support for B+-tree, hash table, GiST and GiN indexes. In addition, user-defined index methods can be created, although this is quite an involved process. Indexes in PostgreSQL also support the following features:

  • Expression indexes can be created with an index of the result of an expression or function, instead of simply the value of a column.
  • Partial indexes, which only index part of a table, can be created by adding a WHERE clause to the end of the CREATE INDEX statement. This allows a smaller index to be created.
  • The planner is capable of using multiple indexes together to satisfy complex queries, using temporary in-memory bitmap index operations.


Triggers are events triggered by the action of SQL DML statements. For example, an INSERT statement might activate a trigger that checked if the values of the statement were valid. Most triggers are only activated by either INSERT or UPDATE statements.

Database triggers are fully supported and can be attached to tables but not to views. Views can have rules, though. Multiple triggers are fired in alphabetical order. In addition to calling functions written in the native PL/PgSQL, triggers can also invoke functions written in other languages like PL/Perl.


PostgreSQL manages concurrency through a system known as Multi-Version Concurrency Control (MVCC), which gives each user a "snapshot" of the database, allowing changes to be made without being visible to other users until a transaction is committed. This largely eliminates the need for read locks, and ensures the database maintains the ACID principles in an efficient manner.


Rules allow the "query tree" of an incoming query to be rewritten. One common usage is to implement views, including updatable views. Rules, or more properly, "Query Re-Write Rules", are attached to a table/class and "Re-Write" the incoming DML (select, insert, update, and/or delete) into 1 or more queries that either replace the original DML statement or execute in addition to it. Query Re-Write occurs after DML statement parsing, but, before query planning.

Data types

A wide variety of native data types are supported, including:

  • Variable length arrays (including text and composite types) up to 1GB in total storage size.
  • Arbitrary precision numerics
  • Geometric primitives
  • IPv4 and IPv6 addresses
  • CIDR blocks and MAC addresses
  • XML supporting Xpath queries (as of 8.3)
  • UUID (as of 8.3)

In addition, users can create their own data types which can usually be made fully indexable via PostgreSQL's GiST infrastructure. Examples of these are the geographic information system (GIS) data types from the PostGIS project for PostgreSQL.

User-defined objects

New types of almost all objects inside the database can be created, including:

  • Casts
  • Conversions
  • Data types
  • Domains
  • Functions, including aggregate functions
  • Indexes
  • Operators (existing ones can be overloaded)
  • Procedural languages


Tables can be set to inherit their characteristics from a "parent" table. Data in child tables will appear to exist in the parent tables, unless data is selected from the parent table using the ONLY keyword, i.e. select * from ONLY PARENT_TABLE. Adding a column in the parent table will cause that column to appear in the child table.

Inheritance can be used to implement table partitioning, using either triggers or rules to direct inserts to the parent table into the proper child tables.

This feature is not fully supported yet—in particular, table constraints are not currently inheritable. As of the 8.4 release, all check constraints and not-null constraints on a parent table are automatically inherited by its children. Other types of constraints (unique, primary key, and foreign key constraints) are not inherited.

Inheritance provides a way to map the features of generalization hierarchies depicted in Entity Relationship Diagrams (ERD) directly into the PostgreSQL database.

Other features

  • Referential integrity constraints including foreign key constraints, column constraints, and row checks
  • Views. Although views are by default not updateable, they can be made so by creating "insert", "update", and/or "delete" Query Re-Write Rules on the view.
  • Inner, outer (full, left and right), and cross joins
  • Sub-selects
    • Correlated sub-queries [5]
  • Transactions
  • Supports most of the major features of SQL:2008 standard [6]
  • Encrypted connections via SSL
  • Binary and textual large-object storage
  • Online backup
  • Domains
  • Tablespaces
  • Savepoints
  • Point-in-time recovery
  • Two-phase commit
  • TOAST (The Oversized-Attribute Storage Technique) is used to transparently store large table attributes (such as big MIME attachments or XML messages) in a separate area, with automatic compression.
  • Regular expressions [7]
  • Common table expressions
  • Embedded SQL is implemented using preprocessor. SQL code is first written embedded into C code. Then code is run through ECPG preprocessor, which replaces SQL with calls to code library. Then code can be compiled using C compiler. Embedding works also with C++ but it does not recognize all C++ constructs.


  • Performance wizard - included with any Postgres download from EnterpriseDB. Source code also available.
  • MySQL migration wizard - included with any Postgres download from EnterpriseDB. Source code also available.
  • Geographic objects via PostGIS. GPL.
  • Shortest-Path-Algorithms with pgRouting using PostGIS. GPL.
  • Full text search via Tsearch2 and OpenFTS. (As of version 8.3, Tsearch2 is included in core PostgreSQL)
  • Some synchronous multi-master derivatives or extensions exist, including
  • Several asynchronous master/slave replication packages, including
    • Londiste
    • Slony-I (same license as PostgreSQL)
    • Mammoth Replicator. (same license as PostgreSQL[8], formerly proprietary)
    • Bucardo (Simplified BSD license; also does master to master replication)
  • There are proxy (middleware) tools that enable replication, failover or load management and balancing for PostgreSQL:
    • PGPool-II.
    • Sequoia available for a number of different server besides PostgreSQL.


A number of companies offer proprietary tools for PostgreSQL. They often consist of a universal core that is adapted for various specific database products. These tools mostly share the administration features with the open source tools but offer improvements in data modeling, importing, exporting or reporting.


Further reading

External links