Skip to content

Commit e48f653

Browse files
author
James William Pye
committed
Include html build in repository.
This should help simplify the release process, and enables people to read the development documentation without having sphinx installed.
1 parent 4e2ef4f commit e48f653

48 files changed

Lines changed: 9842 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ include LICENSE
33
recursive-include postgresql *.c
44
recursive-include postgresql *.sql
55
recursive-include postgresql *.txt
6-
recursive-include sphinx-src Makefile *.rst conf.py
6+
recursive-include postgresql/documentation/sphinx *.rst conf.py
7+
recursive-include postgresql/documentation/html *
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.buildinfo
2+
objects.inv
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Administration
2+
==============
3+
4+
This chapter covers the administration of py-postgresql. This includes
5+
installation and other aspects of working with py-postgresql such as
6+
environment variables and configuration files.
7+
8+
9+
Installation
10+
------------
11+
12+
py-postgresql uses Python's standard distutils package to manage the
13+
build and installation process of the package. The normal entry point for
14+
this is the ``setup.py`` script contained in the root project directory.
15+
16+
After extracting the archive and changing the into the project's directory,
17+
installation is normally as simple as::
18+
19+
$ python3 ./setup.py install
20+
21+
However, if you need to install for use with a particular version of python,
22+
just use the path of the executable that should be used::
23+
24+
$ /usr/opt/bin/python3 ./setup.py install
25+
26+
Under most POSIX systems, the above should work without problem if the proper
27+
Python executable is referenced. However, if it does fail, it is likely due
28+
to a C extension's inability to compile.
29+
30+
The building of C extensions can be disable using the ``PY_BUILD_EXTENSIONS``
31+
environment variable::
32+
33+
$ env PY_BUILD_EXTENSIONS=0 python3 ./setup.py install
34+
35+
36+
Extension Modules under Windows
37+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
39+
By default, a Python installation on Windows cannot build extension modules.
40+
py-postgresql provides optimizations for various key points, but can be
41+
installed and used without them. When a source installation is performed on
42+
'win32' systems, extension modules are *not* built by default.
43+
44+
In order to enable the compilation of extensions, set the environment variable
45+
``PY_BUILD_EXTENSIONS`` to '1' before executing the ``setup.py``
46+
script in the prompt::
47+
48+
C:\-> set PY_BUILD_EXTENSIONS=1
49+
C:\-> c:\python31\python setup.py install
50+
51+
Or, compile using mingw32::
52+
53+
C:\-> set PY_BUILD_EXTENSIONS=1
54+
C:\-> c:\python31\python setup.py build_ext --compiler=mingw32
55+
C:\-> c:\python31\python setup.py install
56+
57+
See http://www.mingw.org/ to get the compiler.
58+
59+
60+
Environment
61+
-----------
62+
63+
These environment variables effect the operation of the package:
64+
65+
============== ===============================================================================
66+
PGINSTALLATION The path to the ``pg_config`` executable of the installation to use by default.
67+
============== ===============================================================================
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
.. _alock:
2+
3+
**************
4+
Advisory Locks
5+
**************
6+
7+
`Explicit Locking in PostgreSQL <http://www.postgresql.org/docs/current/static/explicit-locking.html#ADVISORY-LOCKS>`_.
8+
9+
PostgreSQL's advisory locks offer a cooperative synchronization primitive.
10+
These are used in cases where an application needs access to a resource, but
11+
using table locks may cause interference with other operations that can be
12+
safely performed alongside the application-level, exclusive operation.
13+
14+
Advisory locks can be used by directly executing the stored procedures in the
15+
database or by using the :class:`postgresql.alock.ALock` subclasses, which
16+
provides a context manager that uses those stored procedures.
17+
18+
Currently, only two subclasses exist. Each represents the lock mode
19+
supported by PostgreSQL's advisory locks:
20+
21+
* :class:`postgresql.alock.ShareLock`
22+
* :class:`postgresql.alock.ExclusiveLock`
23+
24+
25+
Acquiring ALocks
26+
================
27+
28+
An ALock instance represents a sequence of advisory locks. A single ALock can
29+
acquire and release multiple advisory locks by creating the instance with
30+
multiple lock identifiers::
31+
32+
>>> from postgresql import alock
33+
>>> table1_oid = 192842
34+
>>> table2_oid = 192849
35+
>>> l = alock.ExclusiveLock(db, (table1_oid, 0), (table2_oid, 0))
36+
>>> l.acquire()
37+
>>> ...
38+
>>> l.release()
39+
40+
:class:`postgresql.alock.ALock` is similar to :class:`threading.RLock`; in
41+
order for an ALock to be released, it must be released the number of times it
42+
has been acquired. ALocks are associated with and survived by their session.
43+
Much like how RLocks are associated with the thread they are acquired in:
44+
acquiring an ALock again will merely increment its count.
45+
46+
PostgreSQL allows advisory locks to be identified using a pair of `int4` or a
47+
single `int8`. ALock instances represent a *sequence* of those identifiers::
48+
49+
>>> from postgresql import alock
50+
>>> ids = [(0,0), 0, 1]
51+
>>> with alock.ShareLock(db, *ids):
52+
... ...
53+
54+
Both types of identifiers may be used within the same ALock, and, regardless of
55+
their type, will be aquired in the order that they were given to the class'
56+
constructor. In the above example, ``(0,0)`` is acquired first, then ``0``, and
57+
lastly ``1``.
58+
59+
60+
ALocks
61+
======
62+
63+
`postgresql.alock.ALock` is abstract; it defines the interface and some common
64+
functionality. The lock mode is selected by choosing the appropriate subclass.
65+
66+
There are two:
67+
68+
``postgresql.alock.ExclusiveLock(database, *identifiers)``
69+
Instantiate an ALock object representing the `identifiers` for use with the
70+
`database`. Exclusive locks will conflict with other exclusive locks and share
71+
locks.
72+
73+
``postgresql.alock.ShareLock(database, *identifiers)``
74+
Instantiate an ALock object representing the `identifiers` for use with the
75+
`database`. Share locks can be acquired when a share lock with the same
76+
identifier has been acquired by another backend. However, an exclusive lock
77+
with the same identifier will conflict.
78+
79+
80+
ALock Interface Points
81+
----------------------
82+
83+
Methods and properties available on :class:`postgresql.alock.ALock` instances:
84+
85+
``alock.acquire(blocking = True)``
86+
Acquire the advisory locks represented by the ``alock`` object. If blocking is
87+
`True`, the default, the method will block until locks on *all* the
88+
identifiers have been acquired.
89+
90+
If blocking is `False`, acquisition may not block, and success will be
91+
indicated by the returned object: `True` if *all* lock identifiers were
92+
acquired and `False` if any of the lock identifiers could not be acquired.
93+
94+
``alock.release()``
95+
Release the advisory locks represented by the ``alock`` object. If the lock
96+
has not been acquired, a `RuntimeError` will be raised.
97+
98+
``alock.locked()``
99+
Returns a boolean describing whether the locks are held or not. This will
100+
return `False` if the lock connection has been closed.
101+
102+
``alock.__enter__()``
103+
Alias to ``acquire``; context manager protocol. Always blocking.
104+
105+
``alock.__exit__(typ, val, tb)``
106+
Alias to ``release``; context manager protocol.
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
Commands
2+
********
3+
4+
This chapter discusses the usage of the available console scripts.
5+
6+
7+
postgresql.bin.pg_python
8+
========================
9+
10+
The ``pg_python`` command provides a simple way to write Python scripts against a
11+
single target database. It acts like the regular Python console command, but
12+
takes standard PostgreSQL options as well to specify the client parameters
13+
to make establish connection with. The Python environment is then augmented
14+
with the following built-ins:
15+
16+
``db``
17+
The PG-API connection object.
18+
19+
``xact``
20+
``db.xact``, the transaction creator.
21+
22+
``settings``
23+
``db.settings``
24+
25+
``prepare``
26+
``db.prepare``, the statement creator.
27+
28+
``proc``
29+
``db.proc``
30+
31+
``do``
32+
``db.do``, execute a single DO statement.
33+
34+
``sqlexec``
35+
``db.execute``, execute multiple SQL statements (``None`` is always returned)
36+
37+
pg_python Usage
38+
---------------
39+
40+
Usage: postgresql.bin.pg_python [connection options] [script] ...
41+
42+
Options:
43+
--unix=UNIX path to filesystem socket
44+
--ssl-mode=SSLMODE SSL requirement for connectivity: require, prefer,
45+
allow, disable
46+
-s SETTINGS, --setting=SETTINGS
47+
run-time parameters to set upon connecting
48+
-I PQ_IRI, --iri=PQ_IRI
49+
database locator string
50+
[pq://user:password@host:port/database?setting=value]
51+
-h HOST, --host=HOST database server host
52+
-p PORT, --port=PORT database server port
53+
-U USER, --username=USER
54+
user name to connect as
55+
-W, --password prompt for password
56+
-d DATABASE, --database=DATABASE
57+
database's name
58+
--pq-trace=PQ_TRACE trace PQ protocol transmissions
59+
-C PYTHON_CONTEXT, --context=PYTHON_CONTEXT
60+
Python context code to run[file://,module:,<code>]
61+
-m PYTHON_MAIN Python module to run as script(__main__)
62+
-c PYTHON_MAIN Python expression to run(__main__)
63+
--version show program's version number and exit
64+
--help show this help message and exit
65+
66+
67+
Interactive Console Backslash Commands
68+
--------------------------------------
69+
70+
Inspired by ``psql``::
71+
72+
>>> \?
73+
Backslash Commands:
74+
75+
\? Show this help message.
76+
\E Edit a file or a temporary script.
77+
\e Edit and Execute the file directly in the context.
78+
\i Execute a Python script within the interpreter's context.
79+
\set Configure environment variables. \set without arguments to show all
80+
\x Execute the Python command within this process.
81+
82+
83+
pg_python Examples
84+
------------------
85+
86+
Module execution taking advantage of the new built-ins::
87+
88+
$ python3 -m postgresql.bin.pg_python -h localhost -W -m timeit "prepare('SELECT 1').first()"
89+
Password for pg_python[pq://jwp@localhost:5432]:
90+
1000 loops, best of 3: 1.35 msec per loop
91+
92+
$ python3 -m postgresql.bin.pg_python -h localhost -W -m timeit -s "ps=prepare('SELECT 1')" "ps.first()"
93+
Password for pg_python[pq://jwp@localhost:5432]:
94+
1000 loops, best of 3: 442 usec per loop
95+
96+
Simple interactive usage::
97+
98+
$ python3 -m postgresql.bin.pg_python -h localhost -W
99+
Password for pg_python[pq://jwp@localhost:5432]:
100+
>>> ps = prepare('select 1')
101+
>>> ps.first()
102+
1
103+
>>> c = ps()
104+
>>> c.read()
105+
[(1,)]
106+
>>> ps.close()
107+
>>> import sys
108+
>>> sys.exit(0)
109+
110+
111+
postgresql.bin.pg_dotconf
112+
=========================
113+
114+
pg_dotconf is used to modify a PostgreSQL cluster's configuration file.
115+
It provides a means to apply settings specified from the command line and from a
116+
file referenced using the ``-f`` option.
117+
118+
.. warning::
119+
``include`` directives in configuration files are *completely* ignored. If
120+
modification of an included file is desired, the command must be applied to
121+
that specific file.
122+
123+
124+
pg_dotconf Usage
125+
----------------
126+
127+
Usage: postgresql.bin.pg_dotconf [--stdout] [-f filepath] postgresql.conf ([param=val]|[param])*
128+
129+
Options:
130+
--version show program's version number and exit
131+
-h, --help show this help message and exit
132+
-f SETTINGS, --file=SETTINGS
133+
A file of settings to *apply* to the given
134+
"postgresql.conf"
135+
--stdout Redirect the product to standard output instead of
136+
writing back to the "postgresql.conf" file
137+
138+
139+
Examples
140+
--------
141+
142+
Modifying a simple configuration file::
143+
144+
$ echo "setting = value" >pg.conf
145+
146+
# change 'setting'
147+
$ python3 -m postgresql.bin.pg_dotconf pg.conf setting=newvalue
148+
149+
$ cat pg.conf
150+
setting = 'newvalue'
151+
152+
# new settings are appended to the file
153+
$ python3 -m postgresql.bin.pg_dotconf pg.conf another_setting=value
154+
$ cat pg.conf
155+
setting = 'newvalue'
156+
another_setting = 'value'
157+
158+
# comment a setting
159+
$ python3 -m postgresql.bin.pg_dotconf pg.conf another_setting
160+
161+
$ cat pg.conf
162+
setting = 'newvalue'
163+
#another_setting = 'value'
164+
165+
When a setting is given on the command line, it must been seen as one argument
166+
to the command, so it's *very* important to avoid invocations like::
167+
168+
$ python3 -m postgresql.bin.pg_dotconf pg.conf setting = value
169+
ERROR: invalid setting, '=' after 'setting'
170+
HINT: Settings must take the form 'setting=value' or 'setting_name_to_comment'. Settings must also be received as a single argument.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Changes
2+
=======
3+
4+
1.0 in development
5+
------------------
6+
7+
* **DEPRECATION**: Removed 2PC support documentation.
8+
* **DEPRECATION**: Removed pg_python and pg_dotconf 'scripts'.
9+
They are still accessible by python3 -m postgresql.bin.pg_*
10+
* Added db.do() method for DO-statement support(convenience method).
11+
* Fix handling of unix domain sockets by pg.open and driver.connect.
12+
[Reported by twitter.com/rintavarustus]
13+
* Set the default client_min_messages level to WARNING.
14+
NOTICEs are often not desired by programmers, and py-postgresql's
15+
high verbosity further irritates that case.
16+
* Added postgresql.project module to provide project information.
17+
Project name, author, version, etc.
18+
* Fixed db.tracer and pg_python's --pq-trace=
19+
* Increased default recvsize and chunksize for improved performance.
20+
* 'D' messages are special cased as builtins.tuples instead of
21+
protocol.element3.Tuple
22+
* Alter Statement.chunks() to return chunks of builtins.tuple. Being
23+
an interface intended for speed, types.Row() impedes its performance.
24+
* Fix handling of infinity values with timestamptz, timestamp, and date.
25+
[Bug reported by Axel Rau.]
26+
* Correct representation of PostgreSQL ARRAYs by properly recording
27+
lowerbounds and upperbounds. Internally, sub-ARRAYs have their own
28+
element lists.
29+
* Implement a NotificationManager for managing the NOTIFYs received
30+
by a connection. The class can manage NOTIFYs from multiple
31+
connections, whereas the db.wait() method is tailored for single targets.
32+
* Implement an ALock class for managing advisory locks using the
33+
threading.Lock APIs. [Feedback from Valentine Gogichashvili]
34+
* Implement reference symbols. Allow libraries to define symbols that
35+
are used to create queries that inherit the original symbol's type and
36+
execution method. ``db.prepare(db.prepare(...).first())``
37+
* Fix typo/dropped parts of a raise LoadError in .lib.
38+
[Reported by Vlad Pranskevichus]
39+
* Fix db.tracer and pg_python's --pq-trace=
40+
* Fix count return from .first() method. Failed to provide an empty
41+
tuple for the rformats of the bind statement.
42+
[Reported by dou dou]
43+
* Add support for binary hstore.

0 commit comments

Comments
 (0)