Advertisement
caglartoklu

PostgreSQL configuration for Django in Ubuntu

May 5th, 2011
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.89 KB | None | 0 0
  1. # PostgreSQL configuration for Django in Ubuntu
  2. # http://pastebin.com/1kgtjh06
  3. #
  4. # This tutorial and code explains how to install and configure PostgreSQL
  5. # to use with Django framework of Python.
  6. # There are much more secure and complex methods to do that, but if all you
  7. # need to do is to starting quickly, you can follow the steps here.
  8. #
  9. # The steps here will also avoid you getting
  10. # "FATAL: Ident authentication failed" errors:
  11. # https://duckduckgo.com/?q=fatal%3A+ident+authentication+failed
  12. #
  13. # By the way, you can apply the steps for PostgreSQL for other applications,
  14. # you do not have to use Django.
  15. #
  16. # In this tutorial, my user name is 'blade'.
  17. # The lines you need to type are not commented,
  18. # all my comments and outputs are commented by convention.
  19. #
  20. # I have been using Ubuntu 11.04 "Natty Narwhal" for this tutorial, but
  21. # the steps are applicable to other systems too.
  22.  
  23.  
  24. # I am assuming you have already installed Django.
  25. # To make sure, type the following in your shell
  26. # (your shell like bash, not Python shell):
  27. python -c "import django; print django.VERSION"
  28. # (1, 2, 5, 'final', 0)
  29.  
  30. # First, install the PostgreSQL stuff from your shell:
  31. sudo apt-get install postgresql python-psycopg2 pgadmin3
  32. # python-psycopg2 is a PostgreSQL database adapter for the Python.
  33. # Although pgadmin3 is not a requirement, it is recommended to easily
  34. # manage your database server.
  35.  
  36. # To check if python-psycopg2 is installed correctly, type the following
  37. # in the shell:
  38. python -c "import psycopg2; print psycopg2.apilevel"
  39. # 2.0
  40.  
  41. # If the security is not your main problem and want to do things quick with
  42. # minimum effort, create a PostgreSQL user with your Ubuntu login user name.
  43. # To do that, type the following in your shell:
  44. sudo -u postgres createuser --superuser blade
  45. # [sudo] password for blade:
  46.  
  47. # Then, set a password for your user from your shell:
  48. sudo -u postgres psql
  49.  
  50. # After this operation, psql (command line client for PostgreSQL)
  51. # will be launched.
  52.  
  53. # psql (8.4.8)
  54. # Type "help" for help.
  55.  
  56. postgres=# \password blade
  57. Enter new password:
  58. Enter it again:
  59. postgres=# \q
  60.  
  61. # Your user is now ready.
  62. # Then, the easiest way, is to create a database with your username.
  63. # To do that type the following in your shell:
  64. sudo -u postgres createdb blade
  65.  
  66.  
  67.  
  68. # Optionally, you can set a password for postgres user to use in pgadmin3:
  69. # To set a password for the postgres user, follow the steps you applied before:
  70. sudo -u postgres psql
  71. \password postgres
  72. Enter new password:
  73. Enter it again:
  74. postgres=# \q
  75.  
  76.  
  77.  
  78. # Edit your Django settings file (settings.py) so that it looks like this:
  79. ....
  80. DATABASES = {
  81.     'default': {
  82.         'ENGINE': 'django.db.backends.postgresql_psycopg2',
  83.         'NAME': 'blade',
  84.         'USER': 'blade',
  85.         'PASSWORD': 'the_password_specified_in_psql_for_blade',
  86.         'HOST': '',
  87.         'PORT': '',
  88.     }
  89. }
  90. ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement