以下参照ubuntu帮助中心关于 安装PostgreSQL的内容 首先是安装PostgreSQL:
sudo apt-get install postgresql
默认安装的是v9.1, 你可以安装一个GUI的客户端:
sudo apt-get install pgadmin3
(如果是安装的v9.2那么这个是在PostgreSQL自带的了,不用安装 —— pgadmin3官网)
默认的ubuntu使用同名用户授权的方式,即如果你的系统用户名是`foo`,那么如果你在pgsql里面也添加一个用户名为`foo` 的用户,那么在你使用pg的时候,他不会要你输入密码就可以直接使用,请参见PostgreSQL官网。
在本地开发的时候可以简单用以下方式快速建立:
sudo -u postgres createuser --superuser shuji
sudo -u postgres psql
postgres=# \password shuji
然后输入新密码就可以了
回答的具体内容如下:
If you want to see where are occurring, import django.db.connection and inspect queries
>>> from django.db import connection
>>> from django.core.paginator import Paginator
>>> queryset = Entry.objects.all()
Lets create the paginator, and see if any queries occur:
>>> paginator = Paginator(queryset, 10)
>>> print connection.queries
[]
None yet.
>>> output = paginator.page(4)
<Page 4 of 788>
>>> print connection.queries
[{'time': '0.014', 'sql': 'SELECT COUNT(*) FROM `entry`'}]
Creating the page has produced one query, to count how many entries are in the queryset. The entries have not been fetched yet.
Generate the HttpResponse.
>>> response = HttpResponse(paginator.page(4))
>>> print connection.queries
[{'time': '0.014', 'sql': 'SELECT COUNT(*) FROM `account`'}]
No extra queries. Now try printing the response.
>>> print response
Content-Type: text/html; charset=utf-8
<snip>
>>> print connection.queries
[{'time': '0.014', 'sql': 'SELECT COUNT(*) FROM `entry`'}, {'time': '0.011', 'sql': 'SELECT `entry`.`id`, <snip> FROM `entry` LIMIT 10 OFFSET 30'}]
Finally, the entries have been fetched.
Contents: