]> begriffs open source - ai-pg/blob - full-docs/html/lo.html
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / html / lo.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>F.21. lo — manage large objects</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="isn.html" title="F.20. isn — data types for international standard numbers (ISBN, EAN, UPC, etc.)" /><link rel="next" href="ltree.html" title="F.22. ltree — hierarchical tree-like data type" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">F.21. lo — manage large objects</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="isn.html" title="F.20. isn — data types for international standard numbers (ISBN, EAN, UPC, etc.)">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules and Extensions">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules and Extensions</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="ltree.html" title="F.22. ltree — hierarchical tree-like data type">Next</a></td></tr></table><hr /></div><div class="sect1" id="LO"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.21. lo — manage large objects <a href="#LO" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="lo.html#LO-RATIONALE">F.21.1. Rationale</a></span></dt><dt><span class="sect2"><a href="lo.html#LO-HOW-TO-USE">F.21.2. How to Use It</a></span></dt><dt><span class="sect2"><a href="lo.html#LO-LIMITATIONS">F.21.3. Limitations</a></span></dt><dt><span class="sect2"><a href="lo.html#LO-AUTHOR">F.21.4. Author</a></span></dt></dl></div><a id="id-1.11.7.31.2" class="indexterm"></a><p>
3   The <code class="filename">lo</code> module provides support for managing Large Objects
4   (also called LOs or BLOBs).  This includes a data type <code class="type">lo</code>
5   and a trigger <code class="function">lo_manage</code>.
6  </p><p>
7   This module is considered <span class="quote">“<span class="quote">trusted</span>”</span>, that is, it can be
8   installed by non-superusers who have <code class="literal">CREATE</code> privilege
9   on the current database.
10  </p><div class="sect2" id="LO-RATIONALE"><div class="titlepage"><div><div><h3 class="title">F.21.1. Rationale <a href="#LO-RATIONALE" class="id_link">#</a></h3></div></div></div><p>
11    One of the problems with the JDBC driver (and this affects the ODBC driver
12    also), is that the specification assumes that references to BLOBs (Binary
13    Large OBjects) are stored within a table, and if that entry is changed, the
14    associated BLOB is deleted from the database.
15   </p><p>
16    As <span class="productname">PostgreSQL</span> stands, this doesn't occur.  Large objects
17    are treated as objects in their own right; a table entry can reference a
18    large object by OID, but there can be multiple table entries referencing
19    the same large object OID, so the system doesn't delete the large object
20    just because you change or remove one such entry.
21   </p><p>
22    Now this is fine for <span class="productname">PostgreSQL</span>-specific applications, but
23    standard code using JDBC or ODBC won't delete the objects, resulting in
24    orphan objects — objects that are not referenced by anything, and
25    simply occupy disk space.
26   </p><p>
27    The <code class="filename">lo</code> module allows fixing this by attaching a trigger
28    to tables that contain LO reference columns.  The trigger essentially just
29    does a <code class="function">lo_unlink</code> whenever you delete or modify a value
30    referencing a large object.  When you use this trigger, you are assuming
31    that there is only one database reference to any large object that is
32    referenced in a trigger-controlled column!
33   </p><p>
34    The module also provides a data type <code class="type">lo</code>, which is really just
35    a <a class="glossterm" href="glossary.html#GLOSSARY-DOMAIN"><em class="glossterm"><a class="glossterm" href="glossary.html#GLOSSARY-DOMAIN" title="Domain">domain</a></em></a> over
36    the <code class="type">oid</code> type.  This is useful for differentiating
37    database columns that hold large object references from those that are
38    OIDs of other things.  You don't have to use the <code class="type">lo</code> type to
39    use the trigger, but it may be convenient to use it to keep track of which
40    columns in your database represent large objects that you are managing with
41    the trigger.  It is also rumored that the ODBC driver gets confused if you
42    don't use <code class="type">lo</code> for BLOB columns.
43   </p></div><div class="sect2" id="LO-HOW-TO-USE"><div class="titlepage"><div><div><h3 class="title">F.21.2. How to Use It <a href="#LO-HOW-TO-USE" class="id_link">#</a></h3></div></div></div><p>
44    Here's a simple example of usage:
45   </p><pre class="programlisting">
46 CREATE TABLE image (title text, raster lo);
47
48 CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON image
49     FOR EACH ROW EXECUTE FUNCTION lo_manage(raster);
50 </pre><p>
51    For each column that will contain unique references to large objects,
52    create a <code class="literal">BEFORE UPDATE OR DELETE</code> trigger, and give the column
53    name as the sole trigger argument.  You can also restrict the trigger
54    to only execute on updates to the column by using <code class="literal">BEFORE UPDATE
55    OF</code> <em class="replaceable"><code>column_name</code></em>.
56    If you need multiple <code class="type">lo</code>
57    columns in the same table, create a separate trigger for each one,
58    remembering to give a different name to each trigger on the same table.
59   </p></div><div class="sect2" id="LO-LIMITATIONS"><div class="titlepage"><div><div><h3 class="title">F.21.3. Limitations <a href="#LO-LIMITATIONS" class="id_link">#</a></h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
60      Dropping a table will still orphan any objects it contains, as the trigger
61      is not executed.  You can avoid this by preceding the <code class="command">DROP
62      TABLE</code> with <code class="command">DELETE FROM <em class="replaceable"><code>table</code></em></code>.
63     </p><p>
64      <code class="command">TRUNCATE</code> has the same hazard.
65     </p><p>
66      If you already have, or suspect you have, orphaned large objects, see the
67      <a class="xref" href="vacuumlo.html" title="vacuumlo"><span class="refentrytitle"><span class="application">vacuumlo</span></span></a> module to help
68      you clean them up.  It's a good idea to run <span class="application">vacuumlo</span>
69      occasionally as a back-stop to the <code class="function">lo_manage</code> trigger.
70     </p></li><li class="listitem"><p>
71      Some frontends may create their own tables, and will not create the
72      associated trigger(s).  Also, users may not remember (or know) to create
73      the triggers.
74     </p></li></ul></div></div><div class="sect2" id="LO-AUTHOR"><div class="titlepage"><div><div><h3 class="title">F.21.4. Author <a href="#LO-AUTHOR" class="id_link">#</a></h3></div></div></div><p>
75    Peter Mount <code class="email">&lt;<a class="email" href="mailto:peter@retep.org.uk">peter@retep.org.uk</a>&gt;</code>
76   </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="isn.html" title="F.20. isn — data types for international standard numbers (ISBN, EAN, UPC, etc.)">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules and Extensions">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ltree.html" title="F.22. ltree — hierarchical tree-like data type">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.20. isn — data types for international standard numbers (ISBN, EAN, UPC, etc.) </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> F.22. ltree — hierarchical tree-like data type</td></tr></table></div></body></html>