pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ANALYZE, pg_class.xmin && pg_class.reltuples
2+ messages / 2 participants
[nested] [flat]

* ANALYZE, pg_class.xmin && pg_class.reltuples
@ 2021-11-25 12:58  Luca Ferrari <fluca1978@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Luca Ferrari @ 2021-11-25 12:58 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

Hi all,
I've a doubt about running ANALYZE and inspecting pg_class.xmin and
pg_class.reltuples.
Let's create a simple table (note, I'm the only user on this instance):

testdb=> CREATE TABLE fizz AS SELECT v FROM generate_series( 1, 100 ) v;
SELECT 100
testdb=> SELECT relpages, reltuples, xmin, age( xmin ) FROM pg_class
WHERE relname = 'fizz';
-[ RECORD 1 ]---------
relpages  | 0
reltuples | 0
xmin      | 2359180435
age       | 1


Therefore transaction 435 created the table.
Now analyze the table:

testdb=> analyze fizz;
ANALYZE

testdb=> SELECT relpages, reltuples, xmin, age( xmin ) FROM pg_class
WHERE relname = 'fizz';
-[ RECORD 1 ]---------
relpages  | 1
reltuples | 100
xmin      | 2359180435
age       | 2


So the pg_class record has changed its content, and in fact we are now
2 transaction away the table creation, but the pg_class.xmin is the
same.
I would have expected that pg_class.xmin was updated as per
user-tables.Now, clearly ANALYZE hit the pg_statistic table and the
xmin "update" is there, but this would make me thing
pg_class.reltuples is a generated column based on some aggregation of
the latter pg_statistic, that apparently is not.
Am I missing something?

Thanks,
Luca





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: ANALYZE, pg_class.xmin && pg_class.reltuples
@ 2021-11-25 16:07  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Luca Ferrari <fluca1978@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2021-11-25 16:07 UTC (permalink / raw)
  To: Luca Ferrari <fluca1978@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

Luca Ferrari <fluca1978@gmail.com> writes:
> I've a doubt about running ANALYZE and inspecting pg_class.xmin and
> pg_class.reltuples.
> ...
> So the pg_class record has changed its content, and in fact we are now
> 2 transaction away the table creation, but the pg_class.xmin is the
> same.

ANALYZE (and VACUUM) update the table's pg_class row non-transactionally.
See the comments for vac_update_relstats():

https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/commands/vacuum.c;h=5c4bc15...

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-11-25 16:07 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25 12:58 ANALYZE, pg_class.xmin && pg_class.reltuples Luca Ferrari <fluca1978@gmail.com>
2021-11-25 16:07 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox