Postgresql 中文操作指南
55.10. Summary of Changes since Protocol 2.0 #
本节提供了更改的快速清单,这将有助于尝试将现有客户端库更新到协议 3.0 的开发者。
This section provides a quick checklist of changes, for the benefit of developers trying to update existing client libraries to protocol 3.0.
初始启动数据包使用灵活的字符串列表格式,而不是固定格式。请注意,运行时参数的会话默认值现在可以直接在启动数据包中指定。(实际上,您之前可以使用 options 字段来实现,但鉴于 options 的宽度受限,并且无法引用值中的空格,因此这并不是一种非常安全的技术。)
The initial startup packet uses a flexible list-of-strings format instead of a fixed format. Notice that session default values for run-time parameters can now be specified directly in the startup packet. (Actually, you could do that before using the options field, but given the limited width of options and the lack of any way to quote whitespace in the values, it wasn’t a very safe technique.)
现在所有消息都紧跟消息类型字节(对于没有类型字节的启动数据,除外),有一个长度计数。另请注意,PasswordMessage 现在有一个类型字节。
All messages now have a length count immediately following the message type byte (except for startup packets, which have no type byte). Also note that PasswordMessage now has a type byte.
ErrorResponse 和 NoticeResponse('E' 和 'N')消息现在包含多个字段,客户端代码可以从中组装出所需详细程度的错误消息。请注意,单个字段通常不会以换行符结尾,而旧协议中发送的单个字符串始终以换行符结尾。
ErrorResponse and NoticeResponse ('E' and 'N') messages now contain multiple fields, from which the client code can assemble an error message of the desired level of verbosity. Note that individual fields will typically not end with a newline, whereas the single string sent in the older protocol always did.
ReadyForQuery('Z')消息包含事务状态指示器。
The ReadyForQuery ('Z') message includes a transaction status indicator.
BinaryRow 和 DataRow 消息类型之间的区别不复存在;单个 DataRow 消息类型用于以所有格式返回数据。请注意,DataRow 的布局已更改,以便于解析。此外,二进制值的表示形式已更改:不再直接与服务器的内部表示形式相关联。
The distinction between BinaryRow and DataRow message types is gone; the single DataRow message type serves for returning data in all formats. Note that the layout of DataRow has changed to make it easier to parse. Also, the representation of binary values has changed: it is no longer directly tied to the server’s internal representation.
新增了一个“Extended Query”子协议,它添加了前端消息类型 Parse、Bind、Execute、Describe、Close、Flush 和 Sync,以及后端消息类型 ParseComplete、BindComplete、PortalSuspended、ParameterDescription、NoData 和 CloseComplete。现有客户端不必关心此子协议,但使用它可以提高性能或功能。
There is a new “extended query” sub-protocol, which adds the frontend message types Parse, Bind, Execute, Describe, Close, Flush, and Sync, and the backend message types ParseComplete, BindComplete, PortalSuspended, ParameterDescription, NoData, and CloseComplete. Existing clients do not have to concern themselves with this sub-protocol, but making use of it might allow improvements in performance or functionality.
COPY 数据现在被封装成 CopyData 和 CopyDone 消息。有一个明确的方法来从 COPY 中的错误中恢复。特殊的“\.”最后一行了不再需要,并且在 COPY OUT 期间不会发送。(它在 COPY IN 期间仍然被识别为终止符,但它的用法已弃用,最终将会被移除。)支持二进制 COPY。CopyInResponse 和 CopyOutResponse 消息包含指示列数和每列格式的字段。
COPY data is now encapsulated into CopyData and CopyDone messages. There is a well-defined way to recover from errors during COPY. The special “\.” last line is not needed anymore, and is not sent during COPY OUT. (It is still recognized as a terminator during COPY IN, but its use is deprecated and will eventually be removed.) Binary COPY is supported. The CopyInResponse and CopyOutResponse messages include fields indicating the number of columns and the format of each column.
FunctionCall 和 FunctionCallResponse 消息的布局已更改。FunctionCall 现在支持向函数传递 NULL 参数。它还可以处理以文本或二进制格式传递参数和检索结果。不再有任何理由将 FunctionCall 视为潜在的安全漏洞,因为它不允许直接访问内部服务器数据表示形式。
The layout of FunctionCall and FunctionCallResponse messages has changed. FunctionCall can now support passing NULL arguments to functions. It also can handle passing parameters and retrieving results in either text or binary format. There is no longer any reason to consider FunctionCall a potential security hole, since it does not offer direct access to internal server data representations.
后端在连接启动期间为其认为对客户端库有用的所有参数发送 ParameterStatus('S')消息。此后,无论何时任何这些参数的活动值发生变化,都会发送 ParameterStatus 消息。
The backend sends ParameterStatus ('S') messages during connection startup for all parameters it considers interesting to the client library. Subsequently, a ParameterStatus message is sent whenever the active value changes for any of these parameters.
RowDescription('T')消息为所描述行的每一列携带新的表 OID 和列编号字段。它还显示每列的格式代码。
The RowDescription ('T') message carries new table OID and column number fields for each column of the described row. It also shows the format code for each column.
不再由后端生成 CursorResponse('P')消息。
The CursorResponse ('P') message is no longer generated by the backend.
NotificationResponse('A')消息有一个附加字符串字段,它可以携带从 NOTIFY 事件发送方传递的“payload”字符串。
The NotificationResponse ('A') message has an additional string field, which can carry a “payload” string passed from the NOTIFY event sender.
EmptyQueryResponse('I')消息过去包含一个空字符串参数;此参数已移除。
The EmptyQueryResponse ('I') message used to include an empty string parameter; this has been removed.