## 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.

Examples:

      /* A new PostgreSQL store */
      storage=librdf_new_storage(world, "postgresql", "db1",
          "new='yes',host='localhost',database='red',user='foo','password='bar'");

      /* A different, existing PostgreSQL store db2 in the same database as above */
      storage=librdf_new_storage(world, "postgresql", "db2",
          "host='localhost',database='red',user='foo','password='bar'");

      /* An existing PostgreSQL store on a different database server */
      storage=librdf_new_storage(world, "postgresql", "db3",
          "host='db.example.org',database='abc',user='baz','password='blah'");

      /* Opening with an options hash */
      options=librdf_new_hash(world, NULL);
      librdf_hash_from_string(options,
          "host='db.example.org',database='abc',user='baz'");
      librdf_hash_put_strings(options, "password", user_password);
      storage=librdf_new_storage_with_options(world, "postgresql", "db4", options);

In PHP:

      # An existing store
      $storage=librdf_new_storage($world, 'postgresql', 'db4',
          "host='127.0.0.1',database='xyz',user='foo',password='blah'");

Summary:

- Persistent

- Suitable for very large models

- Indexed but not optimized

- Smaller disk usage than BDB

- Contexts always provided