forked from mattmakai/fullstackpython.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgresql.html
434 lines (433 loc) · 38.5 KB
/
postgresql.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Matt Makai">
<meta name="description" content="PostgreSQL is an open source relational database commonly used with Python applications.">
<title>PostgreSQL - Full Stack Python</title>
<link href="/f.css" rel="stylesheet">
<link rel="shortcut icon" href="/img/fsp-fav.png">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="logo-header-section">
<a href="/" style="text-decoration: none; border: none;"><img src="/img/logo-sm.png" class="logo-image" alt="Full Stack Python logo"></a>
<span class="logo-title"><a href="https://www.fullstackpython.com/">Full Stack Python</a></span>
</div>
<div class="sans-font">
<!--<a href="/blog.html" class="submenu-item-first">Blog</a> |
<a href="/books.html" class="submenu-item">Books</a> | -->
<a href="/table-of-contents.html">All topics</a>
<span style="margin:0 12px 0 12px">|</span>
<a href="/blog.html">Blog</a>
<span style="margin:0 12px 0 12px">|</span>
<a href="/email.html">Newsletter</a>
<span style="margin:0 12px 0 12px">|</span>
<a href="https://twitter.com/fullstackpython">@fullstackpython</a>
<span style="margin:0 12px 0 12px">|</span>
<a href="https://www.facebook.com/fullstackpython">Facebook</a>
<span style="margin:0 12px 0 12px">|</span>
<a href="https://github.com/mattmakai/fullstackpython.com">Source</a>
</div> </div>
</div><div class="row">
<div class="col-md-8">
<h1>PostgreSQL</h1>
<p><a href="http://www.postgresql.org/">PostgreSQL</a>, often written as "Postgres" and
pronounced "Poss-gres", is an open source
<a href="/databases.html">relational database</a> implementation frequently used by
Python applications as a backed for data storage and retrieval.</p>
<p><img src="/img/postgresql.jpg" width="100%" alt="PostgreSQL logo." class="technical-diagram" /></p>
<h2>How does PostgreSQL fit within the Python stack?</h2>
<p>PostgreSQL is the default database choice for many Python developers,
including the Django team when testing the
<a href="/object-relational-mappers-orms.html">Django ORM</a>. PostgreSQL is often
viewed as more feature robust and stable when compared to MySQL, SQLServer
and Oracle. All of those databases are reasonable choices. However, because
PostgreSQL tends to be used by Python developers the drivers and example
code for using the database tend to be better documented and contain fewer
bugs for typical usage scenarios. If you try to use an Oracle database with
Django, you'll see there is far less example code for that setup compared
to PostgreSQL backend setups.</p>
<div class="well see-also">PostgreSQL is an implementation of the <a href="/databases.html">relational database</a> concept. Learn more in the <a href="/data.html">data</a> chapter or view the <a href="/table-of-contents.html">table of contents</a> for all topics.</div>
<h2>Why is PostgreSQL a good database choice?</h2>
<p>PostgreSQL's open source license allows developers to operate one or
more databases without licensing cost in their applications. The open
source license operating model is much less expensive compared to Oracle
or other proprietary databases, especially as replication and sharding
become necessary at large scale. In addition, because so many people
ranging from independent developers to multinational organizations use
PostgreSQL, it's often easier to find developers with PostgreSQL experience
than other relational databases.</p>
<p>The PostgreSQL core team also releases frequent updates that greatly enhance
the database's capabilities. For example, in the
<a href="http://www.postgresql.org/docs/9.4/static/release-9-4.html">PostgreSQL 9.4 release</a>
the <a href="http://www.postgresql.org/docs/9.4/static/datatype-json.html">jsonb type</a>
was added to enhance JavaScript Object Notation (<a href="http://www.json.org/">JSON</a>)
storage capabilities so that in many cases a separate
<a href="/no-sql-datastore.html">NoSQL database</a> is not required in an application's
architecture.</p>
<h2>Connecting to PostgreSQL with Python</h2>
<p>To work with relational databases in Python you need to use a database
driver, which is also referred to as a database connector. The most common
driver library for working with PostgreSQL is
<a href="http://initd.org/psycopg/">psycopg2</a>. There is
<a href="https://wiki.postgresql.org/wiki/Python">a list of all drivers on the PostgreSQL wiki</a>,
including several libraries that are no longer maintained. If you're
working with the
<a href="https://docs.python.org/3.4/library/asyncio.html">asyncio Python stdlib module</a>
you should also take a look at the
<a href="https://github.com/aio-libs/aiopg">aiopg</a> library which
wraps psycopg2's asychronouos features together.</p>
<p>To abstract the connection between tables and objects, many Python
developers use an
<a href="/object-relational-mappers-orms.html">object-relational mapper (ORM)</a> with
to turn relational data from PostgreSQL into objects that can be used in
their Python application. For example, while PostgreSQL provides a
relational database and psycopg is the common database connector, there
are many ORMs that can be used with varying web frameworks, as shown in the
table below.</p>
<p><img src="/img/postgresql-orm-examples.png" width="100%" alt="Examples of how varying Python ORMs can work with PostgreSQL and the psycopg2 connector." class="technical-diagram" /></p>
<p>Learn more about
<a href="/object-relational-mappers-orms.html">Python ORMs on that dedicated topic page</a>.</p>
<h2>PostgreSQL data safety</h2>
<p>If you're on Linux it's easy to get PostgreSQL installed using a package manager.
However, once the database is installed and running your responsibility is just beginning.
Before you go live with a production application, make sure to:</p>
<ol>
<li>Lock down access with
<a href="http://www.postgresql.org/docs/9.3/static/auth-pg-hba-conf.html">a whitelist</a>
in the <code>pg_hba.conf</code> file </li>
<li>Enable <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-on-postgresql-on-an-ubuntu-12-04-vps">replication</a>
to another database that's preferrably on different infrastructure in
a separate location</li>
<li>Perform regular
<a href="http://www.postgresql.org/docs/current/static/backup.html">backups and test the restoration process</a></li>
<li>Ensure your application prevents
<a href="https://www.owasp.org/index.php/SQL_Injection">SQL injection attacks</a></li>
</ol>
<p>When possible have someone qualified do a
<a href="http://security.stackexchange.com/questions/2517/postgresql-security-audit">PostgreSQL security audit</a>
to identify the biggest risks to your database. Small applications and
bootstrapped companies often cannot afford a full audit in the beginning but
as an application grows over time it becomes a bigger target.</p>
<p>The data stored in your database is the lifeblood of your application. If you have
ever
<a href="https://www.twilio.com/blog/2014/02/introducing-developer-evangelist-matt-makai.html">accidentally dropped a production database</a>
or been the victim of malicious activity such as SQL injection attacks, you'll
know it's far easier to recover when a bit of work has been performed
beforehand on backups, replication and security measures.</p>
<h2>Python-specific PostgreSQL resources</h2>
<p>Many quickstarts and tutorials exist specifically for Django, Flask and
other web application frameworks. The ones below are some of the best
walkthroughs I've read.</p>
<ul>
<li>
<p><a href="/blog/postgresql-python-3-psycopg2-ubuntu-1604.html">Setting up PostgreSQL with Python 3 and psycopg on Ubuntu 16.04</a>
provides instructions for getting a fresh Ubuntu install working with
PostgreSQL and Python 3.</p>
</li>
<li>
<p>This post on
<a href="http://killtheyak.com/use-postgresql-with-django-flask/">using PostgreSQL with Django or Flask</a>
is a great quickstart guide for either framework.</p>
</li>
<li>
<p>This article explains how and why PostgreSQL can handle
<a href="http://blog.lostpropertyhq.com/postgres-full-text-search-is-good-enough/">full text searching</a>
for many use cases. If you're going down this route, read
<a href="http://blog.garage-coding.com/2015/12/18/postgres-fulltext-search.html">this blog post that explains how one developer implemented PostgreSQL full text search with SQLAlchemy</a>.</p>
</li>
<li>
<p><a href="http://django-postgres-copy.californiacivicdata.org/en/latest/">django-postgres-copy</a>
is a tool for bulk loading data into a PostgreSQL database based on Django models.
<a href="http://www.californiacivicdata.org/2015/07/17/hello-django-postgres-copy/">Say hello to our new open-source software for loading bulk data into PostgreSQL</a>
is an introduction to using the tool in your own projects.</p>
</li>
<li>
<p><a href="http://nemesisdesign.net/blog/coding/how-to-speed-up-tests-django-postgresql/">How to speed up tests in Django and PostgreSQL</a>
explains some hacks for making your schema migration-backed run quicker.</p>
</li>
<li>
<p><a href="http://www.machinalis.com/blog/full-text-search-on-django-with-database-back-ends/">Full Text Search in Django using Database Back-Ends</a>
provides code for both PostgreSQL and <a href="/mysql.html">MySQL</a> for adding simple
full text search into your application.</p>
</li>
<li>
<p><a href="https://pypi.python.org/pypi/records/">Records</a> is a wrapper around the psycopg2
driver that allows easy access to direct SQL access. It's worth a look if
you prefer writing SQL over using an
<a href="/object-relational-mappers-orms.html">ORM</a> like SQLAlchemy.</p>
</li>
</ul>
<h2>General PostgreSQL resources</h2>
<p>PostgreSQL tutorials not specific to Python are also really helpful
for properly handling your data.</p>
<ul>
<li>
<p><a href="https://russ.garrett.co.uk/talks/postgres-gds/">PostgreSQL: The Nice Bits</a> is a
good overview slideshow of why PostgreSQL is a great relational database.</p>
</li>
<li>
<p><a href="http://postgresweekly.com/">PostgreSQL Weekly</a> is a weekly newsletter of
PostgreSQL content from around the web.</p>
</li>
<li>
<p><a href="http://rachbelaid.com/introduction-to-postgres-physical-storage/">An introduction to PostgreSQL physical storage</a>
provides a solid walkthrough of where PostgreSQL files are located on
disk, how the files store your data and what mappings are important for
the underlying database structure. This post is an easy read and well worth
your time.</p>
</li>
<li>
<p>Braintree wrote about their experiences <a href="https://www.braintreepayments.com/braintrust/scaling-postgresql-at-braintree-four-years-of-evolution">scaling PostgreSQL</a>.
The post is an inside look at the evolution of Braintree's usage of the database.</p>
</li>
<li>
<p>There is no such thing as total security but this IBM article covers
<a href="http://www.ibm.com/developerworks/library/os-postgresecurity/">hardening a PostgreSQL database</a>. </p>
</li>
<li>
<p><a href="http://instagram-engineering.tumblr.com/post/40781627982/handling-growth-with-postgres-5-tips-from-instagram">Handling growth with Postgres</a>
provides 5 specific tips from Instagram's engineering team on how to scale
the design of your PostgreSQL database.</p>
</li>
<li>
<p><a href="http://rob.conery.io/2015/02/09/inserting-using-new-record-postgres/">Inserting And Using A New Record In Postgres</a>
shows some SQL equivalents to what many developers just do in their ORM
of choice.</p>
</li>
<li>
<p><a href="http://patshaughnessy.net/2014/10/13/following-a-select-statement-through-postgres-internals">Following a Select Statement Through Postgres Internals</a>
provides a fascinating look into the internal workings of PostgreSQL
during a query.</p>
</li>
<li>
<p>If you're just getting started with PostgreSQL here are
<a href="https://eye.raze.mx/10-beginner-postgresql-tasks-you-should-know/">10 beginner tasks you should know how to execute</a>.</p>
</li>
<li>
<p><a href="https://www.compose.com/articles/loading-google-analytics-data-to-postgresql-using-python/">Loading Google Analytics data to PostgreSQL using Python</a>
is a quality tutorial that combines <a href="/api-integration.html">API calls</a>
with psycopg and PostgreSQL to take data from Google Analytics and save
it in a PostgreSQL database.</p>
</li>
<li>
<p>The title's a bit presumptuous but here's a useful list of
<a href="http://engineering.tilt.com/7-postgresql-data-migration-hacks/">7 PostgreSQL data migration hacks you should be using, but aren't</a>.</p>
</li>
<li>
<p><a href="https://github.com/dhamaniasad/awesome-postgres">awesome-postgres</a>
is a list of code libraries, tutorials and newsletters focused
specifically on PostgreSQL.</p>
</li>
<li>
<p>While you can use a graphical interface for working with PostgreSQL, it's
best to spend some time getting
<a href="http://phili.pe/posts/postgresql-on-the-command-line/">comfortable with the command-line interface</a>.</p>
</li>
<li>
<p>Backing up databases is important because data loss can and does happen.
This article explains
<a href="http://www.n2ws.com/blog/how-to-backup-your-aws-cloud-based-postgresql-database.html">how to back up a PostgreSQL database hosted on an Amazon Web Services EC2 instance</a>
if managing your own database on a cloud server is your preferred setup.</p>
</li>
<li>
<p><a href="https://tech.zalando.com/blog/hack-to-terminate-tcp-conn-postgres/">How to fix undead PostgreSQL queries</a>
shows a bit of a hack for what to do when you can't kill certain
PostgreSQL queries.</p>
</li>
<li>
<p><a href="http://sdf.org/~riley/blog/2016/01/04/is-bi-directional-replication-bdr-in-postgres-transactional/">Is bi-directional replication (BDR) in PostgreSQL transactional?</a>
explores a relatively obscure topic with the final result that BDR is
similar to data stores with eventual consistency rather than consistency
as a requirement.</p>
</li>
<li>
<p><a href="https://github.com/spotify/postgresql-metrics">PostgreSQL-metrics</a> is a
tool built by Spotify's engineers that extracts and outputs metrics from
an existing PostgreSQL database. There's also a way to extend the tools
to pull custom metrics as well.</p>
</li>
<li>
<p><a href="https://blog.andyet.com/2016/02/04/postgres-9.5-document-store-hybrid/">Creating a Document-Store Hybrid in Postgres 9.5</a>
explains how to store and query JSON data, similar to how
<a href="/no-sql-datastore.html">NoSQL data stores</a> operate.</p>
</li>
<li>
<p><a href="http://eftimov.net/postgresql-indexes-first-principles">PostgreSQL Indexes: First Principles</a>
is a detailed look at what indexes are, what they are good for and
how to use them in PostgreSQL.</p>
</li>
<li>
<p>This <a href="http://thebuild.com/presentations/pgha-fosdem-2016.pdf">slideshow on high availability for web applications</a>
has a good overview of various database setups common in production
web applications.</p>
</li>
<li>
<p>The
<a href="http://blog.heapanalytics.com/when-to-avoid-jsonb-in-a-postgresql-schema/">JSONB data type</a>
was introduced in PostgreSQL 9.4 to make it easier to store
semi-structured data that previously
<a href="/no-sql-datastore.html">NoSQL databases</a>
such as MongoDB covered. However, there are times when using JSONB
isn't a good idea and
<a href="http://blog.heapanalytics.com/when-to-avoid-jsonb-in-a-postgresql-schema/">this blog post covers when to avoid the column type</a>.</p>
</li>
</ul>
<h3>PostgreSQL monitoring and performance</h3>
<p>Monitoring one or more PostgreSQL instances and trying to performance tune
them is a rare skillset. Here are some resources to get you started if you
have to handle these issues in your applications.</p>
<ul>
<li>
<p>This
<a href="http://russ.garrett.co.uk/2015/10/02/postgres-monitoring-cheatsheet/">guide to PostgreSQL monitoring</a>
is handy for knowing what to measure and how to do it.</p>
</li>
<li>
<p>Craig Kerstiens wrote a detailed post about
<a href="http://www.craigkerstiens.com/2012/10/01/understanding-postgres-performance/">understanding PostgreSQL performance</a>.</p>
</li>
<li>
<p>The <a href="https://tech.lendinghome.com/practical-guide-to-postgresql-optimizations-d7b9c2ad6a22">Practical Guide to PostgreSQL Optimizations</a>
covers using cache sizes, restore configurations and shared buffers
to improve database performance.</p>
</li>
<li>
<p>This article on <a href="http://www.geekytidbits.com/performance-tuning-postgres/">performance tuning PostgreSQL</a>
shows how to find slow queries, tune indexes and modify your queries
to run faster.</p>
</li>
<li>
<p><a href="http://okigiveup.net/what-postgresql-tells-you-about-its-performance/">What PostgreSQL tells you about its performance</a>
explains how to gather general performance metrics and provides the exact
queries you should run to get them. The article also covers performance
monitoring and how to analyze trigger functions.</p>
</li>
<li>
<p><a href="https://github.com/nilenso/postgresql-monitoring">PostgreSQL monitoring queries</a>
is a simple GitHub repository of SQL queries that can be run against
a PostgreSQL instance to determine usage, caching and bloat.</p>
</li>
<li>
<p><a href="http://blog.cleverelephant.ca/2016/08/pgsql-text-pattern-ops.html">PgSQL Indexes and "LIKE"</a>
examines why LIKE queries do not take advantage of PostgreSQL indexes
when the locale is set to something other than the default "C", which is
for the North American UNIX default. The gist is that you need to
build a special index to support LIKE whenever you use a locale other
than "C".</p>
</li>
</ul>
<h3>Do you want to learn more about data or web apps?</h3>
<div class="row">
<div class="col-md-4">
<div class="well select-next">
<a href="/databases.html" class="btn btn-success btn-full"><svg width="28" height="30" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1168 1216q0 33-23.5 56.5t-56.5 23.5-56.5-23.5-23.5-56.5 23.5-56.5 56.5-23.5 56.5 23.5 23.5 56.5zm256 0q0 33-23.5 56.5t-56.5 23.5-56.5-23.5-23.5-56.5 23.5-56.5 56.5-23.5 56.5 23.5 23.5 56.5zm112 160v-320q0-13-9.5-22.5t-22.5-9.5h-1216q-13 0-22.5 9.5t-9.5 22.5v320q0 13 9.5 22.5t22.5 9.5h1216q13 0 22.5-9.5t9.5-22.5zm-1230-480h1180l-157-482q-4-13-16-21.5t-26-8.5h-782q-14 0-26 8.5t-16 21.5zm1358 160v320q0 66-47 113t-113 47h-1216q-66 0-113-47t-47-113v-320q0-25 16-75l197-606q17-53 63-86t101-33h782q55 0 101 33t63 86l197 606q16 50 16 75z" fill="#fff"/></svg></a>
<p class="under-btn">Tell me about standard relational databases.</p> </div>
</div>
<div class="col-md-4">
<div class="well select-next">
<a href="/no-sql-datastore.html" class="btn btn-success btn-full"><svg width="34" height="30" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1151 960h316q-1-3-2.5-8t-2.5-8l-212-496h-708l-212 496q-1 2-2.5 8t-2.5 8h316l95 192h320zm513 30v482q0 26-19 45t-45 19h-1408q-26 0-45-19t-19-45v-482q0-62 25-123l238-552q10-25 36.5-42t52.5-17h832q26 0 52.5 17t36.5 42l238 552q25 61 25 123z" fill="#fff"/></svg></a>
<p class="under-btn">What're these NoSQL data stores hipster developers keep talking about?</p> </div>
</div>
<div class="col-md-4">
<div class="well select-next">
<a href="/web-frameworks.html" class="btn btn-success btn-full"><svg width="28" height="30" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M553 1399l-50 50q-10 10-23 10t-23-10l-466-466q-10-10-10-23t10-23l466-466q10-10 23-10t23 10l50 50q10 10 10 23t-10 23l-393 393 393 393q10 10 10 23t-10 23zm591-1067l-373 1291q-4 13-15.5 19.5t-23.5 2.5l-62-17q-13-4-19.5-15.5t-2.5-24.5l373-1291q4-13 15.5-19.5t23.5-2.5l62 17q13 4 19.5 15.5t2.5 24.5zm657 651l-466 466q-10 10-23 10t-23-10l-50-50q-10-10-10-23t10-23l393-393-393-393q-10-10-10-23t10-23l50-50q10-10 23-10t23 10l466 466q10 10 10 23t-10 23z" fill="#fff"/></svg></a>
<p class="under-btn">I want to learn how to code a Python web application using a framework.</p> </div>
</div>
</div><div id="mc_embed_signup">
<form action="//mattmakai.us2.list-manage.com/subscribe/post?u=b7e774f0c4f05dcebbfee183d&id=b22335388d" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<h4>Sign up here to receive a monthly email with major updates to this site, tutorials and discount codes for Python books.</h4>
<div class="row">
<div class="col-md-9">
<input type="email" value="" name="EMAIL" class="email form-control" id="mce-EMAIL" placeholder="email address" required>
<div style="position: absolute; left: -5000px;"><input type="text" name="b_b7e774f0c4f05dcebbfee183d_b22335388d" tabindex="-1" value=""></div>
</div>
<div class="col-md-3">
<div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="btn btn-success" style="font-family: 'Helvetica Neue';"></div>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="col-md-offset-1 col-md-3" id="sidebar">
<div class="panel">
<div class="panel-body">
<a href="http://www.deploypython.com/"><img src="/img/sponsored/fsp-deployment-guide.png" alt="The Full Stack Python Guide to Deployments" width="100%"></a>
<p style="font-size: .8em; margin-top: 10px;">Searching for a complete, step-by-step deployment walkthrough? Learn more about <a href="http://www.deploypython.com/">The Full Stack Python Guide to Deployments book</a>.
</p>
</div>
</div><div class="panel">
<div class="panel-heading">
<h3 class="panel-head">Email Updates</h3>
</div>
<div class="panel-body">
<div id="mc_embed_signup">
<form action="//mattmakai.us2.list-manage.com/subscribe/post?u=b7e774f0c4f05dcebbfee183d&id=b22335388d" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<h5>Sign up to get a monthly email with Python tutorials and major updates to this site.</h5>
<input type="email" value="" name="EMAIL" class="email form-control" id="mce-EMAIL" placeholder="email address" required>
<div style="position: absolute; left: -5000px;"><input type="text" name="b_b7e774f0c4f05dcebbfee183d_b22335388d" tabindex="-1" value=""></div>
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="btn btn-success" style="font-family: 'Helvetica Neue'; margin-top: 5px;">
</div>
</form>
</div>
</div>
</div><div class="panel" id="full-toc">
<div class="panel-heading">
<h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Table of Contents</a></h3>
</div>
<div class="list-group">
<a href="/introduction.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>1. Introduction</a><a href="/learning-programming.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Learning Programming</a><a href="/why-use-python.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Why Use Python?</a><a href="/python-2-or-3.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Python 2 or 3?</a><a href="/enterprise-python.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Enterprise Python</a><a href="/python-community.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Python Community</a><a href="/best-python-resources.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Best Python Resources</a><a href="/best-python-videos.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Best Python Videos</a><a href="/best-python-podcasts.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Best Python Podcasts</a><a href="/development-environments.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>2. Development Environments</a><a href="/vim.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Vim</a><a href="/emacs.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Emacs</a><a href="/source-control.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Source Control</a><a href="/application-dependencies.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Application Dependencies</a><a href="/python-programming-language.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>3. Core Language</a><a href="/generators.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Generators</a><a href="/comprehensions.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Comprehensions</a><a href="/testing.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>4. Testing</a><a href="/unit-testing.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Unit Testing</a><a href="/integration-testing.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Integration Testing</a><a href="/code-metrics.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Code Metrics</a><a href="/debugging.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Debugging</a><a href="/logging.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Logging</a><a href="/web-application-security.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>6. Security</a><a href="/web-development.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>7. Web Development</a><a href="/web-frameworks.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Web Frameworks</a><a href="/django.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Django</a><a href="/flask.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Flask</a><a href="/bottle.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Bottle</a><a href="/pyramid.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Pyramid</a><a href="/morepath.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Morepath</a><a href="/other-web-frameworks.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Other Web Frameworks</a><a href="/template-engines.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Template Engines</a><a href="/jinja2.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Jinja2</a><a href="/web-design.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Web Design</a><a href="/cascading-style-sheets.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Cascading Style Sheets (CSS)</a><a href="/javascript.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>JavaScript</a><a href="/task-queues.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Task Queues</a><a href="/microservices.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Microservices</a><a href="/static-site-generator.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Static Site Generators</a><a href="/pelican.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Pelican</a><a href="/lektor.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Lektor</a><a href="/mkdocs.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>MkDocs</a><a href="/websockets.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>WebSockets</a><a href="/deployment.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>8. Deployment</a><a href="/servers.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Servers</a><a href="/static-content.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Static Content</a><a href="/platform-as-a-service.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Platform-as-a-Service</a><a href="/operating-systems.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Operating Systems</a><a href="/ubuntu.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Ubuntu</a><a href="/web-servers.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Web Servers</a><a href="/apache-http-server.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Apache HTTP Server</a><a href="/nginx.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Nginx</a><a href="/caddy.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Caddy</a><a href="/wsgi-servers.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>WSGI Servers</a><a href="/green-unicorn-gunicorn.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Green Unicorn (Gunicorn)</a><a href="/continuous-integration.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Continuous Integration</a><a href="/configuration-management.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Configuration Management</a><a href="/docker.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Docker</a><a href="/data.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>9. Data</a><a href="/databases.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Relational Databases</a><a href="/postgresql.html" class="list-group-item smaller-item active" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>PostgreSQL</a><a href="/mysql.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>MySQL</a><a href="/sqlite.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>SQLite</a><a href="/object-relational-mappers-orms.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Object-relational Mappers</a><a href="/sqlalchemy.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>SQLAlchemy</a><a href="/peewee.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>Peewee</a><a href="/no-sql-datastore.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:27px'>NoSQL Data Stores</a><a href="/application-programming-interfaces.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>10. Web APIs</a><a href="/bots.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>Bots</a><a href="/api-creation.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>API Creation</a><a href="/api-integration.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>API Integration</a><a href="/twilio.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>Twilio</a><a href="/devops.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>11. DevOps</a><a href="/monitoring.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>Monitoring</a><a href="/caching.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>Caching</a><a href="/web-analytics.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>Web Analytics</a><a href="/change-log.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif;'>12. Change Log</a><a href="/what-full-stack-means.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>What Full Stack Means</a><a href="/about-author.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>About the Author</a><a href="/future-directions.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",sans-serif; padding-left:35px'>Future Directions</a> <a href="/table-of-contents.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",san-serif;background-color:#22B24C; color: #fff;'>...or <span style="border-bottom: 1px dotted;">view the full table of contents</span>.</a>
</div>
</div> <div class="panel">
<div class="panel-heading"><h3 class="panel-head">PostgreSQL</h3></div>
<div class="panel-body">
Major updates are tweeted via
<a href="https://twitter.com/fullstackpython">@fullstackpython</a>.
<hr/>
Need more detailed tutorials than you see here?
<a href="http://www.deploypython.com/">Learn more about The Full Stack Python Guide to Deployments book.</a>
</div>
</div>
<div class="panel" id="mobile-toc">
<div class="panel-heading">
<h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Chapters</a></h3>
</div>
<div class="list-group">
<a href="/introduction.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>1. Introduction</a><a href="/development-environments.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>2. Development Environments</a><a href="/python-programming-language.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>3. Core Language</a><a href="/testing.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>4. Testing</a><a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>6. Security</a><a href="/web-development.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>7. Web Development</a><a href="/deployment.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>8. Deployment</a><a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>9. Data</a> <a href="/postgresql.html" class="list-group-item smaller-item active" style='font-family: "Helvetica Neue",sans-serif;'>» PostgreSQL</a>
<a href="/application-programming-interfaces.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>10. Web APIs</a><a href="/devops.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>11. DevOps</a><a href="/change-log.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>12. Change Log</a> <a href="/table-of-contents.html" class="list-group-item smaller-item" style='font-family: "Helvetica Neue",san-serif;background-color:#22B24C; color: #fff;'>...or <span style="border-bottom: 1px dotted;">view the full table of contents</span>.</a>
</div>
</div></div></div>
<hr/>
</div>
<div style="margin: 0 0 12px;background-color: #22B24C;">
<div class="container">
<p class="banner sans-font">
<a href="https://gumroad.com/l/python-deployments" style="color: #fff">Learn to deploy Python web applications with this step-by-step book tutorial</a>.
</p>
</div>
</div>
<div class="container">
<div class="sans-font footer">
<a href="https://github.com/mattmakai" class="underline">Matt Makai</a> 2016
</div>
</div><script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-19910497-7', 'auto');
ga('send', 'pageview');
</script><script type='text/javascript'>
var trackOutboundLink = function(url) { ga('send', 'event', 'outbound', 'click', url, {'hitCallback': function () { document.location = url; } }); }
</script>
</body>
</html>