gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
7.3KB

  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.20. lo</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 V1.79.1" /><link rel="prev" href="isn.html" title="F.19. isn" /><link rel="next" href="ltree.html" title="F.21. ltree" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">F.20. lo</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="isn.html" title="F.19. isn">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="ltree.html" title="F.21. ltree">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="LO"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.20. lo</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="lo.html#id-1.11.7.29.4">F.20.1. Rationale</a></span></dt><dt><span class="sect2"><a href="lo.html#id-1.11.7.29.5">F.20.2. How to Use It</a></span></dt><dt><span class="sect2"><a href="lo.html#id-1.11.7.29.6">F.20.3. Limitations</a></span></dt><dt><span class="sect2"><a href="lo.html#id-1.11.7.29.7">F.20.4. Author</a></span></dt></dl></div><a id="id-1.11.7.29.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><div class="sect2" id="id-1.11.7.29.4"><div class="titlepage"><div><div><h3 class="title">F.20.1. Rationale</h3></div></div></div><p>
  7. One of the problems with the JDBC driver (and this affects the ODBC driver
  8. also), is that the specification assumes that references to BLOBs (Binary
  9. Large OBjects) are stored within a table, and if that entry is changed, the
  10. associated BLOB is deleted from the database.
  11. </p><p>
  12. As <span class="productname">PostgreSQL</span> stands, this doesn't occur. Large objects
  13. are treated as objects in their own right; a table entry can reference a
  14. large object by OID, but there can be multiple table entries referencing
  15. the same large object OID, so the system doesn't delete the large object
  16. just because you change or remove one such entry.
  17. </p><p>
  18. Now this is fine for <span class="productname">PostgreSQL</span>-specific applications, but
  19. standard code using JDBC or ODBC won't delete the objects, resulting in
  20. orphan objects — objects that are not referenced by anything, and
  21. simply occupy disk space.
  22. </p><p>
  23. The <code class="filename">lo</code> module allows fixing this by attaching a trigger
  24. to tables that contain LO reference columns. The trigger essentially just
  25. does a <code class="function">lo_unlink</code> whenever you delete or modify a value
  26. referencing a large object. When you use this trigger, you are assuming
  27. that there is only one database reference to any large object that is
  28. referenced in a trigger-controlled column!
  29. </p><p>
  30. The module also provides a data type <code class="type">lo</code>, which is really just
  31. a domain of the <code class="type">oid</code> type. This is useful for differentiating
  32. database columns that hold large object references from those that are
  33. OIDs of other things. You don't have to use the <code class="type">lo</code> type to
  34. use the trigger, but it may be convenient to use it to keep track of which
  35. columns in your database represent large objects that you are managing with
  36. the trigger. It is also rumored that the ODBC driver gets confused if you
  37. don't use <code class="type">lo</code> for BLOB columns.
  38. </p></div><div class="sect2" id="id-1.11.7.29.5"><div class="titlepage"><div><div><h3 class="title">F.20.2. How to Use It</h3></div></div></div><p>
  39. Here's a simple example of usage:
  40. </p><pre class="programlisting">
  41. CREATE TABLE image (title text, raster lo);
  42. CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON image
  43. FOR EACH ROW EXECUTE FUNCTION lo_manage(raster);
  44. </pre><p>
  45. For each column that will contain unique references to large objects,
  46. create a <code class="literal">BEFORE UPDATE OR DELETE</code> trigger, and give the column
  47. name as the sole trigger argument. You can also restrict the trigger
  48. to only execute on updates to the column by using <code class="literal">BEFORE UPDATE
  49. OF</code> <em class="replaceable"><code>column_name</code></em>.
  50. If you need multiple <code class="type">lo</code>
  51. columns in the same table, create a separate trigger for each one,
  52. remembering to give a different name to each trigger on the same table.
  53. </p></div><div class="sect2" id="id-1.11.7.29.6"><div class="titlepage"><div><div><h3 class="title">F.20.3. Limitations</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  54. Dropping a table will still orphan any objects it contains, as the trigger
  55. is not executed. You can avoid this by preceding the <code class="command">DROP
  56. TABLE</code> with <code class="command">DELETE FROM <em class="replaceable"><code>table</code></em></code>.
  57. </p><p>
  58. <code class="command">TRUNCATE</code> has the same hazard.
  59. </p><p>
  60. If you already have, or suspect you have, orphaned large objects, see the
  61. <a class="xref" href="vacuumlo.html" title="vacuumlo"><span class="refentrytitle"><span class="application">vacuumlo</span></span></a> module to help
  62. you clean them up. It's a good idea to run <span class="application">vacuumlo</span>
  63. occasionally as a back-stop to the <code class="function">lo_manage</code> trigger.
  64. </p></li><li class="listitem"><p>
  65. Some frontends may create their own tables, and will not create the
  66. associated trigger(s). Also, users may not remember (or know) to create
  67. the triggers.
  68. </p></li></ul></div></div><div class="sect2" id="id-1.11.7.29.7"><div class="titlepage"><div><div><h3 class="title">F.20.4. Author</h3></div></div></div><p>
  69. Peter Mount <code class="email">&lt;<a class="email" href="mailto:peter@retep.org.uk">peter@retep.org.uk</a>&gt;</code>
  70. </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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ltree.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.19. isn </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> F.21. ltree</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1