postgresql/

Show raw SQL queries in PostgreSQL

If you want to inspect what queries exactly Django ORM sends to the PostgreSQL, you can do it with postgres logging. The first step is to enable logging. Add

log_statement = 'all'

to the file:

sudo vim /etc/postgresql/9.4/main/postgresql.conf

Then you are able to see raw SQL queries with command:

sudo tail -f /var/log/postgresql/postgresql-9.4-main.log
| 1 Jan 2017

How to fix ERROR: new encoding (UTF8) is incompatible

Sometimes I’m unable to create a database in UTF8 encoding because the template database is in the ASCII encoding. To fix it we need to recreate template database in UTF8. Start psql console:

psql -U postgres

Run the following commands:

UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';

DROP DATABASE template1;

CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';

UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';

\c template1

VACUUM FREEZE;
| 1 Jan 2016