Package: django-pgrunner
Django-pgrunner creates a localPostgreSQLdatabase for your project and
automatically starts the database server when needed. It allows you to develop
against a PostgreSQL server, while matching the convenience of a SQLite3
database file.The local database is a self-contained database created using the PostgreSQLinitdbtool. A separate PostgreSQL server will be started on a custom port.Additionally, it support creating and activating database snapshots. This
allows you to experiment with your data and be confident that you can restore
your old data within seconds.Why?While sqlite3 is great for development, being able to develop against a
full-featured database like PostgreSQL has a few huge benefits:Your development database will match the database you run in production,
eliminating a whole category of bugs, like:South migrations failing in production, while working in devErrors in code due to database specific behaviour, like stricter
checks on foreign key references.Proper checks onunique_together(sqlite3 does not support these
constraints)You can use all the great features offered by PostgreSQL, instead of
restricting yourself to a low common denominator. Examples:Database-side constraint and cascading rulesExtra data types, like arraysFull-text searchViewsStored proceduresTriggersPostGIS geo extensionsHStoreJSON featuresAnd with the ease of use this packae offers, there is no good reason not
to use it!Requirements and installationMake sure you havePostgreSQLinstalled. You can either compile from source,
or install a binary for your operating system. Check thedownloadpage for
details. For MacOS X users, I recommend downloadingPostgresApp.The snapshot functionality requiresrsyncto be installed.This package depends on thepsycopg2package.psycopg2provides the Python database adapter needed to communicate
with PostgreSQL. This adapter is partly written in C, and requires a working
C compiler, PostgreSQL development headers and thepg_configbinary in your
PATH. Alternatively, you can install abinarydistribution.pipinstallpsycopg2The easiest way to installdjango-pgrunneris using pip:pipinstalldjango-pgrunnerMicrosoft Windows is currently not supported.This package is not intended for use on production servers.UsageFirst, addpgrunnerto your INSTALLED_APPS.Next, add the following lines to yoursettings.pyor local settings file.
Make sure that these come after any DATABASES setting:# If your PostgreSQL binaries are not in your path, add this setting#PGRUNNER_BIN = '/usr/lib/postgresql/9.3/bin'#PGRUNNER_BIN = '/Applications/Postgres.app/Contents/Versions/9.3/bin'# This will overwrite DATABASES and auto-start PostgreSQL if neededimportpgrunnerpgrunner.settings(locals())Note that most Linux distibutions do not include these binaries in the PATH,
and only expose a few wrappers in/usr/bin. If this is the case for you, you
need to set thePGRUNNER_BINsetting.Run the following command to create your local database:./manage.pypg_initTo start the database in the background:./manage.pypg_ctlstartNote that if you use pgrunner.setting(), it will automatically start the server
for you.To stop the database:./manage.pypg_ctlstopThis will not be done automatically.To start thepsqlcommand line interface with the right parameters, use one of
these commands:./manage.pydbshell./manage.pypg_psqlThe only difference is that the first one uses yourDATABASESsettings, and the
second one ignores it.SnapshotsSnapshots are nothing more than named copies of the full database.
It’s the equivalent of acp dev.sqlite my-backup.sqlitefor SQLite users.To create a snapshot and activate it:./manage.pypg_snapshotmy-snapshot./manage.pypg_activatemy-snapshotThe name of the default snapshot you are running isdefault, so to switch
back:./manage.pypg_activatedefaultSnapshots can be deleted by removing their folder underpgrunnerdb/.Command summary./manage.pypg_init-Initializealocaldatabaseenvironment./manage.pypg_ctlstart-Startserverinbackground./manage.pypg_ctlstop-Stopserverinbackground./manage.pypg_ctlstatus-Checkiftheserverisrunning./manage.pypg_run-RunPostgreSQLserverinforeground./manage.pypg_psql-Startpsqlwithrightparameters./manage.pypg_snapshotfoo-Createacopyofallcurrentdatabasedata./manage.pypg_activate-Listallsnapshots./manage.pypg_activatefoo-Activatesnapshot'foo'./manage.pypg_dump-Runpg_dump./manage.pypg_restore-Runpg_restoreBehind the scenesDjango-pgrunner creates apgrunnerdb/subfolder under your Django project.
This folder contains one folder for every snapshot that was created.
The name of the default instance isdefault. Acurrentsymbolic link
keeps track of which snapshot is active.A separate PostgreSQL daemon is started for every project. When thepg_initmanagement command is run, it will pick a random port between 15000 and 16000
to run the server on and write it to the localpostgres.conf. This way
the chances of a conflict between projects are small.