pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedCalculation of Database Size in postgres
6+ messages / 3 participants
[nested] [flat]
* Calculation of Database Size in postgres
@ 2018-02-14 10:17 pavan95 <pavan.postgresdba@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: pavan95 @ 2018-02-14 10:17 UTC (permalink / raw)
To: pgsql-admin
Hi all,
In postgres for knowing the size of a database we generally use the system
administration function "pg_database_size('database_name')".
I am curious to know how does this calculate internally from the pages(free
pages/fragmented pages/full pages) stored in the disk?
Thanks in advance!
Regards,
Pavan
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-admin-f2076596.html
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Calculation of Database Size in postgres
@ 2018-02-14 10:21 Laurenz Albe <laurenz.albe@cybertec.at>
parent: pavan95 <pavan.postgresdba@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Laurenz Albe @ 2018-02-14 10:21 UTC (permalink / raw)
To: pavan95 <pavan.postgresdba@gmail.com>; pgsql-admin
pavan95 wrote:
> In postgres for knowing the size of a database we generally use the system
> administration function "pg_database_size('database_name')".
>
> I am curious to know how does this calculate internally from the pages(free
> pages/fragmented pages/full pages) stored in the disk?
It just adds up the sizes of the files that make up the database.
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Calculation of Database Size in postgres
@ 2018-02-14 10:23 pavan95 <pavan.postgresdba@gmail.com>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 6+ messages in thread
From: pavan95 @ 2018-02-14 10:23 UTC (permalink / raw)
To: pgsql-admin
Hi Laurenz,
Do you know how does it calculate internally using what functions or what
system catalogs or whatever?
Regards,
Pavan
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-admin-f2076596.html
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Calculation of Database Size in postgres
@ 2018-02-14 11:16 Laurenz Albe <laurenz.albe@cybertec.at>
parent: pavan95 <pavan.postgresdba@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Laurenz Albe @ 2018-02-14 11:16 UTC (permalink / raw)
To: pavan95 <pavan.postgresdba@gmail.com>; pgsql-admin
pavan95 wrote:
> Do you know how does it calculate internally using what functions or what
> system catalogs or whatever?
The functions are in backend/utils/adt/dbsize.c, note in particular
db_dir_size which walks through a directory and adds up the sizes of
all files therein.
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Calculation of Database Size in postgres
@ 2018-02-14 12:21 pavan95 <pavan.postgresdba@gmail.com>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 6+ messages in thread
From: pavan95 @ 2018-02-14 12:21 UTC (permalink / raw)
To: pgsql-admin
Ok, In that case some data files(which in turn consists pages) might be
partially filled.
In that case the size of the database with data will be different to the
size of the database calculated with respect to files size on disk.
So how to calculate the size of only data and not the free space in the
database?
Regards,
Pavan
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-admin-f2076596.html
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Calculation of Database Size in postgres
@ 2018-02-14 14:25 Stephen Frost <sfrost@snowman.net>
parent: pavan95 <pavan.postgresdba@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Stephen Frost @ 2018-02-14 14:25 UTC (permalink / raw)
To: pavan95 <pavan.postgresdba@gmail.com>; +Cc: pgsql-admin
Greetings,
* pavan95 (pavan.postgresdba@gmail.com) wrote:
> Ok, In that case some data files(which in turn consists pages) might be
> partially filled.
>
> In that case the size of the database with data will be different to the
> size of the database calculated with respect to files size on disk.
>
> So how to calculate the size of only data and not the free space in the
> database?
You can look at the free space map using the pg_freespacemap extension,
or you can use the pgstattuple extension to look at free space in both
the heap and the indexes. Note that pgstattuple will scan the table,
while the freespacemap extension just looks at the FSM.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2018-02-14 14:25 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-02-14 10:17 Calculation of Database Size in postgres pavan95 <pavan.postgresdba@gmail.com>
2018-02-14 10:21 ` Laurenz Albe <laurenz.albe@cybertec.at>
2018-02-14 10:23 ` pavan95 <pavan.postgresdba@gmail.com>
2018-02-14 11:16 ` Laurenz Albe <laurenz.albe@cybertec.at>
2018-02-14 12:21 ` pavan95 <pavan.postgresdba@gmail.com>
2018-02-14 14:25 ` Stephen Frost <sfrost@snowman.net>
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