pg_stat_statements 已启用,但 table 不存在
pg_stat_statements enabled, but the table does not exist
我已经安装了 postgresql-9.4 和 运行,并且最近在官方 documentation.
的帮助下启用了 pg_stat_statements 模块
但是我在使用时遇到以下错误:
postgres=# SELECT * FROM pg_stat_statements;
ERROR: relation "pg_stat_statements" does not exist
LINE 1: SELECT * FROM pg_stat_statements;
postgres=# SELECT pg_stat_statements_reset();
ERROR: function pg_stat_statements_reset() does not exist
LINE 1: SELECT pg_stat_statements_reset();
我使用 postgres 用户登录到 psql。
我还检查了可用的扩展列表:
postgres=# SELECT * FROM pg_available_extensions WHERE name = 'pg_stat_statements'
;
name | default_version | installed_version | comment
--------------------+-----------------+-------------------+-----------------------------------------------------------
pg_stat_statements | 1.2 | | track execution statistics of all SQL statements executed
(1 row)
下面是扩展版本查询的结果:
postgres=# SELECT * FROM pg_available_extension_versions WHERE name = 'pg_stat_statements';
name | version | installed | superuser | relocatable | schema | requires | comment
--------------------+---------+-----------+-----------+-------------+--------+----------+-----------------------------------------------------------
pg_stat_statements | 1.2 | f | t | t | | | track execution statistics of all SQL statements executed
(1 row)
我们将不胜感激。
未安装扩展:
SELECT *
FROM pg_available_extensions
WHERE
name = 'pg_stat_statements' and
installed_version is not null;
如果 table 为空,创建扩展名:
CREATE EXTENSION pg_stat_statements;
我第一次使用liquibase部署环境时遇到了同样的问题。
我知道我的回复可能与您的问题无关,但它是第一个 google 结果,所以我认为像我这样的其他人可以带着我同样的 Liquibase 问题来到这里。
这些是在您生成第一个 xml 文件时由 liquibase 检索的 PosGreSQL 元数据表。
在我的例子中,它只是无用的自动生成代码,所以我通过删除这些行来解决它:
<changeSet author="martinlarizzate (generated)" id="1588181532394-7">
<createView fullDefinition="false" viewName="pg_stat_statements"> SELECT pg_stat_statements.userid,
pg_stat_statements.dbid,
pg_stat_statements.queryid,
pg_stat_statements.query,
pg_stat_statements.calls,
pg_stat_statements.total_time,
pg_stat_statements.min_time,
pg_stat_statements.max_time,
pg_stat_statements.mean_time,
pg_stat_statements.stddev_time,
pg_stat_statements.rows,
pg_stat_statements.shared_blks_hit,
pg_stat_statements.shared_blks_read,
pg_stat_statements.shared_blks_dirtied,
pg_stat_statements.shared_blks_written,
pg_stat_statements.local_blks_hit,
pg_stat_statements.local_blks_read,
pg_stat_statements.local_blks_dirtied,
pg_stat_statements.local_blks_written,
pg_stat_statements.temp_blks_read,
pg_stat_statements.temp_blks_written,
pg_stat_statements.blk_read_time,
pg_stat_statements.blk_write_time
FROM pg_stat_statements(true) pg_stat_statements(userid, dbid, queryid, query, calls, total_time, min_time, max_time, mean_time, stddev_time, 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, blk_write_time);</createView>
</changeSet>
我在配置 Percona 监控和管理 (PMM) 时遇到过这个问题,因为一些奇怪的原因 PMM 连接到名称为 postgres
的数据库,因此必须在中创建 pg_stat_statements
扩展此数据库:
yourdb# \c postgres
postgres# CREATE EXTENSION pg_stat_statements SCHEMA public;
我已经安装了 postgresql-9.4 和 运行,并且最近在官方 documentation.
的帮助下启用了 pg_stat_statements 模块但是我在使用时遇到以下错误:
postgres=# SELECT * FROM pg_stat_statements;
ERROR: relation "pg_stat_statements" does not exist
LINE 1: SELECT * FROM pg_stat_statements;
postgres=# SELECT pg_stat_statements_reset();
ERROR: function pg_stat_statements_reset() does not exist
LINE 1: SELECT pg_stat_statements_reset();
我使用 postgres 用户登录到 psql。 我还检查了可用的扩展列表:
postgres=# SELECT * FROM pg_available_extensions WHERE name = 'pg_stat_statements'
;
name | default_version | installed_version | comment
--------------------+-----------------+-------------------+-----------------------------------------------------------
pg_stat_statements | 1.2 | | track execution statistics of all SQL statements executed
(1 row)
下面是扩展版本查询的结果:
postgres=# SELECT * FROM pg_available_extension_versions WHERE name = 'pg_stat_statements';
name | version | installed | superuser | relocatable | schema | requires | comment
--------------------+---------+-----------+-----------+-------------+--------+----------+-----------------------------------------------------------
pg_stat_statements | 1.2 | f | t | t | | | track execution statistics of all SQL statements executed
(1 row)
我们将不胜感激。
未安装扩展:
SELECT *
FROM pg_available_extensions
WHERE
name = 'pg_stat_statements' and
installed_version is not null;
如果 table 为空,创建扩展名:
CREATE EXTENSION pg_stat_statements;
我第一次使用liquibase部署环境时遇到了同样的问题。 我知道我的回复可能与您的问题无关,但它是第一个 google 结果,所以我认为像我这样的其他人可以带着我同样的 Liquibase 问题来到这里。
这些是在您生成第一个 xml 文件时由 liquibase 检索的 PosGreSQL 元数据表。
在我的例子中,它只是无用的自动生成代码,所以我通过删除这些行来解决它:
<changeSet author="martinlarizzate (generated)" id="1588181532394-7">
<createView fullDefinition="false" viewName="pg_stat_statements"> SELECT pg_stat_statements.userid,
pg_stat_statements.dbid,
pg_stat_statements.queryid,
pg_stat_statements.query,
pg_stat_statements.calls,
pg_stat_statements.total_time,
pg_stat_statements.min_time,
pg_stat_statements.max_time,
pg_stat_statements.mean_time,
pg_stat_statements.stddev_time,
pg_stat_statements.rows,
pg_stat_statements.shared_blks_hit,
pg_stat_statements.shared_blks_read,
pg_stat_statements.shared_blks_dirtied,
pg_stat_statements.shared_blks_written,
pg_stat_statements.local_blks_hit,
pg_stat_statements.local_blks_read,
pg_stat_statements.local_blks_dirtied,
pg_stat_statements.local_blks_written,
pg_stat_statements.temp_blks_read,
pg_stat_statements.temp_blks_written,
pg_stat_statements.blk_read_time,
pg_stat_statements.blk_write_time
FROM pg_stat_statements(true) pg_stat_statements(userid, dbid, queryid, query, calls, total_time, min_time, max_time, mean_time, stddev_time, 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, blk_write_time);</createView>
</changeSet>
我在配置 Percona 监控和管理 (PMM) 时遇到过这个问题,因为一些奇怪的原因 PMM 连接到名称为 postgres
的数据库,因此必须在中创建 pg_stat_statements
扩展此数据库:
yourdb# \c postgres
postgres# CREATE EXTENSION pg_stat_statements SCHEMA public;