PostgreSQL Source Code  git master
pqmq.h File Reference
#include "lib/stringinfo.h"
#include "storage/shm_mq.h"
Include dependency graph for pqmq.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void pq_redirect_to_shm_mq (dsm_segment *seg, shm_mq_handle *mqh)
 
void pq_set_parallel_leader (pid_t pid, BackendId backend_id)
 
void pq_parse_errornotice (StringInfo str, ErrorData *edata)
 

Function Documentation

◆ pq_parse_errornotice()

void pq_parse_errornotice ( StringInfo  str,
ErrorData edata 
)

Definition at line 204 of file pqmq.c.

205 {
206  /* Initialize edata with reasonable defaults. */
207  MemSet(edata, 0, sizeof(ErrorData));
208  edata->elevel = ERROR;
210 
211  /* Loop over fields and extract each one. */
212  for (;;)
213  {
214  char code = pq_getmsgbyte(msg);
215  const char *value;
216 
217  if (code == '\0')
218  {
219  pq_getmsgend(msg);
220  break;
221  }
222  value = pq_getmsgrawstring(msg);
223 
224  switch (code)
225  {
226  case PG_DIAG_SEVERITY:
227  /* ignore, trusting we'll get a nonlocalized version */
228  break;
230  if (strcmp(value, "DEBUG") == 0)
231  {
232  /*
233  * We can't reconstruct the exact DEBUG level, but
234  * presumably it was >= client_min_messages, so select
235  * DEBUG1 to ensure we'll pass it on to the client.
236  */
237  edata->elevel = DEBUG1;
238  }
239  else if (strcmp(value, "LOG") == 0)
240  {
241  /*
242  * It can't be LOG_SERVER_ONLY, or the worker wouldn't
243  * have sent it to us; so LOG is the correct value.
244  */
245  edata->elevel = LOG;
246  }
247  else if (strcmp(value, "INFO") == 0)
248  edata->elevel = INFO;
249  else if (strcmp(value, "NOTICE") == 0)
250  edata->elevel = NOTICE;
251  else if (strcmp(value, "WARNING") == 0)
252  edata->elevel = WARNING;
253  else if (strcmp(value, "ERROR") == 0)
254  edata->elevel = ERROR;
255  else if (strcmp(value, "FATAL") == 0)
256  edata->elevel = FATAL;
257  else if (strcmp(value, "PANIC") == 0)
258  edata->elevel = PANIC;
259  else
260  elog(ERROR, "unrecognized error severity: \"%s\"", value);
261  break;
262  case PG_DIAG_SQLSTATE:
263  if (strlen(value) != 5)
264  elog(ERROR, "invalid SQLSTATE: \"%s\"", value);
265  edata->sqlerrcode = MAKE_SQLSTATE(value[0], value[1], value[2],
266  value[3], value[4]);
267  break;
269  edata->message = pstrdup(value);
270  break;
272  edata->detail = pstrdup(value);
273  break;
275  edata->hint = pstrdup(value);
276  break;
278  edata->cursorpos = pg_strtoint32(value);
279  break;
281  edata->internalpos = pg_strtoint32(value);
282  break;
284  edata->internalquery = pstrdup(value);
285  break;
286  case PG_DIAG_CONTEXT:
287  edata->context = pstrdup(value);
288  break;
289  case PG_DIAG_SCHEMA_NAME:
290  edata->schema_name = pstrdup(value);
291  break;
292  case PG_DIAG_TABLE_NAME:
293  edata->table_name = pstrdup(value);
294  break;
295  case PG_DIAG_COLUMN_NAME:
296  edata->column_name = pstrdup(value);
297  break;
299  edata->datatype_name = pstrdup(value);
300  break;
302  edata->constraint_name = pstrdup(value);
303  break;
304  case PG_DIAG_SOURCE_FILE:
305  edata->filename = pstrdup(value);
306  break;
307  case PG_DIAG_SOURCE_LINE:
308  edata->lineno = pg_strtoint32(value);
309  break;
311  edata->funcname = pstrdup(value);
312  break;
313  default:
314  elog(ERROR, "unrecognized error field code: %d", (int) code);
315  break;
316  }
317  }
318 }
#define MemSet(start, val, len)
Definition: c.h:1008
#define LOG
Definition: elog.h:25
#define FATAL
Definition: elog.h:35
#define WARNING
Definition: elog.h:30
#define PANIC
Definition: elog.h:36
#define DEBUG1
Definition: elog.h:24
#define ERROR
Definition: elog.h:33
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
Definition: elog.h:50
#define elog(elevel,...)
Definition: elog.h:218
#define NOTICE
Definition: elog.h:29
#define INFO
Definition: elog.h:28
static struct @142 value
char * pstrdup(const char *in)
Definition: mcxt.c:1299
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
int32 pg_strtoint32(const char *s)
Definition: numutils.c:263
#define PG_DIAG_INTERNAL_QUERY
Definition: postgres_ext.h:63
#define PG_DIAG_SCHEMA_NAME
Definition: postgres_ext.h:65
#define PG_DIAG_CONSTRAINT_NAME
Definition: postgres_ext.h:69
#define PG_DIAG_DATATYPE_NAME
Definition: postgres_ext.h:68
#define PG_DIAG_SOURCE_LINE
Definition: postgres_ext.h:71
#define PG_DIAG_STATEMENT_POSITION
Definition: postgres_ext.h:61
#define PG_DIAG_SOURCE_FILE
Definition: postgres_ext.h:70
#define PG_DIAG_MESSAGE_HINT
Definition: postgres_ext.h:60
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:57
#define PG_DIAG_SEVERITY_NONLOCALIZED
Definition: postgres_ext.h:56
#define PG_DIAG_TABLE_NAME
Definition: postgres_ext.h:66
#define PG_DIAG_MESSAGE_PRIMARY
Definition: postgres_ext.h:58
#define PG_DIAG_COLUMN_NAME
Definition: postgres_ext.h:67
#define PG_DIAG_MESSAGE_DETAIL
Definition: postgres_ext.h:59
#define PG_DIAG_CONTEXT
Definition: postgres_ext.h:64
#define PG_DIAG_SEVERITY
Definition: postgres_ext.h:55
#define PG_DIAG_SOURCE_FUNCTION
Definition: postgres_ext.h:72
#define PG_DIAG_INTERNAL_POSITION
Definition: postgres_ext.h:62
void pq_getmsgend(StringInfo msg)
Definition: pqformat.c:637
int pq_getmsgbyte(StringInfo msg)
Definition: pqformat.c:401
const char * pq_getmsgrawstring(StringInfo msg)
Definition: pqformat.c:610
int internalpos
Definition: elog.h:381
char * schema_name
Definition: elog.h:375
char * context
Definition: elog.h:372
char * internalquery
Definition: elog.h:382
int sqlerrcode
Definition: elog.h:367
struct MemoryContextData * assoc_context
Definition: elog.h:386
const char * filename
Definition: elog.h:362
int elevel
Definition: elog.h:357
char * datatype_name
Definition: elog.h:378
char * detail
Definition: elog.h:369
const char * funcname
Definition: elog.h:364
char * table_name
Definition: elog.h:376
char * message
Definition: elog.h:368
int lineno
Definition: elog.h:363
char * hint
Definition: elog.h:371
char * constraint_name
Definition: elog.h:379
int cursorpos
Definition: elog.h:380
char * column_name
Definition: elog.h:377

References ErrorData::assoc_context, ErrorData::column_name, ErrorData::constraint_name, ErrorData::context, CurrentMemoryContext, ErrorData::cursorpos, ErrorData::datatype_name, DEBUG1, ErrorData::detail, ErrorData::elevel, elog, ERROR, FATAL, ErrorData::filename, ErrorData::funcname, ErrorData::hint, INFO, ErrorData::internalpos, ErrorData::internalquery, ErrorData::lineno, LOG, MAKE_SQLSTATE, MemSet, ErrorData::message, NOTICE, PANIC, PG_DIAG_COLUMN_NAME, PG_DIAG_CONSTRAINT_NAME, PG_DIAG_CONTEXT, PG_DIAG_DATATYPE_NAME, PG_DIAG_INTERNAL_POSITION, PG_DIAG_INTERNAL_QUERY, PG_DIAG_MESSAGE_DETAIL, PG_DIAG_MESSAGE_HINT, PG_DIAG_MESSAGE_PRIMARY, PG_DIAG_SCHEMA_NAME, PG_DIAG_SEVERITY, PG_DIAG_SEVERITY_NONLOCALIZED, PG_DIAG_SOURCE_FILE, PG_DIAG_SOURCE_FUNCTION, PG_DIAG_SOURCE_LINE, PG_DIAG_SQLSTATE, PG_DIAG_STATEMENT_POSITION, PG_DIAG_TABLE_NAME, pg_strtoint32(), pq_getmsgbyte(), pq_getmsgend(), pq_getmsgrawstring(), pstrdup(), ErrorData::schema_name, ErrorData::sqlerrcode, ErrorData::table_name, value, and WARNING.

Referenced by HandleParallelMessage().

◆ pq_redirect_to_shm_mq()

void pq_redirect_to_shm_mq ( dsm_segment seg,
shm_mq_handle mqh 
)

Definition at line 51 of file pqmq.c.

52 {
54  pq_mq_handle = mqh;
58 }
@ DestRemote
Definition: dest.h:91
void on_dsm_detach(dsm_segment *seg, on_dsm_detach_callback function, Datum arg)
Definition: dsm.c:1099
ProtocolVersion FrontendProtocol
Definition: globals.c:28
CommandDest whereToSendOutput
Definition: postgres.c:93
uintptr_t Datum
Definition: postgres.h:411
const PQcommMethods * PqCommMethods
Definition: pqcomm.c:166
#define PG_PROTOCOL_LATEST
Definition: pqcomm.h:123
static void pq_cleanup_redirect_to_shm_mq(dsm_segment *seg, Datum arg)
Definition: pqmq.c:65
static const PQcommMethods PqCommMqMethods
Definition: pqmq.c:37
static shm_mq_handle * pq_mq_handle
Definition: pqmq.c:24

References DestRemote, FrontendProtocol, on_dsm_detach(), PG_PROTOCOL_LATEST, pq_cleanup_redirect_to_shm_mq(), pq_mq_handle, PqCommMethods, PqCommMqMethods, and whereToSendOutput.

Referenced by ParallelWorkerMain().

◆ pq_set_parallel_leader()

void pq_set_parallel_leader ( pid_t  pid,
BackendId  backend_id 
)

Definition at line 76 of file pqmq.c.

77 {
81 }
Assert(fmt[strlen(fmt) - 1] !='\n')
static pid_t pq_mq_parallel_leader_pid
Definition: pqmq.c:26
static pid_t pq_mq_parallel_leader_backend_id
Definition: pqmq.c:27

References Assert(), pq_mq_parallel_leader_backend_id, pq_mq_parallel_leader_pid, PqCommMethods, and PqCommMqMethods.

Referenced by ParallelWorkerMain().