Store 'postgresql'

This module is based on the MySQL store and is compiled in when PostgreSQL is available. This store provides storage using the PostgreSQL open source database including contexts. This store was added in Redland 1.0.3.

There are several options required with the postgresql storage in order to connect to the database. These are:

  • host for the database server hostname

  • port for the database server port (defaults to the Postgresql port 3306 if not given)

  • database for the Postgresql database name (not the storage name)

  • user for the database server user name

  • password for the database server password

  • database for the Postgresql database name (not the storage name)

NOTE: Before Redland 1.0.5, the parameter dbname had to be used instead of database for the Postgresql database name.

NOTE: Take care exposing the password as for example, program arguments or environment variables. The rdfproc utility can with help this by reading the password from standard input. Inside programs, one way to prevent storing the password in a string is to construct a Redland hash of the storage options such as via librdf_hash_from_string and use librdf_new_storage_with_options to create a storage. The rdfproc utility source code demonstrates this.

The storage name parameter given to the storage constructor librdf_new_storage is used inside the postgresql store to allow multiple stores inside one PostgreSQL database instance as parameterised with the above optiosn.

If boolean option new is given, any existing PostgreSQL database named by the storage option database, say db will be dropped and the appropriate new tables created. The PostgreSQL database db must already exist, such as made with the PostgreSQL create database db command and the appropriate privileges set so that the user and password work.

This store always provides contexts; the boolean storage option contexts is not checked.


  /* A new PostgreSQL store */
  storage=librdf_new_storage(world, "postgresql", "db1",

  /* A different, existing PostgreSQL store db2 in the same database as above */
  storage=librdf_new_storage(world, "postgresql", "db2",

  /* An existing PostgreSQL store on a different database server */
  storage=librdf_new_storage(world, "postgresql", "db3",

  /* Opening with an options hash */
  options=librdf_new_hash(world, NULL);
  librdf_hash_put_strings(options, "password", user_password);
  storage=librdf_new_storage_with_options(world, "postgresql", "db4", options);


  # An existing store
  $storage=librdf_new_storage($world, 'postgresql', 'db4', 


  • Persistent

  • Suitable for very large models

  • Indexed but not optimized

  • Smaller disk usage than BDB

  • Contexts always provided

Navigation: Redland Home Page

Copyright 2000-2014 Dave Beckett