简体   繁体   English

使用JPA查询Postgres复制状态

[英]Using JPA to query postgres replication status

I am trying to query the replication status of the underlying database using the query: 我正在尝试使用查询查询基础数据库的复制状态:

em.createNativeQuery("SELECT application_name, backend_start, state, cast(write_lag as text) FROM pg_stat_replication;").getResultList();

Unfortunately, all columns except application_name return null. 不幸的是,除application_name之外的所有列均返回null。 Even if I only run 即使我只跑

 em.createNativeQuery("SELECT backend_start FROM pg_stat_replication;").getResultList();

I get a null result. 我得到空结果。 If I run the same query in the postgres command-line client, I get a meaningful result: 如果我在postgres命令行客户端中运行相同的查询,则会得到有意义的结果:

dbname=# select backend_start from pg_stat_replication;
         backend_start         
-------------------------------
 2018-10-16 09:01:58.262578+02
(1 row)

I am using spring-boot 1.2.6 with hibernate, and postgresql 10.5. 我正在将spring-boot 1.2.6与hibernate和postgresql 10.5一起使用。

What can I do so I get the results for this query? 我该怎么办才能获得此查询的结果?

Just after posting, I realised I user different users in the CLI and from java. 发布后,我意识到我在CLI和Java中使用了不同的用户。 Apparently, the user needs to be superuser or have the pg_read_all_stats default role. 显然,用户需要是超级用户或具有pg_read_all_stats默认角色。 Like this: 像这样:

GRANT pg_read_all_stats TO user;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM