按正常的配置,我们创建快照,使用以下命令即可:select * from profile.take_sample;
但如果我们登录PG,必须输入密码,这个时候,就需要把登录信息加到连接里面去,如下执行:
select profile.drop_server('local');
SELECT profile.create_server('local','host=x.x.x.x dbname=postgres port=5432 user=postgres password=xxxxxxx');
postgres=# select * from profile.show_servers();
server_name | connstr | enabled | max_sample_age | description
-------------+-----------------------------------------------------------------------------------+---------+----------------+-------------
local | host=x.x.x.x dbname=postgres port=5432 user=postgres password=xxxxxx | t | |
之后,再去执行快照,就没有问题了。
postgres=# select profile.show_samples();
postgres-# ;
l
-----------------------------------
(1,"2025-04-23 15:45:08+08",t,,,)
(1 row)
当然,也可以创建其他SERVER_NAME,然后,执行快照时,带上这个server_name即可
比如
SELECT profile.create_server('sz','host=x.x.x.x dbname=postgres port=5432 user=postgres password=xxxxxxx');
select profile.show_samples('sz');
psql -Upostgres -h x.x.x.x -Aqtc "select profile.get_report('sz',begin_snapshot,end_snapshot)" -o awr_report_postgres_x_y.html
|