public inbox for [email protected]
help / color / mirror / Atom feedFrom: Drouvot, Bertrand <[email protected]>
To: Andres Freund <[email protected]>
To: Greg Stark <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: Melanie Plageman <[email protected]>
Cc: Kyotaro Horiguchi <[email protected]>
Cc: Justin Pryzby <[email protected]>
Cc: Thomas Munro <[email protected]>
Cc: David G. Johnston <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: shared-memory based stats collector - v70
Date: Thu, 18 Aug 2022 08:39:02 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<CAM-w4HMhHAxjpXNVMZ5WhULHpd3+LuP27zaSKSFnzZeRwHZTjg@mail.gmail.com>
<[email protected]>
<CAM-w4HNqCR7X9q5_wbJi4wLfTT1gLvy5VRS+ZGo6z8-DbXkHpw@mail.gmail.com>
<[email protected]>
<CAM-w4HP_YL8uPrNiv2DPKmq1KD3QLEX7CBLc5DCJ9j7mf7eerw@mail.gmail.com>
<[email protected]>
<CAM-w4HPGq_rpZAW4p71+d90oykyi9y7PgiQ1c9_ROs+WROCjuQ@mail.gmail.com>
<[email protected]>
<CAM-w4HNLtcKxrG0WepCKjt5tizbvZRcrqABX=jNNZoi_18E5rw@mail.gmail.com>
<[email protected]>
Hi,
On 8/18/22 1:30 AM, Andres Freund wrote:
> Hi,
>
> On 2022-08-17 15:46:42 -0400, Greg Stark wrote:
>> Isn't there also a local hash table used to find the entries to reduce
>> traffic on the shared hash table? Even if you don't take a snapshot
>> does it get entered there? There are definitely still parts of this
>> I'm working on a pretty vague understanding of :/
> Yes, there is. But it's more about code that generates stats, rather than
> reporting functions. While there's backend local pending stats we need to have
> a refcount on the shared stats item so that the stats item can't be dropped
> and then revived when those local stats are flushed.
What do you think about something along those lines for the reporting
part only?
Datum
pgstat_fetch_all_tables_stats(PG_FUNCTION_ARGS)
{
int dbid = PG_ARGISNULL(0) ? -1 : (int) PG_GETARG_OID(0);
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
dshash_seq_status hstat;
PgStatShared_HashEntry *p;
PgStatShared_Common *stats_data;
/* Only members of pg_read_all_stats can use this function */
if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS))
{
aclcheck_error(ACLCHECK_NO_PRIV, OBJECT_FUNCTION,
"pgstat_fetch_all_tables_stats");
}
pgstat_assert_is_up();
SetSingleFuncCall(fcinfo, 0);
dshash_seq_init(&hstat, pgStatLocal.shared_hash, false);
while ((p = dshash_seq_next(&hstat)) != NULL)
{
Datum values[PG_STAT_GET_ALL_TABLES_STATS_COLS];
bool nulls[PG_STAT_GET_ALL_TABLES_STATS_COLS];
PgStat_StatTabEntry * tabentry = NULL;
MemSet(values, 0, sizeof(values));
MemSet(nulls, false, sizeof(nulls));
/* If looking for specific dbid, ignore all the others */
if (dbid != -1 && p->key.dboid != (Oid) dbid)
continue;
/* If the entry is not of kind relation then ignore it */
if (p->key.kind != PGSTAT_KIND_RELATION)
continue;
/* If the entry has been dropped then ignore it */
if (p->dropped)
continue;
stats_data = dsa_get_address(pgStatLocal.dsa, p->body);
LWLockAcquire(&stats_data->lock, LW_SHARED);
tabentry = pgstat_get_entry_data(p->key.kind, stats_data);
values[0] = ObjectIdGetDatum(p->key.dboid);
values[1] = ObjectIdGetDatum(p->key.objoid);
values[2]= DatumGetInt64(tabentry->tuples_inserted);
values[3]= DatumGetInt64(tabentry->tuples_updated);
values[4]= DatumGetInt64(tabentry->tuples_deleted);
.
.
.
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
values, nulls);
LWLockRelease(&stats_data->lock);
}
dshash_seq_term(&hstat);
return (Datum) 0;
}
I also tried to make use of pgstat_get_entry_ref() but went into a
failed assertion: pgstat_get_entry_ref -> dshash_find ->
ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME(hash_table) due to lock acquired by
dshash_seq_next().
Regards,
--
Bertrand Drouvot
Amazon Web Services: https://aws.amazon.com
view thread (82+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: shared-memory based stats collector - v70
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox