def create_incoming_replication_status_view()

in postgresql_metrics/prepare_db.py [0:0]


def create_incoming_replication_status_view(db_connection):
    LOG.info("creating view {}", INCOMING_REPLICATION_STATS_VIEW)
    func_sql = """CREATE OR REPLACE FUNCTION public.stat_incoming_replication()
RETURNS SETOF pg_catalog.pg_stat_wal_receiver AS $$
BEGIN
RETURN QUERY(SELECT * FROM pg_catalog.pg_stat_wal_receiver);
END$$ LANGUAGE plpgsql SECURITY DEFINER;"""
    view_sql = "CREATE OR REPLACE VIEW public.{0} AS SELECT * FROM {0}()".format(
        INCOMING_REPLICATION_STATS_VIEW)
    with db_connection.cursor() as c:
        c.execute(func_sql)
        c.execute(view_sql)