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

Commite7243dc

Browse files
committed
Add description of SSL request protocol. Miscellaneous copy-editing.
1 parent24451cd commite7243dc

File tree

1 file changed

+191
-60
lines changed

1 file changed

+191
-60
lines changed

‎doc/src/sgml/protocol.sgml

Lines changed: 191 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.22 2001/11/21 05:53:41 thomas Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.23 2001/11/22 01:22:10 tgl Exp $ -->
22

33
<chapter id="protocol">
44
<title>Frontend/Backend Protocol</title>
@@ -38,7 +38,7 @@
3838

3939
<para>
4040
A frontend opens a connection to the server and sends a start-up
41-
packet. This includes the names of the user and the database the
41+
packet. This includes the names of the user andofthe database the
4242
user wants to connect to. The server then uses this, and the
4343
information in the <filename>pg_hba.conf</filename> file to
4444
determine what further authentication information it requires the
@@ -53,19 +53,15 @@
5353
</para>
5454

5555
<para>
56-
In order to serve multiple clients efficiently, the server would
57-
normally create a new child process to handle each incoming
58-
connection. However, this is not required. In the current
59-
implementation, a new child process is created immediately after an
60-
incoming connection is detected. In earlier versions of
61-
<productname>PostgreSQL</>
62-
(7.1 and earlier), the child process was created after sending the
63-
authentication confirmation message.
56+
In order to serve multiple clients efficiently, the server launches
57+
a new <quote>backend</> process for each client. This is transparent
58+
to the protocol, however. In the current implementation, a new child
59+
process is created immediately after an incoming connection is detected.
6460
</para>
6561

6662
<para>
6763
When the frontend wishes to disconnect it sends an appropriate packet and
68-
closes the connection without waiting for a responsefor the backend.
64+
closes the connection without waiting for a responsefrom the backend.
6965
</para>
7066

7167
<para>
@@ -319,47 +315,26 @@
319315
<Term>CursorResponse</Term>
320316
<ListItem>
321317
<Para>
322-
The query was either an <literal>INSERT</literal>,
323-
<literal>UPDATE</literal>, <literal>DELETE</literal>,
324-
<literal>FETCH</literal>, or a <literal>SELECT</literal>
325-
command. If the transaction has been aborted then the backend
326-
sends a CompletedResponse message with a tag of <literal>*ABORT
327-
STATE*</literal>. Otherwise the following responses are sent.
328-
</Para>
329-
330-
<Para>
331-
For an <literal>INSERT</literal> command, the backend then
332-
sends a CompletedResponse message with a tag of
333-
<literal>INSERT <replaceable>oid</replaceable>
334-
<replaceable>rows</replaceable></literal>, where
335-
<replaceable>rows</replaceable> is the number of rows
336-
inserted, and <replaceable>oid</replaceable> is the object ID
337-
of the inserted row if <Replaceable>rows</Replaceable> is 1,
338-
otherwise <Replaceable>oid</Replaceable> is 0.
339-
</Para>
340-
341-
<Para>
342-
For a <literal>DELETE</literal> command, the backend then
343-
sends a CompletedResponse message with a tag of <literal>DELETE
344-
<Replaceable>rows</Replaceable></literal> where
345-
<Replaceable>rows</Replaceable> is the number of rows deleted.
346-
</Para>
347-
348-
<Para>
349-
For an <literal>UPDATE</literal> command, the backend then
350-
sends a CompletedResponse message with a tag of <literal>UPDATE
351-
<Replaceable>rows</Replaceable></literal> where
352-
<Replaceable>rows</Replaceable> is the number of rows affected
353-
by the update.
318+
Beginning of the response to a <command>SELECT</command>,
319+
<command>FETCH</command>, <command>INSERT</command>,
320+
<command>UPDATE</command>, or <command>DELETE</command>
321+
query. In the <command>FETCH</command> case the name of the
322+
cursor being fetched from is included in the message. Otherwise
323+
the message always mentions the <quote>blank</> cursor.
354324
</Para>
325+
</ListItem>
326+
</VarListEntry>
355327

328+
<VarListEntry>
329+
<Term>RowDescription</Term>
330+
<ListItem>
356331
<Para>
357-
For a <literal>FETCH</literal> or <literal>SELECT</literal>
358-
command, the backend sends a RowDescription message. This is
359-
then followed by an AsciiRow or BinaryRow message (depending
360-
on whether a binary cursor was specified) for each row being
361-
returned to the frontend. Finally, the backend sends a
362-
CompletedResponse message with a tag of <literal>SELECT</literal>.
332+
Indicates that rows are about to be returned in response to
333+
a <command>SELECT</command> or <command>FETCH</command> query.
334+
The message contents describe the layout of the rows. This
335+
will be followed by an AsciiRow or BinaryRow message (depending on
336+
whether a binary cursor was specified) for each row being returned
337+
to the frontend.
363338
</Para>
364339
</ListItem>
365340
</VarListEntry>
@@ -368,8 +343,7 @@
368343
<Term>EmptyQueryResponse</Term>
369344
<ListItem>
370345
<Para>
371-
An empty query string was recognized. (The need to specially
372-
distinguish this case is historical.)
346+
An empty query string was recognized.
373347
</Para>
374348
</ListItem>
375349
</VarListEntry>
@@ -411,6 +385,41 @@
411385
</VariableList>
412386
</Para>
413387

388+
<Para>
389+
The response to a <command>SELECT</> or <command>FETCH</> query
390+
normally consists of CursorResponse, RowDescription, zero or more
391+
AsciiRow or BinaryRow messages, and finally CompletedResponse.
392+
<command>INSERT</command>, <command>UPDATE</command>, and
393+
<command>DELETE</command> queries produce CursorResponse followed by
394+
CompletedResponse.
395+
<command>COPY</> to or from the frontend invokes special protocol
396+
as mentioned above.
397+
All other query types normally produce only
398+
a CompletedResponse message.
399+
</Para>
400+
401+
<Para>
402+
Since a query string could contain several queries (separated by
403+
semicolons), there might be several such response sequences before the
404+
backend finishes processing the query string. ReadyForQuery is issued
405+
when the entire string has been processed and the backend is ready to
406+
accept a new query string.
407+
</Para>
408+
409+
<Para>
410+
If a completely empty (no contents other than whitespace) query string
411+
is received, the response is EmptyQueryResponse followed by ReadyForQuery.
412+
(The need to specially distinguish this case is historical.)
413+
</Para>
414+
415+
<Para>
416+
In the event of an error, ErrorResponse is issued followed by
417+
ReadyForQuery. All further processing of the query string is aborted by
418+
ErrorResponse (even if more queries remained in it). Note that this
419+
may occur partway through the sequence of messages generated by an
420+
individual query.
421+
</Para>
422+
414423
<para>
415424
A frontend must be prepared to accept ErrorResponse and
416425
NoticeResponse messages whenever it is expecting any other type of
@@ -428,10 +437,16 @@
428437
</para>
429438

430439
<Para>
431-
Also, if the frontend issues any <literal>LISTEN</literal>
440+
Also, if the frontend issues any <command>LISTEN</command>
432441
commands then it must be prepared to accept NotificationResponse
433442
messages at any time; see below.
434443
</para>
444+
445+
<para>
446+
Recommended practice is to code frontends in a state-machine style
447+
that will accept any message type at any time that it could make sense,
448+
rather than wiring in assumptions about the exact sequence of messages.
449+
</para>
435450
</sect2>
436451

437452
<Sect2>
@@ -504,7 +519,7 @@
504519
<para>
505520
A frontend must be prepared to accept ErrorResponse and
506521
NoticeResponse messages whenever it is expecting any other type of
507-
message. Also, if it issues any <literal>LISTEN</literal>
522+
message. Also, if it issues any <command>LISTEN</command>
508523
commands then it must be prepared to accept NotificationResponse
509524
messages at any time; see below.
510525
</para>
@@ -514,10 +529,10 @@
514529
<title>Notification Responses</title>
515530

516531
<Para>
517-
If a frontend issues a <literal>LISTEN</literal> command, then the
532+
If a frontend issues a <command>LISTEN</command> command, then the
518533
backend will send a NotificationResponse message (not to be
519534
confused with NoticeResponse!) whenever a
520-
<literal>NOTIFY</literal> command is executed for the same
535+
<command>NOTIFY</command> command is executed for the same
521536
notification name.
522537
</para>
523538

@@ -534,8 +549,8 @@
534549
<Term>NotificationResponse</Term>
535550
<ListItem>
536551
<Para>
537-
A <literal>NOTIFY</literal> command has been executed for a
538-
name for which a previous <literal>LISTEN</literal> command
552+
A <command>NOTIFY</command> command has been executed for a
553+
name for which a previous <command>LISTEN</command> command
539554
was executed. Notifications may be sent at any time.
540555
</Para>
541556
</ListItem>
@@ -579,7 +594,7 @@
579594
same key data (PID and secret key) passed to the frontend during
580595
connection start-up. If the request matches the PID and secret
581596
key for a currently executing backend, the processing of the
582-
current query is aborted. (In the existingimplemenation, this is
597+
current query is aborted. (In the existingimplementation, this is
583598
done by sending a special signal to the backend process that is
584599
processing the query.)
585600
</para>
@@ -633,6 +648,61 @@
633648
by recontacting the server if it doesn't want to terminate
634649
itself.
635650
</para>
651+
652+
<para>
653+
For either normal or abnormal termination, any open transaction is
654+
rolled back, not committed. One should note however that if a
655+
frontend disconnects while a query is being processed, the backend
656+
will probably finish the query before noticing the disconnection.
657+
If the query is outside any transaction block (<command>BEGIN</>
658+
... <command>COMMIT</> sequence) then its results may be committed
659+
before the disconnection is recognized.
660+
</para>
661+
</sect2>
662+
663+
<Sect2>
664+
<Title>SSL Session Encryption</Title>
665+
666+
<Para>
667+
Recent releases of <productname>PostgreSQL</> allow frontend/backend
668+
communication to be encrypted using SSL. This provides communication
669+
security in environments where attackers might be able to capture the
670+
session traffic.
671+
</para>
672+
673+
<para>
674+
To initiate an SSL-encrypted connection, the frontend initially sends
675+
an SSLRequest message rather than a StartupPacket. The server then
676+
responds with a single byte containing <literal>Y</> or <literal>N</>,
677+
indicating that it is willing or unwilling to perform SSL, respectively.
678+
The frontend may close the connection at this point if it is dissatisfied
679+
with the response. To continue after <literal>Y</>, perform an SSL
680+
startup handshake (not described here, part of the SSL specification)
681+
with the server. If this is successful, continue with
682+
sending the usual StartupPacket. In this case the StartupPacket and
683+
all subsequent data will be SSL-encrypted. To continue after
684+
<literal>N</>, send the usual StartupPacket and proceed without
685+
encryption.
686+
</para>
687+
688+
<para>
689+
The frontend should also be prepared to handle an ErrorMessage response
690+
to SSLRequest from the server. This would only occur if the server
691+
predates the addition of SSL support to <productname>PostgreSQL</>.
692+
In this case the connection must be closed, but the frontend may choose
693+
to open a fresh connection and proceed without requesting SSL.
694+
</para>
695+
696+
<para>
697+
An initial SSLRequest may also be used in a connection that is being
698+
opened to send a CancelRequest message.
699+
</para>
700+
701+
<para>
702+
While the protocol itself does not provide a way for the server to
703+
force SSL encryption, the administrator may configure the server to
704+
reject unencrypted sessions as a byproduct of authentication checking.
705+
</para>
636706
</sect2>
637707
</sect1>
638708

@@ -1240,8 +1310,30 @@ CompletedResponse (B)
12401310
</Term>
12411311
<ListItem>
12421312
<Para>
1243-
The command tag. This is usually (but not always) a single
1244-
word that identifies which SQL command was completed.
1313+
The command tag. This is usually a single
1314+
word that identifies which SQL command was completed.
1315+
</Para>
1316+
1317+
<Para>
1318+
For an <command>INSERT</command> command, the tag is
1319+
<literal>INSERT <replaceable>oid</replaceable>
1320+
<replaceable>rows</replaceable></literal>, where
1321+
<replaceable>rows</replaceable> is the number of rows
1322+
inserted, and <replaceable>oid</replaceable> is the object ID
1323+
of the inserted row if <Replaceable>rows</Replaceable> is 1,
1324+
otherwise <Replaceable>oid</Replaceable> is 0.
1325+
</Para>
1326+
1327+
<Para>
1328+
For a <command>DELETE</command> command, the tag is
1329+
<literal>DELETE <Replaceable>rows</Replaceable></literal> where
1330+
<Replaceable>rows</Replaceable> is the number of rows deleted.
1331+
</Para>
1332+
1333+
<Para>
1334+
For an <command>UPDATE</command> command, the tag is
1335+
<literal>UPDATE <Replaceable>rows</Replaceable></literal> where
1336+
<Replaceable>rows</Replaceable> is the number of rows updated.
12451337
</Para>
12461338
</ListItem>
12471339
</VarListEntry>
@@ -1853,6 +1945,44 @@ RowDescription (B)
18531945
</Para>
18541946
</ListItem>
18551947
</VarListEntry>
1948+
1949+
<VarListEntry>
1950+
<Term>
1951+
SSLRequest (F)
1952+
</Term>
1953+
<ListItem>
1954+
<Para>
1955+
1956+
<VariableList>
1957+
<VarListEntry>
1958+
<Term>
1959+
Int32(8)
1960+
</Term>
1961+
<ListItem>
1962+
<Para>
1963+
The size of the packet in bytes.
1964+
</Para>
1965+
</ListItem>
1966+
</VarListEntry>
1967+
<VarListEntry>
1968+
<Term>
1969+
Int32(80877103)
1970+
</Term>
1971+
<ListItem>
1972+
<Para>
1973+
The SSL request code. The value is chosen to contain
1974+
<literal>1234</> in the most significant 16 bits, and <literal>5679</> in the
1975+
least 16 significant bits. (To avoid confusion, this code
1976+
must not be the same as any protocol version number.)
1977+
</Para>
1978+
</ListItem>
1979+
</VarListEntry>
1980+
</VariableList>
1981+
1982+
</Para>
1983+
</ListItem>
1984+
</VarListEntry>
1985+
18561986
<VarListEntry>
18571987
<Term>
18581988
StartupPacket (F)
@@ -1931,6 +2061,7 @@ StartupPacket (F)
19312061
<ListItem>
19322062
<Para>
19332063
The optional tty the backend should use for debugging messages.
2064+
(Currently, this field is unsupported and ignored.)
19342065
</Para>
19352066
</ListItem>
19362067
</VarListEntry>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp