Querying pg_buffercache: relation "pg_buffercache" does not exist I have PostgreSQL 9.4.7 installed in LXC container on Ubuntu 14.04. For monitoring purposes, i try to execute this from my host machine:
psql -qAtX -h *** -p *** -U postgres -c "select count(*) from pg_buffercache where isdirty", so I am expecting to get a pure decimal value for parsing. However, I get relation "pg_buffercache" does not exist error. I have already added pg_buffercache extension (CREATE EXTENSION pg_buffercache;), restarted server afterwards and checked if it is present:

postgres=# \dx
pg_buffercache | 1.0    | public     | examine the shared buffer cache


The strangest thing is, if i execute this query directly in postgresql shell, it works just fine:

postgres=# select count(*) from pg_buffercache where isdirty;
count
-------
 113


What can cause this? Other queries not using pg_buffercache work perfectly.
You need to first connect to the database that you need to check the stats from, and in that do the create extension, after which the query should work ;)