相关疑难解决方法(0)

Django ORM中select_related和prefetch_related的区别是什么?

在Django doc中,

select_related() "跟随"外键关系,在执行查询时选择其他相关对象数据.

prefetch_related() 对每个关系进行单独查找,并在Python中进行"加入".

"在python中加入"是什么意思?有人能说明一个例子吗?

我的理解是,对于外键关系,使用select_related; 对于M2M关系,请使用prefetch_related.它是否正确?

python django django-models django-orm

244
推荐指数
4
解决办法
11万
查看次数

如何自定义官方PostgreSQL Docker镜像的配置文件?

我正在使用官方的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)

postgresql docker

83
推荐指数
8
解决办法
6万
查看次数

是否有可能获得postgres中的查询历史记录

是否有可能获得postgres中的查询历史记录?是否有可能获得每个查询所花费的时间?我目前正在尝试在我正在处理的应用程序中识别慢查询.

我正在使用Postgres 8.3.5

database postgresql performance timing

53
推荐指数
2
解决办法
8万
查看次数

用于实时监控PostgreSQL查询的应用程序?

我想监视从应用程序发送到我的数据库的查询.为此,我发现pg_stat_activity,但更常见的是,返回的行"在事务中"读取.我要么做错了,要么快到看不到查询,我感到困惑,或者以上所有内容!

有人可以推荐最耐用的方法来监控针对PostgreSQL运行的查询吗?我更喜欢某种易于使用的基于UI的解决方案(例如:SQL Server的"Profiler"),但我不是太挑剔.

postgresql monitoring

23
推荐指数
3
解决办法
3万
查看次数

如何使用sails在控制台日志中显示查询?

我正在启动一个带有sails和mysql的项目,我不知道如何配置它以显示在控制台中执行的查询.

node.js sails.js waterline

13
推荐指数
3
解决办法
8847
查看次数

记录 PostgreSQL 交互式查询

我有几个人直接在某些系统中进行一些数据库查询。

我想将所有交互式/手动完成的查询记录到安全的系统日志服务器,或者如果失败,则使用psql二进制客户端完成所有查询。

我正在使用 Debian Jessie、PostgreSQL 9.4 和 9.1。

我怎样才能做到这一点?

postgresql debian

4
推荐指数
1
解决办法
1498
查看次数

Heroku:执行查询但没有postgresql日志

当运行在Heroku上执行某些数据库查询的特定脚本时,我从回溯中获取的信息量不足以解决我的问题.(django.db.utils.DatabaseError: current transaction is aborted, commands ignored until end of transaction)

我想从postgresl获得有关该问题的更多信息,我能够像这样访问我本地postgresql的日志.

但是在Heroku上,运行heroku logs -p postgres根本不返回任何信息.

django postgresql heroku

3
推荐指数
1
解决办法
809
查看次数

我在哪里可以找到postgresql中的sql语句日志?

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)

sql windows postgresql logging

3
推荐指数
2
解决办法
7399
查看次数

Django ORM:我怎样才能看到上次执行的查询

所以假设我们有一个使用 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 所以......我该怎么办?

python django orm

3
推荐指数
1
解决办法
951
查看次数

如何阅读 Postgres 事务日志

我只想读取所有 SQL 查询仅提交的事务。我有 Postgres 9.5 或者可以在 PG 11 上更新。我需要获取 SQL 格式的事务日志

postgresql

3
推荐指数
2
解决办法
4862
查看次数