<metaname="description" content="Relational databases a critical part of Python web applications. Learn more about persisting data in databases at Full Stack Python.">
<divstyle="padding: 0 0 20px 0; margin: 0 0 20px 0; background-color: #22B24C;">
<divclass="container">
<h2style="color: #fff; margin: 20px 40px 0 0;"><ahref="https://www.gumroad.com/l/python-deployments" style="color: #fff">The Full Stack Python Guide to Deployments book</a> has been released!</h2>
</div>
</div><ahref="https://github.com/makaimc/fullstackpython.com"><imgstyle="position: absolute; top: 0; right: 0; border: 0;" src="/theme/img/fork.png" alt="Fork me on GitHub"></a>
<p>The database storage abstraction most commonly used in Python web development
is sets of relational tables. Alternative storage abstractions are explained
in the <ahref="../no-sql-datastore.html">NoSQL</a> section of this guide.</p>
<p>Relational databases store all data in a series of tables. Interconnections
between the tables are specified as <em>foreign keys</em>.</p>
<p>Databases storage implementations vary in complexity. SQLite, a database
included with Python, creates a single file for all data per database.
Other databases such as Oracle, PostgreSQL, and MySQL have more complicated
persistence schemes while offering additional advanced features that are
useful for web application data storage.</p>
<p><ahref="http://www.postgresql.org/">PostgreSQL</a> and
<ahref="http://www.mysql.com/">MySQL</a> are two of the most common open source
databases for storing Python web application data.</p>
<p><ahref="http://www.sqlite.org/">SQLite</a> is a database that is stored in a single
file on disk. SQLite is built into Python but is only built for access
by a single connection at a time. Therefore is highly recommended to not
<ahref="https://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errors">run a production web application with SQLite</a>.</p>
<h2>PostgreSQL</h2>
<p>PostgreSQL is the recommended relational database for working with Python
web applications. PostgreSQL's feature set, active development and stability
contribute to its usage as the backend for millions of applications live
on the Web today.</p>
<h3>PostgreSQL resources</h3>
<ul>
<li>
<p>This post on
<ahref="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><ahref="http://postgresweekly.com/">PostgreSQL Weekly</a> is a weekly newsletter of
PostgreSQL content from around the web.</p>
</li>
<li>
<p>Braintree wrote about their experiences <ahref="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>This post estimates the <ahref="http://hans.io/blog/2014/02/19/postgresql_connection/index.html">costs of a PostgreSQL connection</a>.</p>
</li>
<li>
<p>There is no such thing as total security but this IBM article covers
<ahref="http://www.ibm.com/developerworks/library/os-postgresecurity/">hardening a PostgreSQL database</a>. </p>
</li>
<li>
<p>Craig Kerstiens wrote a detailed post about <ahref="http://www.craigkerstiens.com/2012/10/01/understanding-postgres-performance/">understanding PostgreSQL performance</a>.</p>
</li>
<li>
<p><ahref="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><ahref="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><ahref="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>This article explains how and why PostgreSQL can handle <ahref="http://blog.lostpropertyhq.com/postgres-full-text-search-is-good-enough/">full text searching</a>
for many use cases.</p>
</li>
<li>
<p>If you're just getting started with PostgreSQL here are
<ahref="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>The title's a bit presumptuous but here's a useful list of
<ahref="http://engineering.tilt.com/7-postgresql-data-migration-hacks/">7 PostgreSQL data migration hacks you should be using, but aren't</a>.</p>
and <ahref="http://readwrite.com/2013/09/14/google-waves-goodbye-to-mysql-in-favor-of-mariadb">Google</a>.
MySQL remains a viable database option but I always recommend new Python
developers learn PostgreSQL if they do not already know MySQL.</p>
<h3>MySQL resources</h3>
<ul>
<li>
<p><ahref="http://designm.ag/tutorials/28-beginners-tutorials-for-learning-about-mysql-databases/">28 Beginner's Tutorials for Learning about MySQL Databases</a>
is a curated collection on various introductory MySQL topics.</p>
</li>
<li>
<p>This tutorial shows how to install <ahref="http://www.cs.wcupa.edu/rkline/index/mysql-lin.html">MySQL on Ubuntu</a>.</p>
<ahref="http://www.deploypython.com/"><imgsrc="https://static.fullstackpython.com/fsp-deployment-guide.png" alt="The Full Stack Python Guide to Deployments" width="100%"></a>
<pstyle="font-size: .8em; margin-top: 10px;">Searching for a complete, step-by-step deployment walkthrough? Learn more about <ahref="http://www.deploypython.com/">The Full Stack Python Guide to Deployments book</a>.
</p>
</div>
</div><divclass="panel panel-success">
<divclass="panel-heading">
<h3class="panel-head"><ahref="/table-of-contents.html" style="color: #fff;">Table of Contents</a></h3>
<ahref="/about-author.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>About the Author</a>
</div>
</div>
<divclass="panel panel-success">
<divclass="panel-body">
<ahref="http://www.deploypython.com/"><imgsrc="https://static.fullstackpython.com/fsp-deployment-guide.png" alt="The Full Stack Python Guide to Deployments" width="100%"></a>
<pstyle="font-size: .8em; margin-top: 10px;">Searching for a complete, step-by-step deployment walkthrough? Learn more about <ahref="http://www.deploypython.com/">The Full Stack Python Guide to Deployments book</a>.