This file is indexed.

/usr/share/doc/python3-postgresql/html/copyman.html is in python3-postgresql 1.1.0-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<!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>Copy Management &mdash; py-postgresql 1.1.0 documentation</title>
    
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.1.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="py-postgresql 1.1.0 documentation" href="index.html" />
    <link rel="next" title="Notification Management" href="notifyman.html" />
    <link rel="prev" title="Driver" href="driver.html" />
 
<link rel="stylesheet" href="_static/unsuck.css" type="text/css" />

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="notifyman.html" title="Notification Management"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="driver.html" title="Driver"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">py-postgresql 1.1.0 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="copy-management">
<span id="pg-copyman"></span><h1>Copy Management<a class="headerlink" href="#copy-management" title="Permalink to this headline"></a></h1>
<p>The <cite>postgresql.copyman</cite> module provides a way to quickly move COPY data coming
from one connection to many connections. Alternatively, it can be sourced
by arbitrary iterators and target arbitrary callables.</p>
<p>Statement execution methods offer a way for running COPY operations
with iterators, but the cost of allocating objects for each row is too
significant for transferring gigabytes of COPY data from one connection to
another. The interfaces available on statement objects are primarily intended to
be used when transferring COPY data to and from arbitrary Python
objects.</p>
<p>Direct connection-to-connection COPY operations can be performed using the
high-level <cite>postgresql.copyman.transfer</cite> function:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">postgresql</span> <span class="kn">import</span> <span class="n">copyman</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">send_stmt</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="s">&quot;COPY (SELECT i FROM generate_series(1, 1000000) AS g(i)) TO STDOUT&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">destination</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;CREATE TEMP TABLE loading_table (i int8)&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">receive_stmt</span> <span class="o">=</span> <span class="n">destination</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="s">&quot;COPY loading_table FROM STDIN&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">total_rows</span><span class="p">,</span> <span class="n">total_bytes</span> <span class="o">=</span> <span class="n">copyman</span><span class="o">.</span><span class="n">transfer</span><span class="p">(</span><span class="n">send_stmt</span><span class="p">,</span> <span class="n">receive_stmt</span><span class="p">)</span>
</pre></div>
</div>
<p>However, if more control is needed, the <cite>postgresql.copyman.CopyManager</cite> class
should be used directly.</p>
<div class="section" id="copy-managers">
<h2>Copy Managers<a class="headerlink" href="#copy-managers" title="Permalink to this headline"></a></h2>
<p>The <cite>postgresql.copyman.CopyManager</cite> class manages the Producer and the
Receivers involved in a COPY operation. Normally,
<cite>postgresql.copyman.StatementProducer</cite> and
<cite>postgresql.copyman.StatementReceiver</cite> instances. Naturally, a Producer is the
object that produces the COPY data to be given to the Manager&#8217;s Receivers.</p>
<p>Using a Manager directly means that there is a need for more control over
the operation. The Manager is both a context manager and an iterator. The
context manager interfaces handle initialization and finalization of the COPY
state, and the iterator provides an event loop emitting information about the
amount of COPY data transferred this cycle. Normal usage takes the form:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">postgresql</span> <span class="kn">import</span> <span class="n">copyman</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">send_stmt</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="s">&quot;COPY (SELECT i FROM generate_series(1, 1000000) AS g(i)) TO STDOUT&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">destination</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;CREATE TEMP TABLE loading_table (i int8)&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">receive_stmt</span> <span class="o">=</span> <span class="n">destination</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="s">&quot;COPY loading_table FROM STDIN&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">producer</span> <span class="o">=</span> <span class="n">copyman</span><span class="o">.</span><span class="n">StatementProducer</span><span class="p">(</span><span class="n">send_stmt</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">receiver</span> <span class="o">=</span> <span class="n">copyman</span><span class="o">.</span><span class="n">StatementReceiver</span><span class="p">(</span><span class="n">receive_stmt</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">source</span><span class="o">.</span><span class="n">xact</span><span class="p">(),</span> <span class="n">destination</span><span class="o">.</span><span class="n">xact</span><span class="p">():</span>
<span class="gp">... </span> <span class="k">with</span> <span class="n">copyman</span><span class="o">.</span><span class="n">CopyManager</span><span class="p">(</span><span class="n">producer</span><span class="p">,</span> <span class="n">receiver</span><span class="p">)</span> <span class="k">as</span> <span class="n">copy</span><span class="p">:</span>
<span class="gp">... </span>  <span class="k">for</span> <span class="n">num_messages</span><span class="p">,</span> <span class="n">num_bytes</span> <span class="ow">in</span> <span class="n">copy</span><span class="p">:</span>
<span class="gp">... </span>   <span class="n">update_rate</span><span class="p">(</span><span class="n">num_bytes</span><span class="p">)</span>
</pre></div>
</div>
<p>As an alternative to a for-loop inside a with-statement block, the <cite>run</cite> method
can be called to perform the operation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">source</span><span class="o">.</span><span class="n">xact</span><span class="p">(),</span> <span class="n">destination</span><span class="o">.</span><span class="n">xact</span><span class="p">():</span>
<span class="gp">... </span> <span class="n">copyman</span><span class="o">.</span><span class="n">CopyManager</span><span class="p">(</span><span class="n">producer</span><span class="p">,</span> <span class="n">receiver</span><span class="p">)</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
</pre></div>
</div>
<p>However, there is little benefit beyond using the high-level
<cite>postgresql.copyman.transfer</cite> function.</p>
<div class="section" id="manager-interface-points">
<h3>Manager Interface Points<a class="headerlink" href="#manager-interface-points" title="Permalink to this headline"></a></h3>
<p>Primarily, the <cite>postgresql.copyman.CopyManager</cite> provides a context manager and
an iterator for controlling the COPY operation.</p>
<blockquote>
<div><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">CopyManager.run()</span></tt></dt>
<dd>Perform the entire COPY operation.</dd>
<dt><tt class="docutils literal"><span class="pre">CopyManager.__enter__()</span></tt></dt>
<dd>Start the COPY operation. Connections taking part in the COPY should <strong>not</strong>
be used until <tt class="docutils literal"><span class="pre">__exit__</span></tt> is ran.</dd>
<dt><tt class="docutils literal"><span class="pre">CopyManager.__exit__(typ,</span> <span class="pre">val,</span> <span class="pre">tb)</span></tt></dt>
<dd>Finish the COPY operation. Fails in the case of an incomplete
COPY, or an untrapped exception. Either returns <cite>None</cite> or raises the generalized
exception, <cite>postgresql.copyman.CopyFail</cite>.</dd>
<dt><tt class="docutils literal"><span class="pre">CopyManager.__iter__()</span></tt></dt>
<dd>Returns the CopyManager instance.</dd>
<dt><tt class="docutils literal"><span class="pre">CopyManager.__next__()</span></tt></dt>
<dd><p class="first">Transfer the next chunk of COPY data to the receivers. Yields a tuple
consisting of the number of messages and bytes transferred,
<tt class="docutils literal"><span class="pre">(num_messages,</span> <span class="pre">num_bytes)</span></tt>. Raises <cite>StopIteration</cite> when complete.</p>
<p class="last">Raises <cite>postgresql.copyman.ReceiverFault</cite> when a Receiver raises an
exception.
Raises <cite>postgresql.copyman.ProducerFault</cite> when the Producer raises an
exception. The original exception is available via the exception&#8217;s
<tt class="docutils literal"><span class="pre">__context__</span></tt> attribute.</p>
</dd>
<dt><tt class="docutils literal"><span class="pre">CopyManager.reconcile(faulted_receiver)</span></tt></dt>
<dd>Reconcile a faulted receiver. When a receiver faults, it will no longer
be in the set of Receivers. This method is used to signal to the manager that the
problem has been corrected, and the receiver is again ready to receive.</dd>
<dt><tt class="docutils literal"><span class="pre">CopyManager.receivers</span></tt></dt>
<dd>The <cite>builtins.set</cite> of Receivers involved in the COPY operation.</dd>
<dt><tt class="docutils literal"><span class="pre">CopyManager.producer</span></tt></dt>
<dd>The Producer emitting the data to be given to the Receivers.</dd>
</dl>
</div></blockquote>
</div>
</div>
<div class="section" id="faults">
<h2>Faults<a class="headerlink" href="#faults" title="Permalink to this headline"></a></h2>
<p>The CopyManager generalizes any exceptions that occur during transfer. While
inside the context manager, <cite>postgresql.copyman.Fault</cite> may be raised if a
Receiver or a Producer raises an exception. A <cite>postgresql.copyman.ProducerFault</cite>
in the case of the Producer, and <cite>postgresql.copyman.ReceiverFault</cite> in the case
of the Receivers.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Faults are only raised by <cite>postgresql.copyman.CopyManager.__next__</cite>. The
<tt class="docutils literal"><span class="pre">run()</span></tt> method will only raise <cite>postgresql.copyman.CopyFail</cite>.</p>
</div>
<div class="section" id="receiver-faults">
<h3>Receiver Faults<a class="headerlink" href="#receiver-faults" title="Permalink to this headline"></a></h3>
<p>The Manager assumes the Fault is fatal to a Receiver, and immediately removes
it from the set of target receivers. Additionally, if the Fault exception goes
untrapped, the copy will ultimately fail.</p>
<p>The Fault exception references the Manager that raised the exception, and the
actual exceptions that occurred associated with the Receiver that caused them.</p>
<p>In order to identify the exception that caused a Fault, the <tt class="docutils literal"><span class="pre">faults</span></tt> attribute
on the <cite>postgresql.copyman.ReceiverFault</cite> must be referenced:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">postgresql</span> <span class="kn">import</span> <span class="n">copyman</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">send_stmt</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="s">&quot;COPY (SELECT i FROM generate_series(1, 1000000) AS g(i)) TO STDOUT&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">destination</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;CREATE TEMP TABLE loading_table (i int8)&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">receive_stmt</span> <span class="o">=</span> <span class="n">destination</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="s">&quot;COPY loading_table FROM STDIN&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">producer</span> <span class="o">=</span> <span class="n">copyman</span><span class="o">.</span><span class="n">StatementProducer</span><span class="p">(</span><span class="n">send_stmt</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">receiver</span> <span class="o">=</span> <span class="n">copyman</span><span class="o">.</span><span class="n">StatementReceiver</span><span class="p">(</span><span class="n">receive_stmt</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">source</span><span class="o">.</span><span class="n">xact</span><span class="p">(),</span> <span class="n">destination</span><span class="o">.</span><span class="n">xact</span><span class="p">():</span>
<span class="gp">... </span> <span class="k">with</span> <span class="n">copyman</span><span class="o">.</span><span class="n">CopyManager</span><span class="p">(</span><span class="n">producer</span><span class="p">,</span> <span class="n">receiver</span><span class="p">)</span> <span class="k">as</span> <span class="n">copy</span><span class="p">:</span>
<span class="gp">... </span>  <span class="k">while</span> <span class="n">copy</span><span class="o">.</span><span class="n">receivers</span><span class="p">:</span>
<span class="gp">... </span>   <span class="k">try</span><span class="p">:</span>
<span class="gp">... </span>    <span class="k">for</span> <span class="n">num_messages</span><span class="p">,</span> <span class="n">num_bytes</span> <span class="ow">in</span> <span class="n">copy</span><span class="p">:</span>
<span class="gp">... </span>     <span class="n">update_rate</span><span class="p">(</span><span class="n">num_bytes</span><span class="p">)</span>
<span class="gp">... </span>    <span class="k">break</span>
<span class="gp">... </span>   <span class="k">except</span> <span class="n">copyman</span><span class="o">.</span><span class="n">ReceiverFault</span> <span class="k">as</span> <span class="n">cf</span><span class="p">:</span>
<span class="gp">... </span>    <span class="c"># Access the original exception using the receiver as the key.</span>
<span class="gp">... </span>    <span class="n">original_exception</span> <span class="o">=</span> <span class="n">cf</span><span class="o">.</span><span class="n">faults</span><span class="p">[</span><span class="n">receiver</span><span class="p">]</span>
<span class="gp">... </span>    <span class="k">if</span> <span class="n">unknown_failure</span><span class="p">(</span><span class="n">original_exception</span><span class="p">):</span>
<span class="gp">... </span>     <span class="o">...</span>
<span class="gp">... </span>     <span class="k">raise</span>
</pre></div>
</div>
<div class="section" id="receiverfault-properties">
<h4>ReceiverFault Properties<a class="headerlink" href="#receiverfault-properties" title="Permalink to this headline"></a></h4>
<p>The following attributes exist on <cite>postgresql.copyman.ReceiverFault</cite> instances:</p>
<blockquote>
<div><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">ReceiverFault.manager</span></tt></dt>
<dd>The subject <cite>postgresql.copyman.CopyManager</cite> instance.</dd>
<dt><tt class="docutils literal"><span class="pre">ReceiverFault.faults</span></tt></dt>
<dd>A dictionary mapping the Receiver to the exception raised by that Receiver.</dd>
</dl>
</div></blockquote>
</div>
<div class="section" id="reconciliation">
<h4>Reconciliation<a class="headerlink" href="#reconciliation" title="Permalink to this headline"></a></h4>
<p>When a <cite>postgresql.copyman.ReceiverFault</cite> is raised, the Manager immediately
removes the Receiver so that the COPY operation can continue. Continuation of
the COPY can occur by trapping the exception and continuing the iteration of the
Manager. However, if the fault is recoverable, the
<cite>postgresql.copyman.CopyManager.reconcile</cite> method must be used to reintroduce the
Receiver into the Manager&#8217;s set. Faults must be trapped from within the
Manager&#8217;s context:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">socket</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">postgresql</span> <span class="kn">import</span> <span class="n">copyman</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">send_stmt</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="s">&quot;COPY (SELECT i FROM generate_series(1, 1000000) AS g(i)) TO STDOUT&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">destination</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;CREATE TEMP TABLE loading_table (i int8)&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">receive_stmt</span> <span class="o">=</span> <span class="n">destination</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="s">&quot;COPY loading_table FROM STDIN&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">producer</span> <span class="o">=</span> <span class="n">copyman</span><span class="o">.</span><span class="n">StatementProducer</span><span class="p">(</span><span class="n">send_stmt</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">receiver</span> <span class="o">=</span> <span class="n">copyman</span><span class="o">.</span><span class="n">StatementReceiver</span><span class="p">(</span><span class="n">receive_stmt</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">source</span><span class="o">.</span><span class="n">xact</span><span class="p">(),</span> <span class="n">destination</span><span class="o">.</span><span class="n">xact</span><span class="p">():</span>
<span class="gp">... </span> <span class="k">with</span> <span class="n">copyman</span><span class="o">.</span><span class="n">CopyManager</span><span class="p">(</span><span class="n">producer</span><span class="p">,</span> <span class="n">receiver</span><span class="p">)</span> <span class="k">as</span> <span class="n">copy</span><span class="p">:</span>
<span class="gp">... </span>  <span class="k">while</span> <span class="n">copy</span><span class="o">.</span><span class="n">receivers</span><span class="p">:</span>
<span class="gp">... </span>   <span class="k">try</span><span class="p">:</span>
<span class="gp">... </span>    <span class="k">for</span> <span class="n">num_messages</span><span class="p">,</span> <span class="n">num_bytes</span> <span class="ow">in</span> <span class="n">copy</span><span class="p">:</span>
<span class="gp">... </span>     <span class="n">update_rate</span><span class="p">(</span><span class="n">num_bytes</span><span class="p">)</span>
<span class="gp">... </span>   <span class="k">except</span> <span class="n">copyman</span><span class="o">.</span><span class="n">ReceiverFault</span> <span class="k">as</span> <span class="n">cf</span><span class="p">:</span>
<span class="gp">... </span>    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cf</span><span class="o">.</span><span class="n">faults</span><span class="p">[</span><span class="n">receiver</span><span class="p">],</span> <span class="n">socket</span><span class="o">.</span><span class="n">timeout</span><span class="p">):</span>
<span class="gp">... </span>     <span class="n">copy</span><span class="o">.</span><span class="n">reconcile</span><span class="p">(</span><span class="n">receiver</span><span class="p">)</span>
<span class="gp">... </span>    <span class="k">else</span><span class="p">:</span>
<span class="gp">... </span>     <span class="k">raise</span>
</pre></div>
</div>
<p>Recovering from Faults does add significant complexity to a COPY operation,
so, often, it&#8217;s best to avoid conditions in which reconciliable Faults may
occur.</p>
</div>
</div>
<div class="section" id="producer-faults">
<h3>Producer Faults<a class="headerlink" href="#producer-faults" title="Permalink to this headline"></a></h3>
<p>Producer faults are normally fatal to the COPY operation and should rarely be
trapped. However, the Manager makes no state changes when a Producer faults,
so, unlike Receiver Faults, no reconciliation process is necessary; rather,
if it&#8217;s safe to continue, the Manager&#8217;s iterator should continue to be
processed.</p>
<div class="section" id="producerfault-properties">
<h4>ProducerFault Properties<a class="headerlink" href="#producerfault-properties" title="Permalink to this headline"></a></h4>
<p>The following attributes exist on <cite>postgresql.copyman.ProducerFault</cite> instances:</p>
<blockquote>
<div><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">ReceiverFault.manager</span></tt></dt>
<dd>The subject <cite>postgresql.copyman.CopyManager</cite>.</dd>
<dt><tt class="docutils literal"><span class="pre">ReceiverFault.__context__</span></tt></dt>
<dd>The original exception raised by the Producer.</dd>
</dl>
</div></blockquote>
</div>
</div>
</div>
<div class="section" id="failures">
<h2>Failures<a class="headerlink" href="#failures" title="Permalink to this headline"></a></h2>
<p>When a COPY operation is aborted, either by an exception or by the iterator
being broken, a <cite>postgresql.copyman.CopyFail</cite> exception will be raised by the
Manager&#8217;s <tt class="docutils literal"><span class="pre">__exit__()</span></tt> method. The <cite>postgresql.copyman.CopyFail</cite> exception
offers to record any exceptions that occur during the exit of the context
managers of the Producer and the Receivers.</p>
<div class="section" id="copyfail-properties">
<h3>CopyFail Properties<a class="headerlink" href="#copyfail-properties" title="Permalink to this headline"></a></h3>
<p>The following properties exist on <cite>postgresql.copyman.CopyFail</cite> exceptions:</p>
<blockquote>
<div><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">CopyFail.manager</span></tt></dt>
<dd>The Manager whose COPY operation failed.</dd>
<dt><tt class="docutils literal"><span class="pre">CopyFail.receiver_faults</span></tt></dt>
<dd>A dictionary mapping a <cite>postgresql.copyman.Receiver</cite> to the exception raised
by that Receiver&#8217;s <tt class="docutils literal"><span class="pre">__exit__</span></tt>. <cite>None</cite> if no exceptions were raised by the
Receivers.</dd>
<dt><tt class="docutils literal"><span class="pre">CopyFail.producer_fault</span></tt></dt>
<dd>The exception Raised by the <cite>postgresql.copyman.Producer</cite>. <cite>None</cite> if none.</dd>
</dl>
</div></blockquote>
</div>
</div>
<div class="section" id="producers">
<h2>Producers<a class="headerlink" href="#producers" title="Permalink to this headline"></a></h2>
<p>The following Producers are available:</p>
<blockquote>
<div><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">postgresql.copyman.StatementProducer(postgresql.api.Statement)</span></tt></dt>
<dd>Given a Statement producing COPY data, construct a Producer.</dd>
<dt><tt class="docutils literal"><span class="pre">postgresql.copyman.IteratorProducer(collections.Iterator)</span></tt></dt>
<dd>Given an Iterator producing <em>chunks</em> of COPY lines, construct a Producer to
manage the data coming from the iterator.</dd>
</dl>
</div></blockquote>
</div>
<div class="section" id="receivers">
<h2>Receivers<a class="headerlink" href="#receivers" title="Permalink to this headline"></a></h2>
<blockquote>
<div><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">postgresql.copyman.StatementReceiver(postgresql.api.Statement)</span></tt></dt>
<dd>Given a Statement producing COPY data, construct a Producer.</dd>
<dt><tt class="docutils literal"><span class="pre">postgresql.copyman.CallReceiver(callable)</span></tt></dt>
<dd>Given a callable, construct a Receiver that will transmit COPY data in chunks
of lines. That is, the callable will be given a list of COPY lines for each
transfer cycle.</dd>
</dl>
</div></blockquote>
</div>
<div class="section" id="terminology">
<h2>Terminology<a class="headerlink" href="#terminology" title="Permalink to this headline"></a></h2>
<p>The following terms are regularly used to describe the implementation and
processes of the <cite>postgresql.copyman</cite> module:</p>
<blockquote>
<div><dl class="docutils">
<dt>Manager</dt>
<dd>The object used to manage data coming from a Producer and being given to the
Receivers. It also manages the necessary initialization and finalization steps
required by those factors.</dd>
<dt>Producer</dt>
<dd>The object used to produce the COPY data to be given to the Receivers. The
source.</dd>
<dt>Receiver</dt>
<dd>An object that consumes COPY data. A target.</dd>
<dt>Fault</dt>
<dd>Specifically, <cite>postgresql.copyman.Fault</cite> exceptions. A Fault is raised
when a Receiver or a Producer raises an exception during the COPY operation.</dd>
<dt>Reconciliation</dt>
<dd>Generally, the steps performed by the &#8220;reconcile&#8221; method on
<cite>postgresql.copyman.CopyManager</cite> instances. More precisely, the
necessary steps for a Receiver&#8217;s reintroduction into the COPY operation after
a Fault.</dd>
<dt>Failed Copy</dt>
<dd>A failed copy is an aborted COPY operation. This occurs in situations of
untrapped exceptions or an incomplete COPY. Specifically, the COPY will be
noted as failed in cases where the Manager&#8217;s iterator is <em>not</em> ran until
exhaustion.</dd>
<dt>Realignment</dt>
<dd>The process of providing compensating data to the Receivers so that the
connection will be on a message boundary. Occurs when the COPY operation
is aborted.</dd>
</dl>
</div></blockquote>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Copy Management</a><ul>
<li><a class="reference internal" href="#copy-managers">Copy Managers</a><ul>
<li><a class="reference internal" href="#manager-interface-points">Manager Interface Points</a></li>
</ul>
</li>
<li><a class="reference internal" href="#faults">Faults</a><ul>
<li><a class="reference internal" href="#receiver-faults">Receiver Faults</a><ul>
<li><a class="reference internal" href="#receiverfault-properties">ReceiverFault Properties</a></li>
<li><a class="reference internal" href="#reconciliation">Reconciliation</a></li>
</ul>
</li>
<li><a class="reference internal" href="#producer-faults">Producer Faults</a><ul>
<li><a class="reference internal" href="#producerfault-properties">ProducerFault Properties</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#failures">Failures</a><ul>
<li><a class="reference internal" href="#copyfail-properties">CopyFail Properties</a></li>
</ul>
</li>
<li><a class="reference internal" href="#producers">Producers</a></li>
<li><a class="reference internal" href="#receivers">Receivers</a></li>
<li><a class="reference internal" href="#terminology">Terminology</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="driver.html"
                        title="previous chapter">Driver</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="notifyman.html"
                        title="next chapter">Notification Management</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/copyman.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="notifyman.html" title="Notification Management"
             >next</a> |</li>
        <li class="right" >
          <a href="driver.html" title="Driver"
             >previous</a> |</li>
        <li><a href="index.html">py-postgresql 1.1.0 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright Python+Postgres.
      Last updated on Mar 31, 2014.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.2.
    </div>
  </body>
</html>