Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
lo.html76 linesDownload Raw Back to 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.22. 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.21. isn — data types for international standard numbers (ISBN, EAN, UPC, etc.)" /><link rel="next" href="ltree.html" title="F.23. 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.22. lo — manage large objects</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="isn.html" title="F.21. 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 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="ltree.html" title="F.23. 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.22. 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.22.1. Rationale</a></span></dt><dt><span class="sect2"><a href="lo.html#LO-HOW-TO-USE">F.22.2. How to Use It</a></span></dt><dt><span class="sect2"><a href="lo.html#LO-LIMITATIONS">F.22.3. Limitations</a></span></dt><dt><span class="sect2"><a href="lo.html#LO-AUTHOR">F.22.4. Author</a></span></dt></dl></div><a id="id-1.11.7.32.2" class="indexterm"></a><p>3  The <code class="filename">lo</code> module provides support for managing Large Objects4  (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 be8  installed by non-superusers who have <code class="literal">CREATE</code> privilege9  on the current database.10 </p><div class="sect2" id="LO-RATIONALE"><div class="titlepage"><div><div><h3 class="title">F.22.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 driver12   also), is that the specification assumes that references to BLOBs (Binary13   Large OBjects) are stored within a table, and if that entry is changed, the14   associated BLOB is deleted from the database.15  </p><p>16   As <span class="productname">PostgreSQL</span> stands, this doesn't occur.  Large objects17   are treated as objects in their own right; a table entry can reference a18   large object by OID, but there can be multiple table entries referencing19   the same large object OID, so the system doesn't delete the large object20   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, but23   standard code using JDBC or ODBC won't delete the objects, resulting in24   orphan objects — objects that are not referenced by anything, and25   simply occupy disk space.26  </p><p>27   The <code class="filename">lo</code> module allows fixing this by attaching a trigger28   to tables that contain LO reference columns.  The trigger essentially just29   does a <code class="function">lo_unlink</code> whenever you delete or modify a value30   referencing a large object.  When you use this trigger, you are assuming31   that there is only one database reference to any large object that is32   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 just35   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> over36   the <code class="type">oid</code> type.  This is useful for differentiating37   database columns that hold large object references from those that are38   OIDs of other things.  You don't have to use the <code class="type">lo</code> type to39   use the trigger, but it may be convenient to use it to keep track of which40   columns in your database represent large objects that you are managing with41   the trigger.  It is also rumored that the ODBC driver gets confused if you42   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.22.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">46CREATE TABLE image (title text, raster lo);47 48CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON image49    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 column53   name as the sole trigger argument.  You can also restrict the trigger54   to only execute on updates to the column by using <code class="literal">BEFORE UPDATE55   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.22.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 trigger61     is not executed.  You can avoid this by preceding the <code class="command">DROP62     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 the67     <a class="xref" href="vacuumlo.html" title="vacuumlo"><span class="refentrytitle"><span class="application">vacuumlo</span></span></a> module to help68     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 the72     associated trigger(s).  Also, users may not remember (or know) to create73     the triggers.74    </p></li></ul></div></div><div class="sect2" id="LO-AUTHOR"><div class="titlepage"><div><div><h3 class="title">F.22.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.21. 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.23. ltree — hierarchical tree-like data type">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.21. 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 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> F.23. ltree — hierarchical tree-like data type</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai