2016-11-09 13:32:16 +00:00
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
PostgreSQL protocol 3.0 cheatsheet
|
|
|
|
----------------------------------
|
2016-11-09 13:32:16 +00:00
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
startup packet
|
2016-11-09 13:32:16 +00:00
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
u32 len # len including len
|
2016-11-09 13:32:16 +00:00
|
|
|
data[]
|
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
header
|
2016-11-09 13:32:16 +00:00
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
u8 type # readable char
|
|
|
|
u32 len # len including len
|
2016-11-09 13:32:16 +00:00
|
|
|
data[]
|
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
Message flow
|
|
|
|
------------
|
|
|
|
|
|
|
|
STARTUP
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
C: SSLRequest
|
|
|
|
S: # one byte: 'S', 'N'
|
|
|
|
S: 'S' # proceed with SSL
|
|
|
|
S: 'N' # not supported
|
|
|
|
- maybe close connection
|
|
|
|
|
|
|
|
C: StartupMessage # or CancelRequest
|
|
|
|
# { len, version: 0x30000, user...database...options..}
|
|
|
|
|
|
|
|
S: # AUTH require message
|
|
|
|
S: AuthenticationClearTextPassword # {'R', 8, 3 }
|
|
|
|
C: PasswordMessage # { 'p', len, data }
|
|
|
|
|
2017-06-24 13:54:23 +00:00
|
|
|
S: ErrorResponse # { 'E', len, 'S' ... , }
|
2016-11-09 13:32:16 +00:00
|
|
|
- close connection
|
|
|
|
S: AuthenticationOk # {'R', 8, 0 }
|
|
|
|
|
|
|
|
# new backend created; server tries to apply startup options
|
2017-06-24 13:54:23 +00:00
|
|
|
S: ErrorResponse
|
2016-11-09 13:32:16 +00:00
|
|
|
- close connection
|
|
|
|
|
|
|
|
S: BackendKeyData # { 'K', 12, u32 pid, u32 key }
|
|
|
|
- cancel key
|
|
|
|
|
|
|
|
S: ParameterStatus # { 'S', len, name, value }
|
|
|
|
- client_encoding, etc...
|
|
|
|
|
2017-06-24 13:54:23 +00:00
|
|
|
S: NoticeResponse # { 'N', len, ... } same as error
|
2016-11-09 13:32:16 +00:00
|
|
|
- just print the message
|
|
|
|
|
|
|
|
S: ReadyForQuery # { 'Z', 5, tx } tx: 'I' inactive, 'T' in tx, 'E' cancelled tx
|
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
TERMINATE
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
C: Terminate # { 'F', 4 }
|
|
|
|
- no wait, close connection
|
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
CANCEL
|
2016-11-09 13:32:16 +00:00
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
# new connection required*
|
|
|
|
# no reply from server*
|
2016-11-09 13:32:16 +00:00
|
|
|
C: CancelRequest # { 16, 80877102, pid, key }
|
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
QUERY
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
C: Query # { 'Q', len, text }
|
|
|
|
|
|
|
|
S: RowDescription
|
|
|
|
S: DataRow
|
|
|
|
S: CommandComplete # can be several
|
|
|
|
|
|
|
|
# can be repeated several time for reach stmt;stmt
|
|
|
|
|
2017-06-24 13:54:23 +00:00
|
|
|
S: EmptyQueryResponse # in case if text=""
|
|
|
|
S: NoticeResponse
|
|
|
|
S: ErrorResponse
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
# all text stmts processed, ready for next command
|
|
|
|
S: ReadyForQuery
|
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
EXTENDED QUERY
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
C: Parse # { 'P', len, operator_name, query, u16 types_count, ... u32 type }
|
2016-11-09 13:37:34 +00:00
|
|
|
# can be 0 can be 0 can be 0
|
|
|
|
#
|
|
|
|
# Parse can have only one query, no ';'.
|
|
|
|
#
|
|
|
|
# Nameless operator exists till next query.
|
|
|
|
#
|
|
|
|
# Named operator exists till end of a session, or explicitly destroyed.
|
|
|
|
# Named operator available for SQL Prepare and Execute calls.
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
S: ParseComplete # { '1', len }
|
2017-06-24 13:54:23 +00:00
|
|
|
S: ErrorResponse
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
C: Bind # { 'B', len, portal_name, operator_name,
|
2016-11-09 13:37:34 +00:00
|
|
|
# 16 argc_call_arg_types_count, u16[] types,
|
|
|
|
# 0 or 1
|
|
|
|
# u16 argc, [ i32 len, bytes],
|
|
|
|
#
|
|
|
|
# u16 argc_result_cols_types_count, u16[] types }
|
|
|
|
#
|
|
|
|
# Named/Nameless Portal exists till transaction ends
|
|
|
|
#
|
|
|
|
# Named portal avail for SQL Declare, Cursor, Fetch
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
S: BindComplete # { '2', len }
|
|
|
|
|
|
|
|
C: Describe # { 'D', len, u8 'S'/'P', operator_or_portal_name }
|
|
|
|
C: Execute # { 'E', len, portal_name, u32 limit } 0 - limitless
|
|
|
|
|
|
|
|
S: PortalSuspended # { 's', len } on execute limit reach
|
|
|
|
|
|
|
|
S: NoData # { 'n', len } on Describe, when portal has no query
|
|
|
|
S: RowDescription # answer for Describe
|
|
|
|
S: DataRow
|
|
|
|
|
|
|
|
S: CommandComplete
|
2017-06-24 13:54:23 +00:00
|
|
|
S: EmptyQueryResponse
|
|
|
|
S: ErrorResponse # Skips all commands till Sync
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
C: Close # { 'C', len, u8 'S'/'P', operator_or_portal }
|
2016-11-09 13:37:34 +00:00
|
|
|
C: Sync # { 'S', len }
|
2016-11-09 13:32:16 +00:00
|
|
|
|
|
|
|
S: ReadyForQuery
|
|
|
|
|
2016-11-09 13:37:34 +00:00
|
|
|
FUNCTION CALL
|
|
|
|
COPY
|
|
|
|
ASYNC
|