On Fri, Jul 1, 2016 at 8:50 AM, Michael Paquier <michael.paqu...@gmail.com> wrote: > On Fri, Jul 1, 2016 at 8:48 AM, Alvaro Herrera <alvhe...@2ndquadrant.com> > wrote: >> Michael Paquier wrote: >>> Yeah, I know. Now my opinion regarding this view is that we should >>> show information about a currently-working WAL receiver, and that it >>> has nothing to do with reporting information of its previous startup state. >>> That's more consistent with the WAL sender. >> >> Okay, that argument I buy. >> >> I suppose this function/view should report no row at all if there is no >> wal receiver connected, rather than a view with nulls. > > The function returns PG_RETURN_NULL() so as we don't have to use a > SRF, and the view checks for IS NOT NULL, so there would be no rows > popping up.
In short, I would just go with the attached and call it a day. -- Michael
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index d552f04..9d858ce 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -770,6 +770,7 @@ WalRcvDie(int code, Datum arg) Assert(walrcv->pid == MyProcPid); walrcv->walRcvState = WALRCV_STOPPED; walrcv->pid = 0; + walrcv->ready_to_display = false; SpinLockRelease(&walrcv->mutex); /* Terminate the connection gracefully. */ @@ -1344,24 +1345,9 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) char *conninfo; /* No WAL receiver, just return a tuple with NULL values */ - if (walrcv->pid == 0) + if (walrcv->pid == 0 || !walrcv->ready_to_display) PG_RETURN_NULL(); - /* - * Users attempting to read this data mustn't be shown security sensitive - * data, so sleep until everything has been properly obfuscated. - */ -retry: - SpinLockAcquire(&walrcv->mutex); - if (!walrcv->ready_to_display) - { - SpinLockRelease(&walrcv->mutex); - CHECK_FOR_INTERRUPTS(); - pg_usleep(1000); - goto retry; - } - SpinLockRelease(&walrcv->mutex); - /* determine result type */ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type");
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers