@@ -59,6 +59,9 @@ ngx_postgres_process_events(ngx_http_request_t *r)
59
59
goto failed ;
60
60
}
61
61
62
+ ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
63
+ "postgres: process events" );
64
+
62
65
switch (pgdt -> state ) {
63
66
case state_db_connect :
64
67
dd ("state_db_connect" );
@@ -115,6 +118,9 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc,
115
118
116
119
pgrc = PQconnectPoll (pgdt -> pgconn );
117
120
121
+ ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
122
+ "postgres: polling while connecting, rc:%d" , (int ) pgrc );
123
+
118
124
if (pgrc == PGRES_POLLING_READING || pgrc == PGRES_POLLING_WRITING ) {
119
125
120
126
/*
@@ -134,8 +140,16 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc,
134
140
pgrc = PQconnectPoll (pgdt -> pgconn );
135
141
dd ("re-polling rc:%d" , (int ) pgrc );
136
142
143
+ ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
144
+ "postgres: re-polling while connecting, rc:%d" ,
145
+ (int ) pgrc );
146
+
137
147
if (pgrc == PGRES_POLLING_READING || pgrc == PGRES_POLLING_WRITING )
138
148
{
149
+ ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
150
+ "postgres: busy while connecting, rc:%d" ,
151
+ (int ) pgrc );
152
+
139
153
dd ("returning NGX_AGAIN" );
140
154
return NGX_AGAIN ;
141
155
}
@@ -178,6 +192,9 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc,
178
192
}
179
193
#endif /* DDEBUG */
180
194
195
+ ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
196
+ "postgres: busy while connecting, rc:%d" , (int ) pgrc );
197
+
181
198
dd ("returning NGX_AGAIN" );
182
199
return NGX_AGAIN ;
183
200
}
@@ -199,6 +216,8 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc,
199
216
}
200
217
201
218
dd ("connected successfully" );
219
+ ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
220
+ "postgres: connected successfully" );
202
221
203
222
pgxc -> log -> action = "sending query to PostgreSQL database" ;
204
223
pgdt -> state = state_db_send_query ;
@@ -228,6 +247,8 @@ ngx_postgres_upstream_send_query(ngx_http_request_t *r, ngx_connection_t *pgxc,
228
247
(void ) ngx_cpystrn (query , pgdt -> query .data , pgdt -> query .len + 1 );
229
248
230
249
dd ("sending query: %s" , query );
250
+ ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
251
+ "postgres: sending query: \"%s\"" , query );
231
252
232
253
if (pglcf -> output_binary ) {
233
254
pgrc = PQsendQueryParams (pgdt -> pgconn , (const char * ) query ,
@@ -250,6 +271,8 @@ ngx_postgres_upstream_send_query(ngx_http_request_t *r, ngx_connection_t *pgxc,
250
271
ngx_add_timer (pgxc -> read , r -> upstream -> conf -> read_timeout );
251
272
252
273
dd ("query sent successfully" );
274
+ ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
275
+ "postgres: query sent successfully" );
253
276
254
277
pgxc -> log -> action = "waiting for result from PostgreSQL database" ;
255
278
pgdt -> state = state_db_get_result ;
@@ -274,11 +297,18 @@ ngx_postgres_upstream_get_result(ngx_http_request_t *r, ngx_connection_t *pgxc,
274
297
}
275
298
276
299
if (!PQconsumeInput (pgdt -> pgconn )) {
300
+ ngx_log_error (NGX_LOG_ERR , pgxc -> log , 0 ,
301
+ "postgres: failed to consume input: %s" ,
302
+ PQerrorMessage (pgdt -> pgconn ));
303
+
277
304
dd ("returning NGX_ERROR" );
278
305
return NGX_ERROR ;
279
306
}
280
307
281
308
if (PQisBusy (pgdt -> pgconn )) {
309
+ ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
310
+ "postgres: busy while receiving result" );
311
+
282
312
dd ("returning NGX_AGAIN" );
283
313
return NGX_AGAIN ;
284
314
}
@@ -289,7 +319,7 @@ ngx_postgres_upstream_get_result(ngx_http_request_t *r, ngx_connection_t *pgxc,
289
319
if (res == NULL ) {
290
320
dd ("receiving result failed" );
291
321
ngx_log_error (NGX_LOG_ERR , pgxc -> log , 0 ,
292
- "postgres: receiving result failed : %s" ,
322
+ "postgres: failed to receive result : %s" ,
293
323
PQerrorMessage (pgdt -> pgconn ));
294
324
295
325
dd ("returning NGX_ERROR" );
@@ -300,7 +330,7 @@ ngx_postgres_upstream_get_result(ngx_http_request_t *r, ngx_connection_t *pgxc,
300
330
if ((pgrc != PGRES_COMMAND_OK ) && (pgrc != PGRES_TUPLES_OK )) {
301
331
dd ("receiving result failed" );
302
332
ngx_log_error (NGX_LOG_ERR , pgxc -> log , 0 ,
303
- "postgres: receiving result failed : %s: %s" ,
333
+ "postgres: failed to receive result : %s: %s" ,
304
334
PQresStatus (pgrc ),
305
335
PQerrorMessage (pgdt -> pgconn ));
306
336
@@ -313,6 +343,10 @@ ngx_postgres_upstream_get_result(ngx_http_request_t *r, ngx_connection_t *pgxc,
313
343
dd ("result received successfully, cols:%d rows:%d" ,
314
344
PQnfields (res ), PQntuples (res ));
315
345
346
+ ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , pgxc -> log , 0 ,
347
+ "postgres: result received successfully, cols:%d rows:%d" ,
348
+ PQnfields (res ), PQntuples (res ));
349
+
316
350
pgxc -> log -> action = "processing result from PostgreSQL database" ;
317
351
rc = ngx_postgres_process_response (r , res );
318
352
0 commit comments