Search code examples
postgresqlpostgres-12

pg_stats_activity.datname is null on one record


i'am using this query to determite hit/read value for my databases

SELECT 
  datname, 
  CASE 
    WHEN blks_read = 0 THEN 0 
    ELSE blks_hit / blks_read 
  END AS ratio 
FROM 
  pg_stat_database;
  
 select * from pg_stat_database;

i have results, but the first column datname is NULL, and it has worst ratio

user: postgres

datname     |ratio  |
------------+-------+
NULL        |9984265|
template1   |      0|
template0   |      0|
postgres    |      9|
db1         |   2078|
db2         |    660|

what does the null mean here?


Solution

  • According to the documentation, pg_stat_databases contains a record for objects that are shared with multiple databases:

    It has a datid = 0 ..

    OID of this database, or 0 for objects belonging to a shared relation

    .. and has no datname:

    Name of this database, or NULL for the shared objects.