Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit370186e

Browse files
committed
Update libpq documentation for PQconndefaults() change. Add section
about thread-safeness of the library.
1 parenta71daab commit370186e

File tree

1 file changed

+65
-26
lines changed

1 file changed

+65
-26
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ PGconn *PQconnectdb(const char *conninfo)
182182
The return value is a pointer to an abstract struct
183183
representing the connection to the backend.
184184
</para>
185-
<para>
186-
This function is not thread-safe.
187-
</para>
188185
</listitem>
189186

190187
<listitem>
@@ -204,9 +201,6 @@ PGconn *PQsetdbLogin(const char *pghost,
204201
This is the predecessor of <function>PQconnectdb</function> with a fixed number
205202
of parameters but the same functionality.
206203
</para>
207-
<para>
208-
This function is not thread-safe.
209-
</para>
210204
</listitem>
211205

212206
<listitem>
@@ -380,9 +374,6 @@ PostgresPollingStatusType *PQconnectPoll(PQconn *conn)
380374
These functions leave the socket in a non-blocking state as if
381375
<function>PQsetnonblocking</function> had been called.
382376
</para>
383-
<para>
384-
These functions are not thread-safe.
385-
</para>
386377
</listitem>
387378

388379
<listitem>
@@ -396,18 +387,17 @@ struct PQconninfoOption
396387
char *keyword; /* The keyword of the option */
397388
char *envvar; /* Fallback environment variable name */
398389
char *compiled; /* Fallback compiled in default value */
399-
char *val; /* Option's value */
390+
char *val; /* Option'scurrentvalue, or NULL */
400391
char *label; /* Label for field in connect dialog */
401392
char *dispchar; /* Character to display for this field
402393
in a connect dialog. Values are:
403394
"" Display entered value as is
404395
"*" Password field - hide value
405-
"D" Debug options - don't
406-
create a field by default */
396+
"D" Debug option - don't show by default */
407397
int dispsize; /* Field size in characters for dialog */
408398
}
409399
</synopsis>
410-
Returnsthe address of theconnection optionsstructure. This may
400+
Returnsaconnection optionsarray. This may
411401
be used to determine all possible PQconnectdb options and their
412402
current default values. The return value points to an array of
413403
PQconninfoOption structs, which ends with an entry having a NULL
@@ -416,7 +406,14 @@ struct PQconninfoOption
416406
Callers must treat the connection options data as read-only.
417407
</para>
418408
<para>
419-
This function is not thread-safe.
409+
After processing the options array, free it by passing it to
410+
PQconninfoFree(). If this is not done, a small amount of memory
411+
is leaked for each call to PQconndefaults().
412+
</para>
413+
<para>
414+
In PostgreSQL versions before 7.0, PQconndefaults() returned a pointer
415+
to a static array, rather than a dynamically allocated array. That
416+
wasn't thread-safe, so the behavior has been changed.
420417
</para>
421418
</listitem>
422419

@@ -675,9 +672,6 @@ void PQsetenvAbort(PGsetenvHandle handle)
675672
<para>
676673
The procedure may be aborted at any time by calling PQsetenvAbort(handle).
677674
</para>
678-
<para>
679-
These functions are not thread-safe.
680-
</para>
681675
</listitem>
682676

683677
<listitem>
@@ -1019,7 +1013,7 @@ char * PQcmdTuples(const PGresult *res);
10191013
<synopsis>
10201014
Oid PQoidValue(const PGresult *res);
10211015
</synopsis>
1022-
The type <type>Oid</type> and the constant <literal>Invalid</literal>
1016+
The type <type>Oid</type> and the constant <literal>InvalidOid</literal>
10231017
will be defined if you include the <application>libpq</application>
10241018
header file. They will both be some integer type.
10251019
</para>
@@ -1034,7 +1028,7 @@ Oid PQoidValue(const PGresult *res);
10341028
<synopsis>
10351029
char * PQoidStatus(const PGresult *res);
10361030
</synopsis>
1037-
The function is deprecated in favor of <function>PQoidValue</function>
1031+
This function is deprecated in favor of <function>PQoidValue</function>
10381032
and is not thread-safe.
10391033
</para>
10401034
</listitem>
@@ -1773,13 +1767,14 @@ PQsetNoticeProcessor(PGconn *conn,
17731767
</para>
17741768

17751769
<para>
1776-
By default, <application>libpq</application> prints <quote>notice</quote> messages
1777-
from the backendas well as a few error messages that it generates by itself
1778-
on <filename>stderr</filename>.
1770+
By default, <application>libpq</application> prints <quote>notice</quote>
1771+
messagesfrom the backendon <filename>stderr</filename>,
1772+
as well as a few error messages that it generates by itself.
17791773
This behavior can be overridden by supplying a callback function that
17801774
does something else with the messages. The callback function is passed
17811775
the text of the error message (which includes a trailing newline), plus
1782-
a void pointer that is the same one passed to <function>PQsetNoticeProcessor</function>.
1776+
a void pointer that is the same one passed to
1777+
<function>PQsetNoticeProcessor</function>.
17831778
(This pointer can be used to access application-specific state if needed.)
17841779
The default notice processor is simply
17851780
<programlisting>
@@ -1789,13 +1784,23 @@ defaultNoticeProcessor(void * arg, const char * message)
17891784
fprintf(stderr, "%s", message);
17901785
}
17911786
</programlisting>
1792-
To use a special notice processor, call <function>PQsetNoticeProcessor</function> just after
1787+
To use a special notice processor, call
1788+
<function>PQsetNoticeProcessor</function> just after
17931789
creation of a new PGconn object.
17941790
</para>
17951791

17961792
<para>
1797-
The return value is the pointer to the previous notice processor. If you supply a callback
1798-
function pointer of NULL, no action is taken, but the current pointer is returned.
1793+
The return value is the pointer to the previous notice processor.
1794+
If you supply a callback function pointer of NULL, no action is taken,
1795+
but the current pointer is returned.
1796+
</para>
1797+
1798+
<para>
1799+
Once you have set a notice processor, you should expect that that function
1800+
could be called as long as either the PGconn object or PGresult objects
1801+
made from it exist. At creation of a PGresult, the PGconn's current
1802+
notice processor pointer is copied into the PGresult for possible use by
1803+
routines like <function>PQgetvalue</function>.
17991804
</para>
18001805

18011806
</sect1>
@@ -1886,6 +1891,13 @@ sets the default style of date/time representation.
18861891
sets the default time zone.
18871892
</para>
18881893
</listitem>
1894+
<listitem>
1895+
<para>
1896+
<envar>PGCLIENTENCODING</envar>
1897+
sets the default client encoding (if MULTIBYTE support was selected
1898+
when configuring Postgres).
1899+
</para>
1900+
</listitem>
18891901
</itemizedlist>
18901902
</para>
18911903

@@ -1910,6 +1922,33 @@ for information on correct values for these environment variables.
19101922

19111923
</sect1>
19121924

1925+
<sect1 id="libpq-threading">
1926+
<title>Threading Behavior</title>
1927+
1928+
<para>
1929+
<filename>libpq</filename> is thread-safe as of
1930+
<productname>PostgreSQL</productname> 7.0, so long as no two threads
1931+
attempt to manipulate the same PGconn object at the same time. In particular,
1932+
you can't issue concurrent queries from different threads through the same
1933+
connection object. (If you need to run concurrent queries, start up multiple
1934+
connections.)
1935+
</para>
1936+
1937+
<para>
1938+
PGresult objects are read-only after creation, and so can be passed around
1939+
freely between threads.
1940+
</para>
1941+
1942+
<para>
1943+
The deprecated functions <function>PQoidStatus</function> and
1944+
<function>fe_setauthsvc</function> are not thread-safe and should not be
1945+
used in multi-thread programs. <function>PQoidStatus</function> can be
1946+
replaced by <function>PQoidValue</function>. There is no good reason to
1947+
call <function>fe_setauthsvc</function> at all.
1948+
</para>
1949+
1950+
</sect1>
1951+
19131952
<sect1>
19141953
<title>Sample Programs</title>
19151954

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp