def create_replication_stats_view()

in postgresql_metrics/prepare_db.py [0:0]


def create_replication_stats_view(db_connection):
    LOG.info("creating view {}", REPLICATION_STATS_VIEW)
    sql = """CREATE OR REPLACE FUNCTION public.pg_stat_repl()
RETURNS SETOF pg_catalog.pg_stat_replication AS $$
BEGIN
RETURN QUERY(SELECT * FROM pg_catalog.pg_stat_replication);
END$$ LANGUAGE plpgsql SECURITY DEFINER;"""
    with db_connection.cursor() as c:
        c.execute(sql)
        c.execute("CREATE VIEW " + REPLICATION_STATS_VIEW
                  + " AS SELECT * FROM public.pg_stat_repl()")