在Django doc中,
select_related()"跟随"外键关系,在执行查询时选择其他相关对象数据.
prefetch_related()对每个关系进行单独查找,并在Python中进行"加入".
"在python中加入"是什么意思?有人能说明一个例子吗?
我的理解是,对于外键关系,使用select_related; 对于M2M关系,请使用prefetch_related.它是否正确?
我正在使用官方的Postgres Docker图像来尝试自定义其配置.为此,我使用命令sed进行更改max_connections,例如:
sed -i -e"s/^max_connections = 100.*$/max_connections = 1000/" /var/lib/postgresql/data/postgresql.conf
Run Code Online (Sandbox Code Playgroud)
我尝试了两种方法来应用此配置.第一种方法是将命令添加到脚本并在init文件夹"/docker-entrypoint-initdb.d"中复制它.第二种方法是使用"RUN"命令在我的Dockerfile中直接运行它们(这种方法适用于非官方的Postgresql映像,配置文件的路径不同于"/ etc/postgres/...").在这两种情况下,更改都会失败,因为配置文件丢失(我认为它尚未创建).
我该如何更改配置?
编辑1:
这是用于创建图像的Dockerfile:
# Database (http://www.cs3c.ma/)
FROM postgres:9.4
MAINTAINER Sabbane <contact@cs3c.ma>
ENV TERM=xterm
RUN apt-get update
RUN apt-get install -y nano
ADD scripts /scripts
# ADD scripts/setup-my-schema.sh /docker-entrypoint-initdb.d/
# Allow connections from anywhere.
RUN sed -i -e"s/^#listen_addresses =.*$/listen_addresses = '*'/" /var/lib/postgresql/data/postgresql.conf
RUN echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf
# Configure logs
RUN sed -i -e"s/^#logging_collector = off.*$/logging_collector = on/" /var/lib/postgresql/data/postgresql.conf …Run Code Online (Sandbox Code Playgroud) 是否有可能获得postgres中的查询历史记录?是否有可能获得每个查询所花费的时间?我目前正在尝试在我正在处理的应用程序中识别慢查询.
我正在使用Postgres 8.3.5
我想监视从应用程序发送到我的数据库的查询.为此,我发现pg_stat_activity,但更常见的是,返回的行"在事务中"读取.我要么做错了,要么快到看不到查询,我感到困惑,或者以上所有内容!
有人可以推荐最耐用的方法来监控针对PostgreSQL运行的查询吗?我更喜欢某种易于使用的基于UI的解决方案(例如:SQL Server的"Profiler"),但我不是太挑剔.
我正在启动一个带有sails和mysql的项目,我不知道如何配置它以显示在控制台中执行的查询.
我有几个人直接在某些系统中进行一些数据库查询。
我想将所有交互式/手动完成的查询记录到安全的系统日志服务器,或者如果失败,则使用psql二进制客户端完成所有查询。
我正在使用 Debian Jessie、PostgreSQL 9.4 和 9.1。
我怎样才能做到这一点?
当运行在Heroku上执行某些数据库查询的特定脚本时,我从回溯中获取的信息量不足以解决我的问题.(django.db.utils.DatabaseError: current transaction is aborted, commands ignored until end of transaction)
我想从postgresl获得有关该问题的更多信息,我能够像这样访问我本地postgresql的日志.
但是在Heroku上,运行heroku logs -p postgres根本不返回任何信息.
我postgresql.conf有以下内容:
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
# name = value
#
# (The "=" is optional.) Whitespace may be used. Comments are introduced with
# "#" anywhere on a line. The complete list of parameter names and allowed
# values can be found in the PostgreSQL documentation.
#
# The commented-out settings shown in this file represent the default values.
# Re-commenting a setting …Run Code Online (Sandbox Code Playgroud) 所以假设我们有一个使用 django orm 的简单查询
filterd = User.objects.exclude(id = request.user.id ).filter(username=data['username'] )
Run Code Online (Sandbox Code Playgroud)
这假设返回一些对象,但它不返回任何对象!显然我做错了什么,因为我对 django ORM 还不满意,所以我会帮助很多人知道在这一行中究竟执行了什么查询
我四处寻找我找到了这个
print(filter.query)
Run Code Online (Sandbox Code Playgroud)
但我明白了
AttributeError: type object 'filter' has no attribute 'query'
Run Code Online (Sandbox Code Playgroud)
我猜当没有返回任何对象时过滤器是 None 所以......我该怎么办?
我只想读取所有 SQL 查询仅提交的事务。我有 Postgres 9.5 或者可以在 PG 11 上更新。我需要获取 SQL 格式的事务日志
postgresql ×7
django ×3
python ×2
database ×1
debian ×1
django-orm ×1
docker ×1
heroku ×1
logging ×1
monitoring ×1
node.js ×1
orm ×1
performance ×1
sails.js ×1
sql ×1
timing ×1
waterline ×1
windows ×1