[英]Queries in pg_stat_activity are truncated?
I'm using SELECT current_query FROM pg_stat_activity;
我正在使用
SELECT current_query FROM pg_stat_activity;
to see the currently executing queries, but I noticed that the query is truncated.查看当前正在执行的查询,但我注意到查询被截断了。 Is there any workaround or any other way to see the currently executing queries?
是否有任何解决方法或任何其他方式来查看当前正在执行的查询?
ALTER SYSTEM SET track_activity_query_size = 16384;
You will still need to restart the service for that to take effect您仍然需要重新启动服务才能生效
PostgreSQL 8.4 adds the parameter " track_activity_query_size
". PostgreSQL 8.4 添加参数“
track_activity_query_size
”。 The value will still be truncated, but you can control at what length.该值仍将被截断,但您可以控制截断的长度。
An alternative in the extreme case is to use the gdb debugger to attach to the process and print out the query.极端情况下的替代方法是使用 gdb 调试器附加到进程并打印出查询。
See http://darthanthony.wordpress.com/2012/10/11/viewing-running-postgres-queries-and-what-if-they-are-too-long/请参阅http://darthanthony.wordpress.com/2012/10/11/viewing-running-postgres-queries-and-what-if-they-are-too-long/
gdb [path_to_postgres] [pid]
printf "%s\n", debug_query_string
Starting from PostgreSQL 13 the maximum value of track_activity_query_size
is increased to 1MB .从 PostgreSQL 13 开始,
track_activity_query_size
的最大值增加到 1MB 。
If you use docker, you can configure your docker-compose file like this:如果你使用 docker,你可以像这样配置你的 docker-compose 文件:
# ...
services:
postgres:
container_name: postgres
image: postgis/postgis:13-3.1
command:
- "postgres"
- "-c"
- "track_activity_query_size=1048576"
# ...
If you do not use docker, you can set the setting at /var/lib/postgresql/data/postgresql.conf
.如果您不使用 docker,则可以在
/var/lib/postgresql/data/postgresql.conf
中进行设置。 Be sure to restart database to apply the setting.请务必重新启动数据库以应用设置。 You can use this query to check if was applied:
您可以使用此查询来检查是否已应用:
SHOW track_activity_query_size;
Get your postgres.conf
file path using below command使用以下命令获取您的
postgres.conf
文件路径
psql -U postgres -c 'SHOW config_file'
Or you are using the root user then simply或者您正在使用 root 用户然后简单地
SHOW config_file;
It will output something like它会输出类似
/var/lib/pgsql/data/postgresql.conf # Output of above command
then just edit the file using vim and change the below parameter to let's say 16kb然后只需使用 vim 编辑文件并将以下参数更改为 16kb
track_activity_query_size=16384
And restart your Postgres server并重新启动您的 Postgres 服务器
After that if you run SELECT current_query FROM pg_stat_activity;
之后,如果你运行
SELECT current_query FROM pg_stat_activity;
it will show you the more query but it will truncate till 16KB you can increase the size that you want.它会向您显示更多查询,但它会截断到 16KB,您可以增加所需的大小。
you can just enable statement logging in postgresql (log_statement), and check the logs.您可以只在 postgresql (log_statement) 中启用语句日志记录,然后检查日志。
If you run a Google Cloud SQL instance, you can configure track_activity_query_size
in Edit Instance --> Flags
section.如果您运行 Google Cloud SQL 实例,则可以在
Edit Instance --> Flags
部分配置track_activity_query_size
。
I personally set it to 32786
.我个人将其设置为
32786
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.