pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_total_relation_size accuracy guarantee
3+ messages / 2 participants
[nested] [flat]
* pg_total_relation_size accuracy guarantee
@ 2017-11-23 22:11 Nikita <jne100@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Nikita @ 2017-11-23 22:11 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hello, I'am currently trying to implement some simple disc space limitation
mechanism for my database. Database is partition based and insert-only - I
insert new rows to the current partition and drop oldest partition when
disc space limit exceeded.
Algorithm is quite simple and it seems it works but I must ensure two
assumptions to avoid extra VACUUM/ANALYZE calls:
1. pg_total_relation_size return predictable approximately correct table
size (apart from some preallocation) without subsequent
VACUUM/ANALYZE/anything call as long as I don't DELETE/UPDATE rows;
2. DROP/TRUNCATE table reclaim disc space without subsequent VACUUM;
These assumptions are correct? Is it fixed in doc if so?
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_total_relation_size accuracy guarantee
@ 2017-11-24 07:15 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Nikita <jne100@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Laurenz Albe @ 2017-11-24 07:15 UTC (permalink / raw)
To: Nikita <jne100@gmail.com>; pgsql-general@lists.postgresql.org
Nikita wrote:
> 1. pg_total_relation_size return predictable approximately correct table size (apart from some preallocation) without subsequent VACUUM/ANALYZE/anything call as long as I don't DELETE/UPDATE rows;
>
> 2. DROP/TRUNCATE table reclaim disc space without subsequent VACUUM;
>
> These assumptions are correct? Is it fixed in doc if so?
Sort of, if you consider the source as documentation.
Ad pg_total_relation_size:
See the function definition in backend/utils/adt/dbsize.c and
the functions that it calls, especially "calculate_relation_size":
PostgreSQL uses the stat(2) system call to determine the actual
size of the files on disk.
Ad TRUNCATE (from backend/commands/tablecmds.c):
/*
* Need the full transaction-safe pushups.
*
* Create a new empty storage file for the relation, and assign it
* as the relfilenode value. The old storage file is scheduled for
* deletion at commit.
*/
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_total_relation_size accuracy guarantee
@ 2017-11-24 10:52 Nikita <jne100@gmail.com>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 0 replies; 3+ messages in thread
From: Nikita @ 2017-11-24 10:52 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: pgsql-general@lists.postgresql.org
Source is good enough in my case and I planned to grep it anyway, so thanks
for saving my time!
2017-11-24 10:15 GMT+03:00 Laurenz Albe <laurenz.albe@cybertec.at>:
> Nikita wrote:
> > 1. pg_total_relation_size return predictable approximately correct table
> size (apart from some preallocation) without subsequent
> VACUUM/ANALYZE/anything call as long as I don't DELETE/UPDATE rows;
> >
> > 2. DROP/TRUNCATE table reclaim disc space without subsequent VACUUM;
> >
> > These assumptions are correct? Is it fixed in doc if so?
>
> Sort of, if you consider the source as documentation.
>
> Ad pg_total_relation_size:
>
> See the function definition in backend/utils/adt/dbsize.c and
> the functions that it calls, especially "calculate_relation_size":
>
> PostgreSQL uses the stat(2) system call to determine the actual
> size of the files on disk.
>
> Ad TRUNCATE (from backend/commands/tablecmds.c):
>
> /*
> * Need the full transaction-safe pushups.
> *
> * Create a new empty storage file for the relation, and assign it
> * as the relfilenode value. The old storage file is scheduled for
> * deletion at commit.
> */
>
> Yours,
> Laurenz Albe
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2017-11-24 10:52 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-11-23 22:11 pg_total_relation_size accuracy guarantee Nikita <jne100@gmail.com>
2017-11-24 07:15 ` Laurenz Albe <laurenz.albe@cybertec.at>
2017-11-24 10:52 ` Nikita <jne100@gmail.com>
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