我已按照以下说明进行操作:
http://www.postgresql.org/docs/9.3/static/pgstatstatements.html
...添加以下行的效果:
# postgresql.conf
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 10000
pg_stat_statements.track = all
在文件中postgresql.conf
,然后重新启动服务器,但表pg_stat_statements
仍然不可见:
$ cat /usr/share/postgresql/9.3/postgresql.conf | grep -A3 ^shared_preload_libraries
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
pg_stat_statements.max = 10000
pg_stat_statements.track = all
$ sudo /etc/init.d/postgresql restart
* Restarting PostgreSQL 9.3 database server [ OK ]
$ psql -U postgres
psql (9.3.10)
Type "help" for help.
postgres=# select count(*) from pg_stat_activity;
count
-------
1
(1 row)
postgres=# select count(*) from pg_stat_statements;
ERROR: relation "pg_stat_statements" does not exist
更新
执行后:
sudo apt-get install postgresql-contrib-9.3
然后做:
$ psql -U postgres
psql (9.4.5, server 9.3.10)
Type "help" for help.
postgres=# create extension pg_stat_statements;
CREATE EXTENSION
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+-----------------------------------------------------------
pg_stat_statements | 1.1 | public | track execution statistics of all SQL statements executed
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
postgres=# \quit
$ sudo /etc/init.d/postgresql restart
* Restarting PostgreSQL 9.3 database server [OK]
...我现在得到:
postgres=# select * from pg_stat_statements ;
ERROR: pg_stat_statements must be loaded via shared_preload_libraries
系统详情
我正在运行Ubuntu 14.04.03 LTS
。PostgreSQL 与apt-get install
.
重启期间 PostgreSQL 的日志跟踪
在执行时,sudo /etc/init.d/postgresql restart
我得到以下日志跟踪:
$ tail -f /var/log/postgresql/postgresql-9.3-main.log
2015-12-21 11:11:31 EET [23790-2] LOG: received fast shutdown request
2015-12-21 11:11:31 EET [23790-3] LOG: aborting any active transactions
2015-12-21 11:11:31 EET [7231-1] esavo-user@RegTAP FATAL: terminating connection due to administrator command
2015-12-21 11:11:31 EET [23903-5] postgres@postgres FATAL: terminating connection due to administrator command
2015-12-21 11:11:31 EET [23822-7] esavo-user@RegTAP FATAL: terminating connection due to administrator command
2015-12-21 11:11:31 EET [23795-2] LOG: autovacuum launcher shutting down
2015-12-21 11:11:31 EET [23815-1] esavo-user@RegTAP FATAL: terminating connection due to administrator command
2015-12-21 11:11:31 EET [23792-1] LOG: shutting down
2015-12-21 11:11:31 EET [23792-2] LOG: database system is shut down
2015-12-21 11:11:32 EET [16886-1] LOG: database system was shut down at 2015-12-21 11:11:31 EET
2015-12-21 11:11:32 EET [16886-2] LOG: MultiXact member wraparound protections are now enabled
2015-12-21 11:11:32 EET [16885-1] LOG: database system is ready to accept connections
2015-12-21 11:11:32 EET [16890-1] LOG: autovacuum launcher started
2015-12-21 11:11:33 EET [16892-1] [unknown]@[unknown] LOG: incomplete startup packet
最新版本的 Postgres 将 conf 文件安装在与以前不同的位置。有时存在一个模板 .conf 文件(但实际上并未使用),然后还有一个活动的 .conf 文件(在完全不同的位置) . 我通过浏览 /etc/init.d 文件发现了这一点。您编辑的 .conf 文件可能实际上不是数据库正在使用的文件。
你可以通过连接数据库并查询来找到你的数据库使用的conf文件的位置
SHOW config_file
这是您后续问题的链接(以防将来有人发现它有用)