Why is my empty postgres database at 7 MB?

I just created a new database and it already takes 7 MB. Do you know what takes up a lot of space? Is there a way to get the "real" database size used in how much data is stored?

0f41ba72-a1ea-4516-a9f0-de8a3609bc4a=> select pg_size_pretty(pg_database_size(current_database()));
 pg_size_pretty 
----------------
 7055 kB
(1 row)

0f41ba72-a1ea-4516-a9f0-de8a3609bc4a=> \dt
No relations found.
+4
source share
3 answers

Well, even you have not created any relationship yet, but the new database is not empty. When issued CREATE DATABASE, Postgres copies the database TEMPLATEthat comes with the catalog tables to the new database. In fact, "nothing is created, everything is transformed." You can use the following commands to verify this:

--Size per table
SELECT pg_size_pretty(pg_total_relation_size(oid)), relname FROM pg_class WHERE relkind = 'r' AND NOT relisshared;

--Total size
SELECT pg_size_pretty(sum(pg_total_relation_size(oid))) FROM pg_class WHERE relkind = 'r' AND NOT relisshared;

--Total size of databases
SELECT pg_size_pretty(pg_database_size(oid)), datname FROM pg_database;

Quote from docs :

.

+3

.

, :

select nspname as schema, relname as table, pg_total_relation_size(c.oid)
from pg_class c
join pg_namespace n on n.oid = relnamespace
order by 3 desc;

       schema       |            table            | pg_total_relation_size 
--------------------+-----------------------------+------------------------
 pg_catalog         | pg_depend                   |                1146880
 pg_catalog         | pg_proc                     |                 950272
 pg_catalog         | pg_rewrite                  |                 589824
 pg_catalog         | pg_attribute                |                 581632
... etc

:

select sum(pg_total_relation_size(c.oid))
from pg_class c
join pg_namespace n on n.oid = relnamespace
where nspname not in ('information_schema', 'pg_catalog', 'pg_toast');

null .

+2

PostgreSQL . 7MB. . PostgreSQL - 1 , .

, , SQLite Firebird.

0

Source: https://habr.com/ru/post/1680024/


All Articles