I'm using 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?
I'm using 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?
PostgreSQL 8.4 adds the parameter "track_activity_query_size". The value will still be truncated, but you can control at what length.
Starting from PostgreSQL 13 the maximum value of track_activity_query_size is increased to 1MB.
If you use docker, you can configure your docker-compose file like this:
# ...
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. 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
psql -U postgres -c 'SHOW config_file'
Or you are using the root user then simply
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
track_activity_query_size=16384
And restart your Postgres server
After that if you run 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.
If you run a Google Cloud SQL instance, you can configure track_activity_query_size in Edit Instance --> Flags section.
I personally set it to 32786.