Skip to content

Instantly share code, notes, and snippets.

@atenni
Created August 11, 2014 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atenni/b8e72888f10d8bd5340a to your computer and use it in GitHub Desktop.
Save atenni/b8e72888f10d8bd5340a to your computer and use it in GitHub Desktop.

Create Postgres dev environment in Windows 7 for Django

Install Postgres

  1. Download and run the Postgres Windows installer http://www.postgresql.org/download/windows/
  2. Initally the only user will be postgres. Edit the pg_hba.conf file (probably in C:\Program Files (x86)\PostgreSQL\8.4\data) to add trust to all the methods
  3. Additionally, add local all all trust to the top row to allow localhost access.
  4. Use createuser (in C:\Program Files (x86)\PostgreSQL\8.4\bin) to create a new database (super)user
  5. Use createdb to create a new database

Test you can access the new database via PgAdminIII.

Import live DB data

  1. Run pg_dump with appropriate options on production server (something like pg_dump --create --host=HOST --port=PORT --username=USERNAME mydatabase > django_db_backup.sql)
    • --create includes appropriate CREATE statements to recreate the database from the file.
  2. Copy file to local machine (using FTP or something like pscp. For example pscp acadmin@spider:path/to/file.sql C:\path\to\local\copy.sql)
  3. On local machine use copied file as input to psql similar to this: psql -U USERNAME --file django_db_backup.sql

As written, the above will require the same pre-created database name and username to exist locally as on the production server.

Psycopg2

Best: pip install in a virtualenv

  1. Create a virtualnev to build your Django environment in http://www.tylerbutler.com/2012/05/how-to-install-python-pip-and-virtualenv-on-windows-with-powershell/
  2. Switch to the created virtualenv and pip install the appropriate psycopg2 for your python version number and 32/64bit level from here: https://github.com/nwcell/psycopg2-windows

Alternative: Download a precompiled Windows installer

  1. Download and run the appropriate release file from this page: http://www.stickpeople.com/projects/python/win-psycopg/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment