This file is indexed.

/usr/share/doc/python-psycopg2-doc/html/connection.html is in python-psycopg2-doc 2.6.1-1build2.

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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
<!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>The connection class &mdash; Psycopg 2.0 documentation</title>
    
    <link rel="stylesheet" href="_static/psycopg.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '2.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="Psycopg 2.0 documentation" href="index.html" />
    <link rel="next" title="The cursor class" href="cursor.html" />
    <link rel="prev" title="The psycopg2 module content" href="module.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <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="cursor.html" title="The cursor class"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="module.html" title="The psycopg2 module content"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Psycopg 2.0 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="the-connection-class">
<h1>The <code class="docutils literal"><span class="pre">connection</span></code> class<a class="headerlink" href="#the-connection-class" title="Permalink to this headline"></a></h1>
<dl class="class">
<dt id="connection">
<em class="property">class </em><code class="descname">connection</code><a class="headerlink" href="#connection" title="Permalink to this definition"></a></dt>
<dd><p>Handles the connection to a PostgreSQL database instance. It encapsulates
a database session.</p>
<p>Connections are created using the factory function
<a class="reference internal" href="module.html#psycopg2.connect" title="psycopg2.connect"><code class="xref py py-obj docutils literal"><span class="pre">connect()</span></code></a>.</p>
<p>Connections are thread safe and can be shared among many threads. See
<a class="reference internal" href="usage.html#thread-safety"><span>Thread and process safety</span></a> for details.</p>
<dl class="method">
<dt id="connection.cursor">
<code class="descname">cursor</code><span class="sig-paren">(</span><em>name=None</em>, <em>cursor_factory=None</em>, <em>scrollable=None</em>, <em>withhold=False</em><span class="sig-paren">)</span><a class="headerlink" href="#connection.cursor" title="Permalink to this definition"></a></dt>
<dd><p>Return a new <a class="reference internal" href="cursor.html#cursor" title="cursor"><code class="xref py py-obj docutils literal"><span class="pre">cursor</span></code></a> object using the connection.</p>
<p>If <em>name</em> is specified, the returned cursor will be a <a class="reference internal" href="usage.html#server-side-cursors"><span>server
side cursor</span></a> (also known as <em>named cursor</em>).
Otherwise it will be a regular <em>client side</em> cursor.  By default a
named cursor is declared without <code class="sql docutils literal"><span class="pre">SCROLL</span></code> option and
<code class="sql docutils literal"><span class="pre">WITHOUT</span> <span class="pre">HOLD</span></code>: set the argument or property <a class="reference internal" href="cursor.html#cursor.scrollable" title="cursor.scrollable"><code class="xref py py-obj docutils literal"><span class="pre">scrollable</span></code></a>
to <code class="xref py py-obj docutils literal"><span class="pre">True</span></code>/<code class="xref py py-obj docutils literal"><span class="pre">False</span></code> and or <a class="reference internal" href="cursor.html#cursor.withhold" title="cursor.withhold"><code class="xref py py-obj docutils literal"><span class="pre">withhold</span></code></a> to <code class="xref py py-obj docutils literal"><span class="pre">True</span></code> to change the
declaration.</p>
<p>The name can be a string not valid as a PostgreSQL identifier: for
example it may start with a digit and contain non-alphanumeric
characters and quotes.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.4: </span>previously only valid PostgreSQL identifiers were accepted as
cursor name.</p>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">It is unsafe to expose the <em>name</em> to an untrusted source, for
instance you shouldn&#8217;t allow <em>name</em> to be read from a HTML form.
Consider it as part of the query, not as a query parameter.</p>
</div>
<p>The <em>cursor_factory</em> argument can be used to create non-standard
cursors. The class returned must be a subclass of
<a class="reference internal" href="extensions.html#psycopg2.extensions.cursor" title="psycopg2.extensions.cursor"><code class="xref py py-obj docutils literal"><span class="pre">psycopg2.extensions.cursor</span></code></a>. See <a class="reference internal" href="advanced.html#subclassing-cursor"><span>Connection and cursor factories</span></a> for
details. A default factory for the connection can also be specified
using the <a class="reference internal" href="#connection.cursor_factory" title="connection.cursor_factory"><code class="xref py py-obj docutils literal"><span class="pre">cursor_factory</span></code></a> attribute.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.4.3: </span>added the <em>withhold</em> argument.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.5: </span>added the <em>scrollable</em> argument.</p>
</div>
<div class="admonition-db-api-extension dbapi-extension admonition">
<p class="first admonition-title">DB API extension</p>
<p class="last">All the function arguments are Psycopg extensions to the DB API 2.0.</p>
</div>
</dd></dl>

<span class="target" id="index-0"></span><dl class="method">
<dt id="connection.commit">
<code class="descname">commit</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.commit" title="Permalink to this definition"></a></dt>
<dd><p>Commit any pending transaction to the database.</p>
<p>By default, Psycopg opens a transaction before executing the first
command: if <code class="xref py py-obj docutils literal"><span class="pre">commit()</span></code> is not called, the effect of any data
manipulation will be lost.</p>
<p>The connection can be also set in &#8220;autocommit&#8221; mode: no transaction is
automatically open, commands have immediate effect. See
<a class="reference internal" href="usage.html#transactions-control"><span>Transactions control</span></a> for details.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.5: </span>if the connection is used in a <code class="docutils literal"><span class="pre">with</span></code>
statement, the method is automatically called if no exception is
raised in the <code class="docutils literal"><span class="pre">with</span></code> block.</p>
</div>
</dd></dl>

<span class="target" id="index-1"></span><dl class="method">
<dt id="connection.rollback">
<code class="descname">rollback</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.rollback" title="Permalink to this definition"></a></dt>
<dd><p>Roll back to the start of any pending transaction.  Closing a
connection without committing the changes first will cause an implicit
rollback to be performed.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.5: </span>if the connection is used in a <code class="docutils literal"><span class="pre">with</span></code>
statement, the method is automatically called if an exception is
raised in the <code class="docutils literal"><span class="pre">with</span></code> block.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="connection.close">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.close" title="Permalink to this definition"></a></dt>
<dd><p>Close the connection now (rather than whenever <code class="xref py py-obj docutils literal"><span class="pre">del</span></code> is executed).
The connection will be unusable from this point forward; an
<a class="reference internal" href="module.html#psycopg2.InterfaceError" title="psycopg2.InterfaceError"><code class="xref py py-obj docutils literal"><span class="pre">InterfaceError</span></code></a> will be raised if any operation is
attempted with the connection.  The same applies to all cursor objects
trying to use the connection.  Note that closing a connection without
committing the changes first will cause any pending change to be
discarded as if a <code class="sql docutils literal"><span class="pre">ROLLBACK</span></code> was performed (unless a different
isolation level has been selected: see
<a class="reference internal" href="#connection.set_isolation_level" title="connection.set_isolation_level"><code class="xref py py-obj docutils literal"><span class="pre">set_isolation_level()</span></code></a>).</p>
<div class="versionchanged" id="index-2">
<p><span class="versionmodified">Changed in version 2.2: </span>previously an explicit <code class="sql docutils literal"><span class="pre">ROLLBACK</span></code> was issued by Psycopg on
<code class="xref py py-obj docutils literal"><span class="pre">close()</span></code>. The command could have been sent to the backend at an
inappropriate time, so Psycopg currently relies on the backend to
implicitly discard uncommitted changes. Some middleware are known
to behave incorrectly though when the connection is closed during
a transaction (when <a class="reference internal" href="#connection.status" title="connection.status"><code class="xref py py-obj docutils literal"><span class="pre">status</span></code></a> is
<a class="reference internal" href="extensions.html#psycopg2.extensions.STATUS_IN_TRANSACTION" title="psycopg2.extensions.STATUS_IN_TRANSACTION"><code class="xref py py-obj docutils literal"><span class="pre">STATUS_IN_TRANSACTION</span></code></a>), e.g. <a class="reference external" href="http://pgbouncer.projects.postgresql.org/">PgBouncer</a>
reports an <code class="docutils literal"><span class="pre">unclean</span> <span class="pre">server</span></code> and discards the connection. To
avoid this problem you can ensure to terminate the transaction
with a <a class="reference internal" href="#connection.commit" title="connection.commit"><code class="xref py py-obj docutils literal"><span class="pre">commit()</span></code></a>/<a class="reference internal" href="#connection.rollback" title="connection.rollback"><code class="xref py py-obj docutils literal"><span class="pre">rollback()</span></code></a> before
closing.</p>
</div>
</dd></dl>

<p class="rubric" id="index-3">Exceptions as connection class attributes</p>
<p>The <code class="xref py py-obj docutils literal"><span class="pre">connection</span></code> also exposes as attributes the same exceptions
available in the <a class="reference internal" href="module.html#module-psycopg2" title="psycopg2"><code class="xref py py-obj docutils literal"><span class="pre">psycopg2</span></code></a> module.  See <a class="reference internal" href="module.html#dbapi-exceptions"><span>Exceptions</span></a>.</p>
<p class="rubric" id="index-4">Two-phase commit support methods</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.3.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="usage.html#tpc"><span>Two-Phase Commit protocol support</span></a> for an introductory explanation of these methods.</p>
</div>
<p>Note that PostgreSQL supports two-phase commit since release 8.1: these
methods raise <a class="reference internal" href="module.html#psycopg2.NotSupportedError" title="psycopg2.NotSupportedError"><code class="xref py py-obj docutils literal"><span class="pre">NotSupportedError</span></code></a> if used with an older version
server.</p>
<span class="target" id="tpc-methods"></span><dl class="method">
<dt id="connection.xid">
<code class="descname">xid</code><span class="sig-paren">(</span><em>format_id</em>, <em>gtrid</em>, <em>bqual</em><span class="sig-paren">)</span><a class="headerlink" href="#connection.xid" title="Permalink to this definition"></a></dt>
<dd><p>Returns a <code class="xref py py-obj docutils literal"><span class="pre">Xid</span></code> instance to be passed to the
<code class="xref py py-obj docutils literal"><span class="pre">tpc_*()</span></code> methods of this connection. The argument types and
constraints are explained in <a class="reference internal" href="usage.html#tpc"><span>Two-Phase Commit protocol support</span></a>.</p>
<p>The values passed to the method will be available on the returned
object as the members <code class="xref py py-obj docutils literal"><span class="pre">format_id</span></code>,
<code class="xref py py-obj docutils literal"><span class="pre">gtrid</span></code>, <code class="xref py py-obj docutils literal"><span class="pre">bqual</span></code>.
The object also allows accessing to these members and unpacking as a
3-items tuple.</p>
</dd></dl>

<dl class="method">
<dt id="connection.tpc_begin">
<code class="descname">tpc_begin</code><span class="sig-paren">(</span><em>xid</em><span class="sig-paren">)</span><a class="headerlink" href="#connection.tpc_begin" title="Permalink to this definition"></a></dt>
<dd><p>Begins a TPC transaction with the given transaction ID <em>xid</em>.</p>
<p>This method should be called outside of a transaction (i.e. nothing
may have executed since the last <a class="reference internal" href="#connection.commit" title="connection.commit"><code class="xref py py-obj docutils literal"><span class="pre">commit()</span></code></a> or
<a class="reference internal" href="#connection.rollback" title="connection.rollback"><code class="xref py py-obj docutils literal"><span class="pre">rollback()</span></code></a> and <a class="reference internal" href="#connection.status" title="connection.status"><code class="xref py py-obj docutils literal"><span class="pre">connection.status</span></code></a> is
<a class="reference internal" href="extensions.html#psycopg2.extensions.STATUS_READY" title="psycopg2.extensions.STATUS_READY"><code class="xref py py-obj docutils literal"><span class="pre">STATUS_READY</span></code></a>).</p>
<p>Furthermore, it is an error to call <code class="xref py py-obj docutils literal"><span class="pre">commit()</span></code> or <code class="xref py py-obj docutils literal"><span class="pre">rollback()</span></code>
within the TPC transaction: in this case a <a class="reference internal" href="module.html#psycopg2.ProgrammingError" title="psycopg2.ProgrammingError"><code class="xref py py-obj docutils literal"><span class="pre">ProgrammingError</span></code></a>
is raised.</p>
<p>The <em>xid</em> may be either an object returned by the <a class="reference internal" href="#connection.xid" title="connection.xid"><code class="xref py py-obj docutils literal"><span class="pre">xid()</span></code></a>
method or a plain string: the latter allows to create a transaction
using the provided string as PostgreSQL transaction id. See also
<a class="reference internal" href="#connection.tpc_recover" title="connection.tpc_recover"><code class="xref py py-obj docutils literal"><span class="pre">tpc_recover()</span></code></a>.</p>
</dd></dl>

<span class="target" id="index-5"></span><dl class="method">
<dt id="connection.tpc_prepare">
<code class="descname">tpc_prepare</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.tpc_prepare" title="Permalink to this definition"></a></dt>
<dd><p>Performs the first phase of a transaction started with
<a class="reference internal" href="#connection.tpc_begin" title="connection.tpc_begin"><code class="xref py py-obj docutils literal"><span class="pre">tpc_begin()</span></code></a>.  A <a class="reference internal" href="module.html#psycopg2.ProgrammingError" title="psycopg2.ProgrammingError"><code class="xref py py-obj docutils literal"><span class="pre">ProgrammingError</span></code></a> is raised if
this method is used outside of a TPC transaction.</p>
<p>After calling <code class="xref py py-obj docutils literal"><span class="pre">tpc_prepare()</span></code>, no statements can be executed until
<a class="reference internal" href="#connection.tpc_commit" title="connection.tpc_commit"><code class="xref py py-obj docutils literal"><span class="pre">tpc_commit()</span></code></a> or <a class="reference internal" href="#connection.tpc_rollback" title="connection.tpc_rollback"><code class="xref py py-obj docutils literal"><span class="pre">tpc_rollback()</span></code></a> will be
called.  The <a class="reference internal" href="#connection.reset" title="connection.reset"><code class="xref py py-obj docutils literal"><span class="pre">reset()</span></code></a> method can be used to restore the
status of the connection to <a class="reference internal" href="extensions.html#psycopg2.extensions.STATUS_READY" title="psycopg2.extensions.STATUS_READY"><code class="xref py py-obj docutils literal"><span class="pre">STATUS_READY</span></code></a>: the
transaction will remain prepared in the database and will be
possible to finish it with <code class="xref py py-obj docutils literal"><span class="pre">tpc_commit(xid)</span></code> and
<code class="xref py py-obj docutils literal"><span class="pre">tpc_rollback(xid)</span></code>.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">the <a class="reference external" href="http://www.postgresql.org/docs/current/static/sql-prepare-transaction.html"><code class="sql docutils literal"><span class="pre">PREPARE</span> <span class="pre">TRANSACTION</span></code></a> PostgreSQL command.</p>
</div>
</dd></dl>

<span class="target" id="index-6"></span><dl class="method">
<dt id="connection.tpc_commit">
<code class="descname">tpc_commit</code><span class="sig-paren">(</span><span class="optional">[</span><em>xid</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.tpc_commit" title="Permalink to this definition"></a></dt>
<dd><p>When called with no arguments, <code class="xref py py-obj docutils literal"><span class="pre">tpc_commit()</span></code> commits a TPC
transaction previously prepared with <a class="reference internal" href="#connection.tpc_prepare" title="connection.tpc_prepare"><code class="xref py py-obj docutils literal"><span class="pre">tpc_prepare()</span></code></a>.</p>
<p>If <code class="xref py py-obj docutils literal"><span class="pre">tpc_commit()</span></code> is called prior to <code class="xref py py-obj docutils literal"><span class="pre">tpc_prepare()</span></code>, a single phase
commit is performed.  A transaction manager may choose to do this if
only a single resource is participating in the global transaction.</p>
<p>When called with a transaction ID <em>xid</em>, the database commits
the given transaction.  If an invalid transaction ID is
provided, a <a class="reference internal" href="module.html#psycopg2.ProgrammingError" title="psycopg2.ProgrammingError"><code class="xref py py-obj docutils literal"><span class="pre">ProgrammingError</span></code></a> will be raised.  This form
should be called outside of a transaction, and is intended for use in
recovery.</p>
<p>On return, the TPC transaction is ended.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">the <a class="reference external" href="http://www.postgresql.org/docs/current/static/sql-commit-prepared.html"><code class="sql docutils literal"><span class="pre">COMMIT</span> <span class="pre">PREPARED</span></code></a> PostgreSQL command.</p>
</div>
</dd></dl>

<span class="target" id="index-7"></span><dl class="method">
<dt id="connection.tpc_rollback">
<code class="descname">tpc_rollback</code><span class="sig-paren">(</span><span class="optional">[</span><em>xid</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.tpc_rollback" title="Permalink to this definition"></a></dt>
<dd><p>When called with no arguments, <code class="xref py py-obj docutils literal"><span class="pre">tpc_rollback()</span></code> rolls back a TPC
transaction.  It may be called before or after
<a class="reference internal" href="#connection.tpc_prepare" title="connection.tpc_prepare"><code class="xref py py-obj docutils literal"><span class="pre">tpc_prepare()</span></code></a>.</p>
<p>When called with a transaction ID <em>xid</em>, it rolls back the given
transaction.  If an invalid transaction ID is provided, a
<a class="reference internal" href="module.html#psycopg2.ProgrammingError" title="psycopg2.ProgrammingError"><code class="xref py py-obj docutils literal"><span class="pre">ProgrammingError</span></code></a> is raised.  This form should be called
outside of a transaction, and is intended for use in recovery.</p>
<p>On return, the TPC transaction is ended.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">the <a class="reference external" href="http://www.postgresql.org/docs/current/static/sql-rollback-prepared.html"><code class="sql docutils literal"><span class="pre">ROLLBACK</span> <span class="pre">PREPARED</span></code></a> PostgreSQL command.</p>
</div>
</dd></dl>

<span class="target" id="index-8"></span><dl class="method">
<dt id="connection.tpc_recover">
<code class="descname">tpc_recover</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.tpc_recover" title="Permalink to this definition"></a></dt>
<dd><p>Returns a list of <code class="xref py py-obj docutils literal"><span class="pre">Xid</span></code> representing pending
transactions, suitable for use with <a class="reference internal" href="#connection.tpc_commit" title="connection.tpc_commit"><code class="xref py py-obj docutils literal"><span class="pre">tpc_commit()</span></code></a> or
<a class="reference internal" href="#connection.tpc_rollback" title="connection.tpc_rollback"><code class="xref py py-obj docutils literal"><span class="pre">tpc_rollback()</span></code></a>.</p>
<p>If a transaction was not initiated by Psycopg, the returned Xids will
have attributes <code class="xref py py-obj docutils literal"><span class="pre">format_id</span></code> and
<code class="xref py py-obj docutils literal"><span class="pre">bqual</span></code> set to <code class="xref py py-obj docutils literal"><span class="pre">None</span></code> and the
<code class="xref py py-obj docutils literal"><span class="pre">gtrid</span></code> set to the PostgreSQL transaction ID: such Xids are still
usable for recovery.  Psycopg uses the same algorithm of the
<a class="reference external" href="http://jdbc.postgresql.org/">PostgreSQL JDBC driver</a> to encode a XA triple in a string, so
transactions initiated by a program using such driver should be
unpacked correctly.</p>
<p>Xids returned by <code class="xref py py-obj docutils literal"><span class="pre">tpc_recover()</span></code> also have extra attributes
<code class="xref py py-obj docutils literal"><span class="pre">prepared</span></code>, <code class="xref py py-obj docutils literal"><span class="pre">owner</span></code>,
<code class="xref py py-obj docutils literal"><span class="pre">database</span></code> populated with the values read
from the server.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">the <a class="reference external" href="http://www.postgresql.org/docs/current/static/view-pg-prepared-xacts.html"><code class="xref py py-obj docutils literal"><span class="pre">pg_prepared_xacts</span></code></a> system view.</p>
</div>
</dd></dl>

<div class="admonition-db-api-extension dbapi-extension admonition">
<p class="first admonition-title">DB API extension</p>
<p class="last">The above methods are the only ones defined by the DB API 2.0 protocol.
The Psycopg connection objects exports the following additional
methods and attributes.</p>
</div>
<dl class="attribute">
<dt id="connection.closed">
<code class="descname">closed</code><a class="headerlink" href="#connection.closed" title="Permalink to this definition"></a></dt>
<dd><p>Read-only integer attribute: 0 if the connection is open, nonzero if
it is closed or broken.</p>
</dd></dl>

<dl class="method">
<dt id="connection.cancel">
<code class="descname">cancel</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.cancel" title="Permalink to this definition"></a></dt>
<dd><p>Cancel the current database operation.</p>
<p>The method interrupts the processing of the current operation. If no
query is being executed, it does nothing. You can call this function
from a different thread than the one currently executing a database
operation, for instance if you want to cancel a long running query if a
button is pushed in the UI. Interrupting query execution will cause the
cancelled method to raise a
<a class="reference internal" href="extensions.html#psycopg2.extensions.QueryCanceledError" title="psycopg2.extensions.QueryCanceledError"><code class="xref py py-obj docutils literal"><span class="pre">QueryCanceledError</span></code></a>. Note that the termination
of the query is not guaranteed to succeed: see the documentation for
<a class="reference external" href="http://www.postgresql.org/docs/current/static/libpq-cancel.html#LIBPQ-PQCANCEL"><code class="xref py py-obj docutils literal"><span class="pre">PQcancel()</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.3.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="connection.reset">
<code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.reset" title="Permalink to this definition"></a></dt>
<dd><p>Reset the connection to the default.</p>
<p>The method rolls back an eventual pending transaction and executes the
PostgreSQL <a class="reference external" href="http://www.postgresql.org/docs/current/static/sql-reset.html"><code class="sql docutils literal"><span class="pre">RESET</span></code></a> and <a class="reference external" href="http://www.postgresql.org/docs/current/static/sql-set-session-authorization.html"><code class="sql docutils literal"><span class="pre">SET</span> <span class="pre">SESSION</span> <span class="pre">AUTHORIZATION</span></code></a> to revert the
session to the default values. A two-phase commit transaction prepared
using <a class="reference internal" href="#connection.tpc_prepare" title="connection.tpc_prepare"><code class="xref py py-obj docutils literal"><span class="pre">tpc_prepare()</span></code></a> will remain in the database
available for recover.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.12.</span></p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="connection.dsn">
<code class="descname">dsn</code><a class="headerlink" href="#connection.dsn" title="Permalink to this definition"></a></dt>
<dd><p>Read-only string containing the connection string used by the
connection.</p>
</dd></dl>

<span class="target" id="index-9"></span><dl class="method">
<dt id="connection.set_session">
<code class="descname">set_session</code><span class="sig-paren">(</span><em>isolation_level=None</em>, <em>readonly=None</em>, <em>deferrable=None</em>, <em>autocommit=None</em><span class="sig-paren">)</span><a class="headerlink" href="#connection.set_session" title="Permalink to this definition"></a></dt>
<dd><p>Set one or more parameters for the next transactions or statements in
the current session.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>isolation_level</strong> &#8211; set the <a class="reference external" href="http://www.postgresql.org/docs/current/static/transaction-iso.html">isolation level</a> for the next
transactions/statements.  The value can be one of the literal
values <code class="docutils literal"><span class="pre">READ</span> <span class="pre">UNCOMMITTED</span></code>, <code class="docutils literal"><span class="pre">READ</span> <span class="pre">COMMITTED</span></code>, <code class="docutils literal"><span class="pre">REPEATABLE</span>
<span class="pre">READ</span></code>, <code class="docutils literal"><span class="pre">SERIALIZABLE</span></code> or the equivalent <a class="reference internal" href="extensions.html#isolation-level-constants"><span>constant</span></a> defined in the <a class="reference internal" href="extensions.html#module-psycopg2.extensions" title="psycopg2.extensions"><code class="xref py py-obj docutils literal"><span class="pre">extensions</span></code></a>
module.</li>
<li><strong>readonly</strong> &#8211; if <code class="xref py py-obj docutils literal"><span class="pre">True</span></code>, set the connection to read only;
read/write if <code class="xref py py-obj docutils literal"><span class="pre">False</span></code>.</li>
<li><strong>deferrable</strong> &#8211; if <code class="xref py py-obj docutils literal"><span class="pre">True</span></code>, set the connection to deferrable;
non deferrable if <code class="xref py py-obj docutils literal"><span class="pre">False</span></code>. Only available from PostgreSQL 9.1.</li>
<li><strong>autocommit</strong> &#8211; switch the connection to autocommit mode: not a
PostgreSQL session setting but an alias for setting the
<a class="reference internal" href="#connection.autocommit" title="connection.autocommit"><code class="xref py py-obj docutils literal"><span class="pre">autocommit</span></code></a> attribute.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Arguments set to <code class="xref py py-obj docutils literal"><span class="pre">None</span></code> (the default for all) will not be changed.
The parameters <em>isolation_level</em>, <em>readonly</em> and <em>deferrable</em> also
accept the string <code class="docutils literal"><span class="pre">DEFAULT</span></code> as a value: the effect is to reset the
parameter to the server default.  Defaults are defined by the server
configuration: see values for <a class="reference external" href="http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-ISOLATION"><code class="sql docutils literal"><span class="pre">default_transaction_isolation</span></code></a>,
<a class="reference external" href="http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-READ-ONLY"><code class="sql docutils literal"><span class="pre">default_transaction_read_only</span></code></a>, <a class="reference external" href="http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-DEFERRABLE"><code class="sql docutils literal"><span class="pre">default_transaction_deferrable</span></code></a>.</p>
<p>The function must be invoked with no transaction in progress.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">There is currently no builtin method to read the current value for
the parameters: use <code class="sql docutils literal"><span class="pre">SHOW</span> <span class="pre">default_transaction_...</span></code> to read
the values from the backend.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference external" href="http://www.postgresql.org/docs/current/static/sql-set-transaction.html"><code class="sql docutils literal"><span class="pre">SET</span> <span class="pre">TRANSACTION</span></code></a> for further details about the behaviour
of the transaction parameters in the server.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.4.2.</span></p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="connection.autocommit">
<code class="descname">autocommit</code><a class="headerlink" href="#connection.autocommit" title="Permalink to this definition"></a></dt>
<dd><p>Read/write attribute: if <code class="xref py py-obj docutils literal"><span class="pre">True</span></code>, no transaction is handled by the
driver and every statement sent to the backend has immediate effect;
if <code class="xref py py-obj docutils literal"><span class="pre">False</span></code> a new transaction is started at the first command
execution: the methods <a class="reference internal" href="#connection.commit" title="connection.commit"><code class="xref py py-obj docutils literal"><span class="pre">commit()</span></code></a> or <a class="reference internal" href="#connection.rollback" title="connection.rollback"><code class="xref py py-obj docutils literal"><span class="pre">rollback()</span></code></a> must be manually
invoked to terminate the transaction.</p>
<p>The autocommit mode is useful to execute commands requiring to be run
outside a transaction, such as <code class="sql docutils literal"><span class="pre">CREATE</span> <span class="pre">DATABASE</span></code> or
<code class="sql docutils literal"><span class="pre">VACUUM</span></code>.</p>
<p>The default is <code class="xref py py-obj docutils literal"><span class="pre">False</span></code> (manual commit) as per DBAPI specification.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">By default, any query execution, including a simple <code class="sql docutils literal"><span class="pre">SELECT</span></code>
will start a transaction: for long-running programs, if no further
action is taken, the session will remain &#8220;idle in transaction&#8221;, an
undesirable condition for several reasons (locks are held by
the session, tables bloat...). For long lived scripts, either
ensure to terminate a transaction as soon as possible or use an
autocommit connection.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.4.2.</span></p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="connection.isolation_level">
<code class="descname">isolation_level</code><a class="headerlink" href="#connection.isolation_level" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="connection.set_isolation_level">
<code class="descname">set_isolation_level</code><span class="sig-paren">(</span><em>level</em><span class="sig-paren">)</span><a class="headerlink" href="#connection.set_isolation_level" title="Permalink to this definition"></a></dt>
<dd><div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">From version 2.4.2, <a class="reference internal" href="#connection.set_session" title="connection.set_session"><code class="xref py py-obj docutils literal"><span class="pre">set_session()</span></code></a> and <a class="reference internal" href="#connection.autocommit" title="connection.autocommit"><code class="xref py py-obj docutils literal"><span class="pre">autocommit</span></code></a>, offer
finer control on the transaction characteristics.</p>
</div>
<p>Read or set the <a class="reference external" href="http://www.postgresql.org/docs/current/static/transaction-iso.html">transaction isolation level</a> for the current session.
The level defines the different phenomena that can happen in the
database between concurrent transactions.</p>
<p>The value set or read is an integer: symbolic constants are defined in
the module <a class="reference internal" href="extensions.html#module-psycopg2.extensions" title="psycopg2.extensions"><code class="xref py py-obj docutils literal"><span class="pre">psycopg2.extensions</span></code></a>: see
<a class="reference internal" href="extensions.html#isolation-level-constants"><span>Isolation level constants</span></a> for the available values.</p>
<p>The default level is <code class="sql docutils literal"><span class="pre">READ</span> <span class="pre">COMMITTED</span></code>: at this level a
transaction is automatically started the first time a database command
is executed.  If you want an <em>autocommit</em> mode, switch to
<a class="reference internal" href="extensions.html#psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT" title="psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT"><code class="xref py py-obj docutils literal"><span class="pre">ISOLATION_LEVEL_AUTOCOMMIT</span></code></a> before
executing any command:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">conn</span><span class="o">.</span><span class="n">set_isolation_level</span><span class="p">(</span><span class="n">psycopg2</span><span class="o">.</span><span class="n">extensions</span><span class="o">.</span><span class="n">ISOLATION_LEVEL_AUTOCOMMIT</span><span class="p">)</span>
</pre></div>
</div>
<p>See also <a class="reference internal" href="usage.html#transactions-control"><span>Transactions control</span></a>.</p>
</dd></dl>

<span class="target" id="index-10"></span><dl class="attribute">
<dt id="connection.encoding">
<code class="descname">encoding</code><a class="headerlink" href="#connection.encoding" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="connection.set_client_encoding">
<code class="descname">set_client_encoding</code><span class="sig-paren">(</span><em>enc</em><span class="sig-paren">)</span><a class="headerlink" href="#connection.set_client_encoding" title="Permalink to this definition"></a></dt>
<dd><p>Read or set the client encoding for the current session. The default
is the encoding defined by the database. It should be one of the
<a class="reference external" href="http://www.postgresql.org/docs/current/static/multibyte.html">characters set supported by PostgreSQL</a></p>
</dd></dl>

<span class="target" id="index-11"></span><dl class="attribute">
<dt id="connection.notices">
<code class="descname">notices</code><a class="headerlink" href="#connection.notices" title="Permalink to this definition"></a></dt>
<dd><p>A list containing all the database messages sent to the client during
the session.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;CREATE TABLE foo (id serial PRIMARY KEY);&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">conn</span><span class="o">.</span><span class="n">notices</span><span class="p">)</span>
<span class="go">[&#39;NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index &quot;foo_pkey&quot; for table &quot;foo&quot;\n&#39;,</span>
<span class="go"> &#39;NOTICE:  CREATE TABLE will create implicit sequence &quot;foo_id_seq&quot; for serial column &quot;foo.id&quot;\n&#39;]</span>
</pre></div>
</div>
<p>To avoid a leak in case excessive notices are generated, only the last
50 messages are kept.</p>
<p>You can configure what messages to receive using <a class="reference external" href="http://www.postgresql.org/docs/current/static/runtime-config-logging.html">PostgreSQL logging
configuration parameters</a> such as <code class="docutils literal"><span class="pre">log_statement</span></code>,
<code class="docutils literal"><span class="pre">client_min_messages</span></code>, <code class="docutils literal"><span class="pre">log_min_duration_statement</span></code> etc.</p>
</dd></dl>

<dl class="attribute">
<dt id="connection.notifies">
<code class="descname">notifies</code><a class="headerlink" href="#connection.notifies" title="Permalink to this definition"></a></dt>
<dd><p>List of <code class="xref py py-obj docutils literal"><span class="pre">Notify</span></code> objects containing asynchronous
notifications received by the session.</p>
<p>For other details see <a class="reference internal" href="advanced.html#async-notify"><span>Asynchronous notifications</span></a>.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.3: </span>Notifications are instances of the <code class="xref py py-obj docutils literal"><span class="pre">Notify</span></code> object. Previously the
list was composed by 2 items tuples <code class="samp docutils literal"><span class="pre">(</span><em><span class="pre">pid</span></em><span class="pre">,</span><em><span class="pre">channel</span></em><span class="pre">)</span></code> and
the payload was not accessible. To keep backward compatibility,
<code class="xref py py-obj docutils literal"><span class="pre">Notify</span></code> objects can still be accessed as 2 items tuples.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="connection.cursor_factory">
<code class="descname">cursor_factory</code><a class="headerlink" href="#connection.cursor_factory" title="Permalink to this definition"></a></dt>
<dd><p>The default cursor factory used by <a class="reference internal" href="#connection.cursor" title="connection.cursor"><code class="xref py py-obj docutils literal"><span class="pre">cursor()</span></code></a> if the
parameter is not specified.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.5.</span></p>
</div>
</dd></dl>

<span class="target" id="index-12"></span><dl class="method">
<dt id="connection.get_backend_pid">
<code class="descname">get_backend_pid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.get_backend_pid" title="Permalink to this definition"></a></dt>
<dd><p>Returns the process ID (PID) of the backend server process handling
this connection.</p>
<p>Note that the PID belongs to a process executing on the database
server host, not the local host!</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">libpq docs for <a class="reference external" href="http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQBACKENDPID">PQbackendPID()</a> for details.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.8.</span></p>
</div>
</dd></dl>

<span class="target" id="index-13"></span><dl class="method">
<dt id="connection.get_parameter_status">
<code class="descname">get_parameter_status</code><span class="sig-paren">(</span><em>parameter</em><span class="sig-paren">)</span><a class="headerlink" href="#connection.get_parameter_status" title="Permalink to this definition"></a></dt>
<dd><p>Look up a current parameter setting of the server.</p>
<p>Potential values for <code class="docutils literal"><span class="pre">parameter</span></code> are: <code class="docutils literal"><span class="pre">server_version</span></code>,
<code class="docutils literal"><span class="pre">server_encoding</span></code>, <code class="docutils literal"><span class="pre">client_encoding</span></code>, <code class="docutils literal"><span class="pre">is_superuser</span></code>,
<code class="docutils literal"><span class="pre">session_authorization</span></code>, <code class="docutils literal"><span class="pre">DateStyle</span></code>, <code class="docutils literal"><span class="pre">TimeZone</span></code>,
<code class="docutils literal"><span class="pre">integer_datetimes</span></code>, and <code class="docutils literal"><span class="pre">standard_conforming_strings</span></code>.</p>
<p>If server did not report requested parameter, return <code class="xref py py-obj docutils literal"><span class="pre">None</span></code>.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">libpq docs for <a class="reference external" href="http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQPARAMETERSTATUS">PQparameterStatus()</a> for details.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.12.</span></p>
</div>
</dd></dl>

<span class="target" id="index-14"></span><dl class="method">
<dt id="connection.get_transaction_status">
<code class="descname">get_transaction_status</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.get_transaction_status" title="Permalink to this definition"></a></dt>
<dd><p>Return the current session transaction status as an integer.  Symbolic
constants for the values are defined in the module
<a class="reference internal" href="extensions.html#module-psycopg2.extensions" title="psycopg2.extensions"><code class="xref py py-obj docutils literal"><span class="pre">psycopg2.extensions</span></code></a>: see <a class="reference internal" href="extensions.html#transaction-status-constants"><span>Transaction status constants</span></a>
for the available values.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">libpq docs for <a class="reference external" href="http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQTRANSACTIONSTATUS">PQtransactionStatus()</a> for details.</p>
</div>
</dd></dl>

<span class="target" id="index-15"></span><dl class="attribute">
<dt id="connection.protocol_version">
<code class="descname">protocol_version</code><a class="headerlink" href="#connection.protocol_version" title="Permalink to this definition"></a></dt>
<dd><p>A read-only integer representing frontend/backend protocol being used.
Currently Psycopg supports only protocol 3, which allows connection
to PostgreSQL server from version 7.4. Psycopg versions previous than
2.3 support both protocols 2 and 3.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">libpq docs for <a class="reference external" href="http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQPROTOCOLVERSION">PQprotocolVersion()</a> for details.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.12.</span></p>
</div>
</dd></dl>

<span class="target" id="index-16"></span><dl class="attribute">
<dt id="connection.server_version">
<code class="descname">server_version</code><a class="headerlink" href="#connection.server_version" title="Permalink to this definition"></a></dt>
<dd><p>A read-only integer representing the backend version.</p>
<p>The number is formed by converting the major, minor, and revision
numbers into two-decimal-digit numbers and appending them together.
For example, version 8.1.5 will be returned as <code class="docutils literal"><span class="pre">80105</span></code>.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">libpq docs for <a class="reference external" href="http://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQSERVERVERSION">PQserverVersion()</a> for details.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.12.</span></p>
</div>
</dd></dl>

<span class="target" id="index-17"></span><dl class="attribute">
<dt id="connection.status">
<code class="descname">status</code><a class="headerlink" href="#connection.status" title="Permalink to this definition"></a></dt>
<dd><p>A read-only integer representing the status of the connection.
Symbolic constants for the values are defined in the module
<a class="reference internal" href="extensions.html#module-psycopg2.extensions" title="psycopg2.extensions"><code class="xref py py-obj docutils literal"><span class="pre">psycopg2.extensions</span></code></a>: see <a class="reference internal" href="extensions.html#connection-status-constants"><span>Connection status constants</span></a>
for the available values.</p>
<p>The status is undefined for <a class="reference internal" href="#connection.closed" title="connection.closed"><code class="xref py py-obj docutils literal"><span class="pre">closed</span></code></a> connectons.</p>
</dd></dl>

<dl class="method">
<dt id="connection.lobject">
<code class="descname">lobject</code><span class="sig-paren">(</span><span class="optional">[</span><em>oid</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>new_oid</em><span class="optional">[</span>, <em>new_file</em><span class="optional">[</span>, <em>lobject_factory</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.lobject" title="Permalink to this definition"></a></dt>
<dd><p>Return a new database large object as a <a class="reference internal" href="extensions.html#psycopg2.extensions.lobject" title="psycopg2.extensions.lobject"><code class="xref py py-obj docutils literal"><span class="pre">lobject</span></code></a>
instance.</p>
<p>See <a class="reference internal" href="usage.html#large-objects"><span>Access to PostgreSQL large objects</span></a> for an overview.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>oid</strong> &#8211; The OID of the object to read or write. 0 to create
a new large object and and have its OID assigned automatically.</li>
<li><strong>mode</strong> &#8211; Access mode to the object, see below.</li>
<li><strong>new_oid</strong> &#8211; Create a new object using the specified OID. The
function raises <a class="reference internal" href="module.html#psycopg2.OperationalError" title="psycopg2.OperationalError"><code class="xref py py-obj docutils literal"><span class="pre">OperationalError</span></code></a> if the OID is already
in use. Default is 0, meaning assign a new one automatically.</li>
<li><strong>new_file</strong> &#8211; The name of a file to be imported in the the database
(using the <a class="reference external" href="http://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-IMPORT"><code class="xref py py-obj docutils literal"><span class="pre">lo_import()</span></code></a> function)</li>
<li><strong>lobject_factory</strong> &#8211; Subclass of
<a class="reference internal" href="extensions.html#psycopg2.extensions.lobject" title="psycopg2.extensions.lobject"><code class="xref py py-obj docutils literal"><span class="pre">lobject</span></code></a> to be instantiated.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Available values for <em>mode</em> are:</p>
<table border="1" class="docutils">
<colgroup>
<col width="6%" />
<col width="94%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><em>mode</em></th>
<th class="head">meaning</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal"><span class="pre">r</span></code></td>
<td>Open for read only</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">w</span></code></td>
<td>Open for write only</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">rw</span></code></td>
<td>Open for read/write</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">n</span></code></td>
<td>Don&#8217;t open the file</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">b</span></code></td>
<td>Don&#8217;t decode read data (return data as <code class="xref py py-obj docutils literal"><span class="pre">str</span></code> in Python 2 or <code class="xref py py-obj docutils literal"><span class="pre">bytes</span></code> in Python 3)</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">t</span></code></td>
<td>Decode read data according to <a class="reference internal" href="#connection.encoding" title="connection.encoding"><code class="xref py py-obj docutils literal"><span class="pre">connection.encoding</span></code></a> (return data as <code class="xref py py-obj docutils literal"><span class="pre">unicode</span></code> in Python 2 or <code class="xref py py-obj docutils literal"><span class="pre">str</span></code> in Python 3)</td>
</tr>
</tbody>
</table>
<p><code class="docutils literal"><span class="pre">b</span></code> and <code class="docutils literal"><span class="pre">t</span></code> can be specified together with a read/write mode. If
neither <code class="docutils literal"><span class="pre">b</span></code> nor <code class="docutils literal"><span class="pre">t</span></code> is specified, the default is <code class="docutils literal"><span class="pre">b</span></code> in Python 2
and <code class="docutils literal"><span class="pre">t</span></code> in Python 3.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.8.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.4: </span>added <code class="docutils literal"><span class="pre">b</span></code> and <code class="docutils literal"><span class="pre">t</span></code> mode and unicode
support.</p>
</div>
</dd></dl>

<p class="rubric">Methods related to asynchronous support.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.2.0.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="advanced.html#async-support"><span>Asynchronous support</span></a> and <a class="reference internal" href="advanced.html#green-support"><span>Support for coroutine libraries</span></a>.</p>
</div>
<dl class="attribute">
<dt id="connection.async">
<code class="descname">async</code><a class="headerlink" href="#connection.async" title="Permalink to this definition"></a></dt>
<dd><p>Read only attribute: 1 if the connection is asynchronous, 0 otherwise.</p>
</dd></dl>

<dl class="method">
<dt id="connection.poll">
<code class="descname">poll</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.poll" title="Permalink to this definition"></a></dt>
<dd><p>Used during an asynchronous connection attempt, or when a cursor is
executing a query on an asynchronous connection, make communication
proceed if it wouldn&#8217;t block.</p>
<p>Return one of the constants defined in <a class="reference internal" href="extensions.html#poll-constants"><span>Poll constants</span></a>. If it
returns <a class="reference internal" href="extensions.html#psycopg2.extensions.POLL_OK" title="psycopg2.extensions.POLL_OK"><code class="xref py py-obj docutils literal"><span class="pre">POLL_OK</span></code></a> then the connection has been
established or the query results are available on the client.
Otherwise wait until the file descriptor returned by <a class="reference internal" href="#connection.fileno" title="connection.fileno"><code class="xref py py-obj docutils literal"><span class="pre">fileno()</span></code></a> is
ready to read or to write, as explained in <a class="reference internal" href="advanced.html#async-support"><span>Asynchronous support</span></a>.
<a class="reference internal" href="#connection.poll" title="connection.poll"><code class="xref py py-obj docutils literal"><span class="pre">poll()</span></code></a> should be also used by the function installed by
<code class="xref py py-obj docutils literal"><span class="pre">set_wait_callback()</span></code> as explained in
<a class="reference internal" href="advanced.html#green-support"><span>Support for coroutine libraries</span></a>.</p>
<p><a class="reference internal" href="#connection.poll" title="connection.poll"><code class="xref py py-obj docutils literal"><span class="pre">poll()</span></code></a> is also used to receive asynchronous notifications from the
database: see <a class="reference internal" href="advanced.html#async-notify"><span>Asynchronous notifications</span></a> from further details.</p>
</dd></dl>

<dl class="method">
<dt id="connection.fileno">
<code class="descname">fileno</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.fileno" title="Permalink to this definition"></a></dt>
<dd><p>Return the file descriptor underlying the connection: useful to read
its status during asynchronous communication.</p>
</dd></dl>

<dl class="method">
<dt id="connection.isexecuting">
<code class="descname">isexecuting</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#connection.isexecuting" title="Permalink to this definition"></a></dt>
<dd><p>Return <code class="xref py py-obj docutils literal"><span class="pre">True</span></code> if the connection is executing an asynchronous operation.</p>
</dd></dl>

</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="module.html"
                        title="previous chapter">The <code class="docutils literal"><span class="pre">psycopg2</span></code> module content</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="cursor.html"
                        title="next chapter">The <code class="docutils literal"><span class="pre">cursor</span></code> class</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/connection.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <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" role="navigation" aria-label="related navigation">
      <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="cursor.html" title="The cursor class"
             >next</a> |</li>
        <li class="right" >
          <a href="module.html" title="The psycopg2 module content"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Psycopg 2.0 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2001-2016, Federico Di Gregorio, Daniele Varrazzo.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.4.
    </div>
  </body>
</html>