I use Postgres 12.7
I did massive insert using CopyManager.
- Input: 320GB of tab separated data
Sample row is:
2021-03-16T07:14:41.121000 588467 1900000 0 0 0 0 S 0 LITTLE_CHAR
-- around 60 bytes
Table schema is:
create table my_table
(
time TIMESTAMPTZ NOT NULL, -- 8 bytes
price integer NOT NULL, -- 4 bytes
size bigint NOT NULL, -- 8 bytes
bid integer not NULL, -- 4 bytes
ask integer not NULL, -- 4 bytes
openInterest integer not NULL, -- 4 bytes
marketCenter integer not NULL, -- 4 bytes
conditions varchar(8) not NULL, -- 8 bytes
side smallint not NULL, -- 2 bytes
symbol varchar(16) not NULL -- 16 bytes
-- 8*2 + 4*5 + 8 + 2 + 16 =
-- 16 + 20 + 10 + 16 = 62 bytes per row
);
It took 1TB on Postgres side. Three times more, what went wrong?
i was advised to run VACCUM. Why would I if there were only inserts? 24 hours of inserts.
varchar(16)
is 16 characters not 16 bytes (and has one additional byte for the length information). Depending on your data this could be up to 48 bytes if you have values that require multi-byte characters