Switching to Postgresql from MySql | Akshay Deo Switching to Postgresql from MySql · Akshay Deo

Switching to Postgresql from MySql


I have been using MySQL database as back end since my first Django web application. But as my applications started getting more and more complex, MySQL started giving me a lot of issues. One of the biggest issue was while performing south migrations. Usually migrations used to affect/break relationships and Django ORM used to return None objects. But a lot of times these migrations used to run correctly on my test PostgreSQL db. So finally I decided to switch onto PostgreSQL db.

But initially I faced a lot of problems while setting up PostgreSQL on my Ubuntu box. Basically its way different than the way we use MySQL. So gathered a lot of information over web and aggregating those here. This was for me, but probably useful for few of you, so making it public.

Install PostgreSQL

PostgreSQL server

sudo apt-get install postgresql

</p>

Pgadmin tool for managing databases

sudo apt-get install pgadmin

</p>

Add password for default superuser postgres

The default superuser, called β€˜postgres’, does not have a password by default. So we need to add password for this user

sudo su postgres -c psql template1
postgres=# ALTER USER postgres with PASSWORD '<your password>';
postgres=# q

</p>

Crate a user and database under that user

Create user

sudo -u postgres createuser -d -R -P <new username>

Create database

sudo -u postgres createdb -O <usename> <database name>

</p>

These are the basic things one should know who wants to switch their Django apps from MySql to PostgreSQL. Hope this post will help you. Do correct me if I made some wrong comments here in this post :).
Happy coding m/


powered by TinyLetter



Comments