1
1
About
2
2
=====
3
+
3
4
` ngx_postgres ` is an upstream module that allows ` nginx ` to communicate directly with ` PostgreSQL ` database.
4
5
5
6
Response is generated in ` rds ` format, so it's compatible with ` ngx_rds_json ` and ` ngx_drizzle ` modules.
6
7
7
8
8
9
Status
9
10
======
11
+
10
12
This module is production-ready and it's compatible with following nginx releases:
11
13
12
14
- 0.7.x (tested with 0.7.60 to 0.7.67),
@@ -15,8 +17,10 @@ This module is production-ready and it's compatible with following nginx release
15
17
16
18
Configuration directives
17
19
========================
20
+
18
21
postgres_server
19
22
---------------
23
+
20
24
** syntax** : ` postgres_server ip[:port] dbname=dbname user=user password=pass `
21
25
** default** : ` none `
22
26
** context** : ` upstream `
@@ -26,6 +30,7 @@ Set details about the database server.
26
30
27
31
postgres_keepalive
28
32
------------------
33
+
29
34
** syntax** : ` postgres_keepalive off | max=count [mode=single|multi] [overflow=ignore|reject] `
30
35
** default** : ` max=10 mode=single overflow=ignore `
31
36
** context** : ` upstream `
@@ -39,6 +44,7 @@ Configure keepalive parameters:
39
44
40
45
postgres_pass
41
46
-------------
47
+
42
48
** syntax** : ` postgres_pass upstream `
43
49
** default** : ` none `
44
50
** context** : ` location `
@@ -48,6 +54,7 @@ Set name of an upstream block that will be used for the database connections (it
48
54
49
55
postgres_query
50
56
--------------
57
+
51
58
** syntax** : ` postgres_query [methods] query `
52
59
** default** : ` none `
53
60
** context** : ` http ` , ` server ` , ` location `
@@ -59,6 +66,7 @@ This directive can be used more than once within same context.
59
66
60
67
postgres_rewrite
61
68
----------------
69
+
62
70
** syntax** : ` postgres_rewrite [methods] condition status_code `
63
71
** default** : ` none `
64
72
** context** : ` http ` , ` server ` , ` location `
@@ -77,6 +85,7 @@ This directive can be used more than once within same context.
77
85
78
86
postgres_output
79
87
---------------
88
+
80
89
** syntax** : ` postgres_output none|value|row|rds [row] [column] `
81
90
** default** : ` rds `
82
91
** context** : ` http ` , ` server ` , ` location `
@@ -93,6 +102,7 @@ Row and column numbers start at 0. Column name can be used instead of column num
93
102
94
103
postgres_set
95
104
------------
105
+
96
106
** syntax** : ` postgres_set $variable row column [optional|required] `
97
107
** default** : ` none `
98
108
** context** : ` http ` , ` server ` , ` location `
@@ -106,6 +116,7 @@ This directive can be used more than once within same context.
106
116
107
117
postgres_escape
108
118
---------------
119
+
109
120
** syntax** : ` postgres_escape $escaped $unescaped `
110
121
** default** : ` none `
111
122
** context** : ` http ` , ` server ` , ` location `
@@ -115,6 +126,7 @@ Escape and quote `$unescaped` variable. Result is stored in `$escaped` variable
115
126
116
127
postgres_connect_timeout
117
128
------------------------
129
+
118
130
** syntax** : ` postgres_connect_timeout timeout `
119
131
** default** : ` 10s `
120
132
** context** : ` http ` , ` server ` , ` location `
@@ -124,6 +136,7 @@ Set timeout for connecting to the database.
124
136
125
137
postgres_result_timeout
126
138
-----------------------
139
+
127
140
** syntax** : ` postgres_result_timeout timeout `
128
141
** default** : ` 30s `
129
142
** context** : ` http ` , ` server ` , ` location `
@@ -133,30 +146,37 @@ Set timeout for receiving result from the database.
133
146
134
147
Configuration variables
135
148
=======================
149
+
136
150
$postgres_columns
137
151
-----------------
152
+
138
153
Number of columns in received result-set.
139
154
140
155
141
156
$postgres_rows
142
157
--------------
158
+
143
159
Number of rows in received result-set.
144
160
145
161
146
162
$postgres_affected
147
163
------------------
164
+
148
165
Number of rows affected by ` INSERT ` , ` UPDATE ` , ` DELETE ` , ` MOVE ` , ` FETCH ` or ` COPY ` SQL query.
149
166
150
167
151
168
$postgres_query
152
169
---------------
170
+
153
171
SQL query, as seen by ` PostgreSQL ` database.
154
172
155
173
156
174
Sample configurations
157
175
=====================
176
+
158
177
Sample configuration #1
159
178
-----------------------
179
+
160
180
Return content of table ` cats ` (in ` rds ` format).
161
181
162
182
http {
@@ -176,6 +196,7 @@ Return content of table `cats` (in `rds` format).
176
196
177
197
Sample configuration #2
178
198
-----------------------
199
+
179
200
Return only those rows from table ` sites ` that match ` host ` filter which is evaluated for each request based on its ` $http_host ` variable.
180
201
181
202
http {
@@ -195,6 +216,7 @@ Return only those rows from table `sites` that match `host` filter which is eval
195
216
196
217
Sample configuration #3
197
218
-----------------------
219
+
198
220
Pass request to the backend selected from the database (traffic router).
199
221
200
222
http {
@@ -224,6 +246,7 @@ Required modules (other than `ngx_postgres`):
224
246
225
247
Sample configuration #4
226
248
-----------------------
249
+
227
250
Restrict access to local files by authenticating against ` PostgreSQL ` database.
228
251
229
252
http {
@@ -259,6 +282,7 @@ Required modules (other than `ngx_postgres`):
259
282
260
283
Sample configuration #5
261
284
-----------------------
285
+
262
286
Simple RESTful webservice returning JSON responses with appropriate HTTP status codes.
263
287
264
288
http {
@@ -307,6 +331,7 @@ Required modules (other than `ngx_postgres`):
307
331
308
332
Testing
309
333
=======
334
+
310
335
` ngx_postgres ` comes with complete test suite based on [ Test::Nginx] ( http://github.com/agentzh/test-nginx ) .
311
336
312
337
You can test core functionality using:
@@ -328,6 +353,7 @@ using:
328
353
329
354
License
330
355
=======
356
+
331
357
Copyright (c) 2010, FRiCKLE Piotr Sikora <info@frickle.com>
332
358
Copyright (c) 2009-2010, Xiaozhe Wang <chaoslawful@gmail.com>
333
359
Copyright (c) 2009-2010, Yichun Zhang <agentzh@gmail.com>
@@ -360,6 +386,7 @@ This software includes also parts of the code from `nginx` (copyrighted by **Igo
360
386
361
387
See also
362
388
========
389
+
363
390
- [ ngx_rds_json] ( http://github.com/agentzh/rds-json-nginx-module ) ,
364
391
- [ ngx_drizzle] ( http://github.com/chaoslawful/drizzle-nginx-module ) ,
365
392
- [ ngx_lua] ( http://github.com/chaoslawful/lua-nginx-module ) ,
0 commit comments