pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedDB size
9+ messages / 6 participants
[nested] [flat]
* DB size
@ 2021-04-26 20:24 luis.roberto@siscobra.com.br
2021-04-26 20:40 ` Re: DB size Josef Šimánek <josef.simanek@gmail.com>
2021-04-26 20:45 ` Re: DB size Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 2 replies; 9+ messages in thread
From: luis.roberto@siscobra.com.br @ 2021-04-26 20:24 UTC (permalink / raw)
To: pgsql-general <pgsql-general@lists.postgresql.org>
Hi!
I've looked around, but could only find very old answers to this question, and maybe it changed since then...
I'm struggling to identify the cause of the difference in size between the sum of all relations (via pg_total_relation_size) and pg_database_size:
SELECT sum(pg_total_relation_size(relid)),
pg_size_pretty(sum(pg_total_relation_size(relid)))
FROM pg_catalog.pg_stat_all_tables
sum |pg_size_pretty|
------------+--------------+
518549716992|483 GB |
SELECT pg_database_size('mydb'),
pg_size_pretty(pg_database_size('mydb'))
pg_database_size|pg_size_pretty|
----------------+--------------+
869150909087|809 GB |
There are three databases in the cluster, apart from 'mydb' (one of them is the 'postgres' database). These other two size about 8MB each.
We run pg_repack weekly and recently had crashes related to disk running out of space, so my guess is something got 'lost' during repack.
What can I do to recover the wasted space?
Thanks!
Luis R. Weck
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: DB size
2021-04-26 20:24 DB size luis.roberto@siscobra.com.br
@ 2021-04-26 20:40 ` Josef Šimánek <josef.simanek@gmail.com>
2021-04-26 20:50 ` Re: DB size luis.roberto@siscobra.com.br
1 sibling, 1 reply; 9+ messages in thread
From: Josef Šimánek @ 2021-04-26 20:40 UTC (permalink / raw)
To: luis.roberto@siscobra.com.br; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
po 26. 4. 2021 v 22:25 odesílatel <luis.roberto@siscobra.com.br> napsal:
>
> Hi!
>
> I've looked around, but could only find very old answers to this question, and maybe it changed since then...
>
> I'm struggling to identify the cause of the difference in size between the sum of all relations (via pg_total_relation_size) and pg_database_size:
>
> SELECT sum(pg_total_relation_size(relid)),
> pg_size_pretty(sum(pg_total_relation_size(relid)))
> FROM pg_catalog.pg_stat_all_tables
>
>
> sum |pg_size_pretty|
> ------------+--------------+
> 518549716992|483 GB |
>
>
> SELECT pg_database_size('mydb'),
> pg_size_pretty(pg_database_size('mydb'))
>
>
> pg_database_size|pg_size_pretty|
> ----------------+--------------+
> 869150909087|809 GB |
>
> There are three databases in the cluster, apart from 'mydb' (one of them is the 'postgres' database). These other two size about 8MB each.
Do you have any indexes in mydb database?
>
> We run pg_repack weekly and recently had crashes related to disk running out of space, so my guess is something got 'lost' during repack.
>
> What can I do to recover the wasted space?
>
> Thanks!
>
> Luis R. Weck
>
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: DB size
2021-04-26 20:24 DB size luis.roberto@siscobra.com.br
2021-04-26 20:40 ` Re: DB size Josef Šimánek <josef.simanek@gmail.com>
@ 2021-04-26 20:50 ` luis.roberto@siscobra.com.br
0 siblings, 0 replies; 9+ messages in thread
From: luis.roberto@siscobra.com.br @ 2021-04-26 20:50 UTC (permalink / raw)
To: Josef Šimánek <josef.simanek@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
----- Mensagem original -----
> De: "Josef Šimánek" <josef.simanek@gmail.com>
> Para: "luis.roberto" <luis.roberto@siscobra.com.br>
> Cc: "pgsql-general" <pgsql-general@lists.postgresql.org>
> Enviadas: Segunda-feira, 26 de abril de 2021 17:40:05
> Assunto: Re: DB size
> Do you have any indexes in mydb database?
Yes, I do. I believe pg_total_relation_size accounts for these. These are the results for my biggest table:
SELECT pg_table_size('my_table'),
pg_size_pretty(pg_table_size('my_table')) AS tb_pretty,
pg_indexes_size('my_table'),
pg_size_pretty(pg_indexes_size('my_table')) AS idx_pretty,
pg_total_relation_size('my_table'),
pg_size_pretty(pg_total_relation_size('my_table')) AS total_pretty
pg_table_size|tb_pretty|pg_indexes_size|idx_pretty|pg_total_relation_size|total_pretty|
-------------+---------+---------------+----------+----------------------+------------+
82016485376|76 GB | 88119033856|82 GB | 170135519232|158 GB |
Luis R. Weck
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: DB size
2021-04-26 20:24 DB size luis.roberto@siscobra.com.br
@ 2021-04-26 20:45 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-04-26 20:59 ` Re: DB size luis.roberto@siscobra.com.br
2021-04-27 06:58 ` Re: DB size Laurenz Albe <laurenz.albe@cybertec.at>
1 sibling, 2 replies; 9+ messages in thread
From: Alvaro Herrera @ 2021-04-26 20:45 UTC (permalink / raw)
To: luis.roberto@siscobra.com.br; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
On 2021-Apr-26, luis.roberto@siscobra.com.br wrote:
> SELECT sum(pg_total_relation_size(relid)),
> pg_size_pretty(sum(pg_total_relation_size(relid)))
> FROM pg_catalog.pg_stat_all_tables
>
>
> sum |pg_size_pretty|
> ------------+--------------+
> 518549716992|483 GB |
>
>
> SELECT pg_database_size('mydb'),
> pg_size_pretty(pg_database_size('mydb'))
>
>
> pg_database_size|pg_size_pretty|
> ----------------+--------------+
> 869150909087|809 GB |
>
> There are three databases in the cluster, apart from 'mydb' (one of
> them is the 'postgres' database). These other two size about 8MB each.
I would guess that there are leftover files because of those crashes you
mentioned. You can probably look for files in the database subdir in
the data directory that do not appear in the pg_class.relfilenode
listing for the database.
--
Álvaro Herrera 39°49'30"S 73°17'W
<inflex> really, I see PHP as like a strange amalgamation of C, Perl, Shell
<crab> inflex: you know that "amalgam" means "mixture with mercury",
more or less, right?
<crab> i.e., "deadly poison"
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: DB size
2021-04-26 20:24 DB size luis.roberto@siscobra.com.br
2021-04-26 20:45 ` Re: DB size Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2021-04-26 20:59 ` luis.roberto@siscobra.com.br
2021-04-27 06:57 ` Re: DB size Guillaume Lelarge <guillaume@lelarge.info>
1 sibling, 1 reply; 9+ messages in thread
From: luis.roberto@siscobra.com.br @ 2021-04-26 20:59 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
----- Mensagem original -----
> De: "Alvaro Herrera" <alvherre@alvh.no-ip.org>
> Para: "luis.roberto" <luis.roberto@siscobra.com.br>
> Cc: "pgsql-general" <pgsql-general@lists.postgresql.org>
> Enviadas: Segunda-feira, 26 de abril de 2021 17:45:34
> Assunto: Re: DB size
> I would guess that there are leftover files because of those crashes you
> mentioned. You can probably look for files in the database subdir in
> the data directory that do not appear in the pg_class.relfilenode
> listing for the database.
> --
> Álvaro Herrera 39°49'30"S 73°17'W
> <inflex> really, I see PHP as like a strange amalgamation of C, Perl, Shell
> <crab> inflex: you know that "amalgam" means "mixture with mercury",
> more or less, right?
> <crab> i.e., "deadly poison"
Thanks Alvaro!
That's what I read in an old thread, back in the 8.3 days... Can you point me in the right direction as to where sould I look and how do I know which files exactly are safe to remove?
Luis R. Weck
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: DB size
2021-04-26 20:24 DB size luis.roberto@siscobra.com.br
2021-04-26 20:45 ` Re: DB size Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-04-26 20:59 ` Re: DB size luis.roberto@siscobra.com.br
@ 2021-04-27 06:57 ` Guillaume Lelarge <guillaume@lelarge.info>
0 siblings, 0 replies; 9+ messages in thread
From: Guillaume Lelarge @ 2021-04-27 06:57 UTC (permalink / raw)
To: luis.roberto@siscobra.com.br; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; pgsql-general <pgsql-general@lists.postgresql.org>
Hi,
Le lun. 26 avr. 2021 à 22:59, <luis.roberto@siscobra.com.br> a écrit :
>
> ----- Mensagem original -----
> > De: "Alvaro Herrera" <alvherre@alvh.no-ip.org>
> > Para: "luis.roberto" <luis.roberto@siscobra.com.br>
> > Cc: "pgsql-general" <pgsql-general@lists.postgresql.org>
> > Enviadas: Segunda-feira, 26 de abril de 2021 17:45:34
> > Assunto: Re: DB size
>
> > I would guess that there are leftover files because of those crashes you
> > mentioned. You can probably look for files in the database subdir in
> > the data directory that do not appear in the pg_class.relfilenode
> > listing for the database.
>
> > --
> > Álvaro Herrera 39°49'30"S 73°17'W
> > <inflex> really, I see PHP as like a strange amalgamation of C, Perl,
> Shell
> > <crab> inflex: you know that "amalgam" means "mixture with mercury",
> > more or less, right?
> > <crab> i.e., "deadly poison"
>
>
> Thanks Alvaro!
>
> That's what I read in an old thread, back in the 8.3 days... Can you point
> me in the right direction as to where sould I look and how do I know which
> files exactly are safe to remove?
>
>
pg_orphaned is probably what you need. See
https://github.com/bdrouvot/pg_orphaned for details.
--
Guillaume.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: DB size
2021-04-26 20:24 DB size luis.roberto@siscobra.com.br
2021-04-26 20:45 ` Re: DB size Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2021-04-27 06:58 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-27 07:05 ` Re: DB size Magnus Hagander <magnus@hagander.net>
1 sibling, 1 reply; 9+ messages in thread
From: Laurenz Albe @ 2021-04-27 06:58 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; luis.roberto@siscobra.com.br; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
On Mon, 2021-04-26 at 16:45 -0400, Alvaro Herrera wrote:
> I would guess that there are leftover files because of those crashes you
> mentioned. You can probably look for files in the database subdir in
> the data directory that do not appear in the pg_class.relfilenode
> listing for the database.
Not all tables have their "relfilenode" set:
SELECT relfilenode FROM pg_class WHERE relname = 'pg_class';
relfilenode
═════════════
0
(1 row)
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: DB size
2021-04-26 20:24 DB size luis.roberto@siscobra.com.br
2021-04-26 20:45 ` Re: DB size Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-04-27 06:58 ` Re: DB size Laurenz Albe <laurenz.albe@cybertec.at>
@ 2021-04-27 07:05 ` Magnus Hagander <magnus@hagander.net>
2021-04-27 11:16 ` Re: DB size luis.roberto@siscobra.com.br
0 siblings, 1 reply; 9+ messages in thread
From: Magnus Hagander @ 2021-04-27 07:05 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; luis.roberto@siscobra.com.br, pgsql-general <pgsql-general@lists.postgresql.org>
On Tue, Apr 27, 2021 at 8:59 AM Laurenz Albe <laurenz.albe@cybertec.at> wrote:
>
> On Mon, 2021-04-26 at 16:45 -0400, Alvaro Herrera wrote:
> > I would guess that there are leftover files because of those crashes you
> > mentioned. You can probably look for files in the database subdir in
> > the data directory that do not appear in the pg_class.relfilenode
> > listing for the database.
>
> Not all tables have their "relfilenode" set:
>
> SELECT relfilenode FROM pg_class WHERE relname = 'pg_class';
> relfilenode
> ═════════════
> 0
> (1 row)
Yeah, you want to use pg_relation_filenode(oid) rather than looking
directly at relfilenode.
When compared to the filesystem, it's probably even easier to use
pg_relation_filepath(oid).
--
Magnus Hagander
Me: https://www.hagander.net/
Work: https://www.redpill-linpro.com/
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: DB size
2021-04-26 20:24 DB size luis.roberto@siscobra.com.br
2021-04-26 20:45 ` Re: DB size Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-04-27 06:58 ` Re: DB size Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-27 07:05 ` Re: DB size Magnus Hagander <magnus@hagander.net>
@ 2021-04-27 11:16 ` luis.roberto@siscobra.com.br
0 siblings, 0 replies; 9+ messages in thread
From: luis.roberto@siscobra.com.br @ 2021-04-27 11:16 UTC (permalink / raw)
To: Magnus Hagander <magnus@hagander.net>; +Cc: Laurenz Albe <laurenz.albe@cybertec.at>; Alvaro Herrera <alvherre@alvh.no-ip.org>; pgsql-general <pgsql-general@lists.postgresql.org>
----- Mensagem original -----
> De: "Magnus Hagander" <magnus@hagander.net>
> Para: "Laurenz Albe" <laurenz.albe@cybertec.at>
> Cc: "Alvaro Herrera" <alvherre@alvh.no-ip.org>, "luis.roberto" <luis.roberto@siscobra.com.br>, "pgsql-general"
> <pgsql-general@lists.postgresql.org>
> Enviadas: Terça-feira, 27 de abril de 2021 4:05:42
> Assunto: Re: DB size
> Yeah, you want to use pg_relation_filenode(oid) rather than looking
> directly at relfilenode.
>
> When compared to the filesystem, it's probably even easier to use
> pg_relation_filepath(oid).
>
> --
> Magnus Hagander
> Me: https://www.hagander.net/
> Work: https://www.redpill-linpro.com/
Thanks all!
Looks like pg_orphaned is what I need! I'll use pg_relation_filepath too to double check.
Luis R. Weck
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2021-04-27 11:16 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-26 20:24 DB size luis.roberto@siscobra.com.br
2021-04-26 20:40 ` Josef Šimánek <josef.simanek@gmail.com>
2021-04-26 20:50 ` luis.roberto@siscobra.com.br
2021-04-26 20:45 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-04-26 20:59 ` luis.roberto@siscobra.com.br
2021-04-27 06:57 ` Guillaume Lelarge <guillaume@lelarge.info>
2021-04-27 06:58 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-27 07:05 ` Magnus Hagander <magnus@hagander.net>
2021-04-27 11:16 ` luis.roberto@siscobra.com.br
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