Search code examples
postgresqlkubernetespostgis

Postgis pg_stat_statements errors


I have a Postgis database deployed on a Kubernetes cluster, using this image: docker pull postgis/postgis:13-3.1.

I was trying to solve this error:

2021-06-29 03:20:50.958 UTC [2852] ERROR:  relation "pg_stat_statements" does not exist at character 536
2021-06-29 03:20:50.958 UTC [2852] STATEMENT:  SELECT t2.rolname, t3.datname, queryid, calls, total_time / 1000 as total_time_seconds, min_time / 1000 as min_time_seconds, max_time / 1000 as max_time_seconds, mean_time / 1000 as mean_time_seconds, stddev_time / 1000 as stddev_time_seconds, rows, shared_blks_hit, shared_blks_read, shared_blks_dirtied, shared_blks_written, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, temp_blks_read, temp_blks_written, blk_read_time / 1000 as blk_read_time_seconds, blk_write_time / 1000 as blk_write_time_seconds FROM pg_stat_statements t1 JOIN pg_roles t2 ON (t1.userid=t2.oid) JOIN pg_database t3 ON (t1.dbid=t3.oid) WHERE t2.rolname != 'rdsadmin'

So I installed the missing extension in all my dbs, like so:

psql -U $PG_USER \
  -d $DATABSE \
  -c "CREATE EXTENSION pg_stat_statements SCHEMA public"

psql -U $PG_USER \
  -d $DATABSE \
  -c "CREATE EXTENSION pg_stat_statements SCHEMA pg_catalog"

I'm now getting this error:

2021-06-29 20:04:46.870 UTC [331] ERROR:  column "total_time" does not exist at character 48
2021-06-29 20:04:46.870 UTC [331] STATEMENT:  SELECT t2.rolname, t3.datname, queryid, calls, total_time / 1000 as total_time_seconds, min_time / 1000 as min_time_seconds, max_time / 1000 as max_time_seconds, mean_time / 1000 as mean_time_seconds, stddev_time / 1000 as stddev_time_seconds, rows, shared_blks_hit, shared_blks_read, shared_blks_dirtied, shared_blks_written, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, temp_blks_read, temp_blks_written, blk_read_time / 1000 as blk_read_time_seconds, blk_write_time / 1000 as blk_write_time_seconds FROM pg_stat_statements t1 JOIN pg_roles t2 ON (t1.userid=t2.oid) JOIN pg_database t3 ON (t1.dbid=t3.oid) WHERE t2.rolname != 'rdsadmin'

I've tried to find the reason why, but haven't found anything helpful anywhere. Any ideias on how to solve this issue?

Postgres version: psql (PostgreSQL) 13.2 (Debian 13.2-1.pgdg100+1)

Config file:

# ...
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 1000
pg_stat_statements.track = all
# ...

Solution

  • Following jjanes comment I found out that the Prometheus node exporter was making an incorrect query (here), due to the fact that the column was, indeed, mispelled.

    Changing the column name fixed this issue.