| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 5 | <title>Store 'postgresql'</title> |
| 6 | <meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> |
| 7 | <link rel="home" href="index.html" title="Redland RDF Library Manual"> |
| 8 | <link rel="up" href="redland-storage-modules.html" title="Storage Modules"> |
| 9 | <link rel="prev" href="redland-storage-module-mysql.html" title="Store 'mysql'"> |
| 10 | <link rel="next" href="redland-storage-module-sqlite.html" title="Store 'sqlite'"> |
| 11 | <meta name="generator" content="GTK-Doc V1.18 (XML mode)"> |
| 12 | <link rel="stylesheet" href="style.css" type="text/css"> |
| 13 | </head> |
| 14 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 15 | <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"> |
| 16 | <td><a accesskey="p" href="redland-storage-module-mysql.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td> |
| 17 | <td><a accesskey="u" href="redland-storage-modules.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td> |
| 18 | <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td> |
| 19 | <th width="100%" align="center">Redland RDF Library Manual</th> |
| 20 | <td><a accesskey="n" href="redland-storage-module-sqlite.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td> |
| 21 | </tr></table> |
| 22 | <div class="section"> |
| 23 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 24 | <a name="redland-storage-module-postgresql"></a>Store 'postgresql'</h2></div></div></div> |
| 25 | <p>This module is based on the MySQL store and is compiled in when |
| 26 | PostgreSQL is available. This store provides storage using the |
| 27 | <a class="ulink" href="http://www.postgresql.org/" target="_top">PostgreSQL</a> |
| 28 | open source database including contexts. This store was added in |
| 29 | Redland 1.0.3.</p> |
| 30 | <p>There are several options required with the postgresql storage |
| 31 | in order to connect to the database. These are:</p> |
| 32 | <div class="itemizedlist"><ul class="itemizedlist" type="disc"> |
| 33 | <li class="listitem"><p><code class="literal">host</code> for the database server hostname</p></li> |
| 34 | <li class="listitem"><p><code class="literal">port</code> for the database server port (defaults to the Postgresql port 3306 if not given)</p></li> |
| 35 | <li class="listitem"><p><code class="literal">database</code> for the Postgresql database name (not the storage name)</p></li> |
| 36 | <li class="listitem"><p><code class="literal">user</code> for the database server user name</p></li> |
| 37 | <li class="listitem"><p><code class="literal">password</code> for the database server password</p></li> |
| 38 | <li class="listitem"><p><code class="literal">database</code> for the Postgresql database name (not the storage name)</p></li> |
| 39 | </ul></div> |
| 40 | <p>NOTE: Before Redland 1.0.5, the |
| 41 | parameter <code class="literal">dbname</code> had to be used instead |
| 42 | of <code class="literal">database</code> for the Postgresql database name.</p> |
| 43 | <p>NOTE: Take care exposing the password as for example, program |
| 44 | arguments or environment variables. The rdfproc utility can with |
| 45 | help this by reading the password from standard input. Inside |
| 46 | programs, one way to prevent storing the password in a string is to |
| 47 | construct a Redland hash of the storage options such as |
| 48 | via <code class="literal">librdf_hash_from_string</code> and use |
| 49 | <code class="literal">librdf_new_storage_with_options</code> to create a storage. |
| 50 | The rdfproc utility source code demonstrates this. |
| 51 | </p> |
| 52 | <p>The storage name parameter given to the storage constructor |
| 53 | <code class="literal">librdf_new_storage</code> is used inside the postgresql |
| 54 | store to allow multiple stores inside one PostgreSQL database |
| 55 | instance as parameterised with the above optiosn.</p> |
| 56 | <p>If boolean option <code class="literal">new</code> is given, any existing |
| 57 | PostgreSQL database named by the storage |
| 58 | option <code class="literal">database</code>, say |
| 59 | <span class="emphasis"><em>db</em></span> will be dropped and the appropriate new |
| 60 | tables created. The PostgreSQL database <span class="emphasis"><em>db</em></span> must |
| 61 | already exist, such as made with the PostgreSQL <code class="literal">create |
| 62 | database </code><span class="emphasis"><em>db</em></span> command and the |
| 63 | appropriate privileges set so that the user and password |
| 64 | work.</p> |
| 65 | <p>This store always provides contexts; the boolean storage option |
| 66 | <code class="literal">contexts</code> is not checked.</p> |
| 67 | <p>Examples:</p> |
| 68 | <pre class="programlisting"> |
| 69 | /* A new PostgreSQL store */ |
| 70 | storage=librdf_new_storage(world, "postgresql", "db1", |
| 71 | "new='yes',host='localhost',database='red',user='foo','password='bar'"); |
| 72 | |
| 73 | /* A different, existing PostgreSQL store db2 in the same database as above */ |
| 74 | storage=librdf_new_storage(world, "postgresql", "db2", |
| 75 | "host='localhost',database='red',user='foo','password='bar'"); |
| 76 | |
| 77 | /* An existing PostgreSQL store on a different database server */ |
| 78 | storage=librdf_new_storage(world, "postgresql", "db3", |
| 79 | "host='db.example.org',database='abc',user='baz','password='blah'"); |
| 80 | |
| 81 | /* Opening with an options hash */ |
| 82 | options=librdf_new_hash(world, NULL); |
| 83 | librdf_hash_from_string(options, |
| 84 | "host='db.example.org',database='abc',user='baz'"); |
| 85 | librdf_hash_put_strings(options, "password", user_password); |
| 86 | storage=librdf_new_storage_with_options(world, "postgresql", "db4", options); |
| 87 | </pre> |
| 88 | <p>In PHP:</p> |
| 89 | <pre class="programlisting"> |
| 90 | # An existing store |
| 91 | $storage=librdf_new_storage($world, 'postgresql', 'db4', |
| 92 | "host='127.0.0.1',database='xyz',user='foo',password='blah'"); |
| 93 | |
| 94 | </pre> |
| 95 | <p>Summary:</p> |
| 96 | <div class="itemizedlist"><ul class="itemizedlist" type="disc"> |
| 97 | <li class="listitem"><p>Persistent</p></li> |
| 98 | <li class="listitem"><p>Suitable for very large models</p></li> |
| 99 | <li class="listitem"><p>Indexed but not optimized</p></li> |
| 100 | <li class="listitem"><p>Smaller disk usage than BDB</p></li> |
| 101 | <li class="listitem"><p>Contexts always provided</p></li> |
| 102 | </ul></div> |
| 103 | </div> |
| 104 | <div class="footer"> |
| 105 | <hr> |
| 106 | Generated by GTK-Doc V1.18</div> |
| 107 | </body> |
| 108 | </html> |