Tag Archives: PostgreSQL

Install and setup PostgreSQL for Django

1. Deactivate the virtualenv if there is.

pyenv deactivate

 

2. Install the required libraries.

sudo apt-get install libpq-dev python-dev

 

3. Install PostgreSQL.

sudo apt-get install postgresql postgresql-contrib

Continue reading Install and setup PostgreSQL for Django

Advertisements

Django – Schedule django-admin command using django-chronograph

Previously we talked about setting up some custom command in a Django project.

 

I would like to run the custom command in a regular interval. I could use Linux cronjob but it’s hard to manage and check the run history. It would be great if i could setup and manage these scheduled commands on the Django web portal.

django-chronograph, written by wnielson, is a Python Package which allows us to schedule any django-admin command through the web interface. It works well with the UTC timezone but if you have set the TIME_ZONE in your Django project setting.py, there would be time discrepancy.

For more detail about the bug, you can refer to the Issue #36 – Job doesn’t follow the Django’s TIME_ZONE setting.
Continue reading Django – Schedule django-admin command using django-chronograph

PostgreSQL – Set and Get Timezone

There is a timezone configuration on PostgreSQL server. If you want to change the default globally, you can edit the postgresql.conf. On Ubuntu, it is located at

  • /etc/postgresql/<version>/main/postgresql.conf
# - Locale and Formatting -

datestyle = 'iso, mdy'
#intervalstyle = 'postgres'
#timezone = 'Hongkong'
timezone = 'UTC'

 

We could also tweak the timezone only in your current PostgreSQL session.

1. Get the current timezone.

SELECT current_setting('TIMEZONE');

Continue reading PostgreSQL – Set and Get Timezone

Drupal 7 – Create a Datetime field in hook_schema() @ 1

Next: Drupal 7 – Create a Datetime field in hook_schema() @ 1

If your custom module requires an additional table in the Drupal database, you have to create the .install file and define the schema inside it. In Drupal 7, the datetime field is no longer support by the Drupal Schema API. If you want to create a datetime field, you have to use the mysql_type or pgsql_type. Here is an example.
Continue reading Drupal 7 – Create a Datetime field in hook_schema() @ 1

PostgreSQL – Check Running SQLs

Recently, there is a performance issue on the application which i am supporting and i find that the bottleneck is related to the SQL query speed. Therefore, my SA suggests me to add an index on the table to increase the query speed.

But before i could add the index, i have to find out the SQL which runs slow. In PostgreSQL, you can query the recent SQLs by the pg_stat_get_backend_activity() function. Here shows you an example. Continue reading PostgreSQL – Check Running SQLs