M
M
Micro Null2021-04-01 10:30:39
PostgreSQL
Micro Null, 2021-04-01 10:30:39

How to store a large table with the same values?

Hi all. Need help from more experienced colleagues.

You need to create a table where a large number of records with the same values ​​will be entered.

There can be a dozen different values, but there are millions of records.

As I understand it, if you create a simple table, then it will bloat on disk for nothing.

How can you create such a table (or an index for it) so that it takes up minimal space on disk?

The table will only be populated with data. Sampling will be done infrequently and manually when necessary. The sampling rate is not important.

Thank you!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Slava Rozhnev, 2021-04-01
@micronull

For example, like this: a table of values ​​reference and a main table:

create table datavalues (
  id serial primary key,
  	value text -- json or any suitable type
);

create table manydata (
  id bigserial primary key,
  	value_id int,
  	inserted_at timestamp with time zone default current_timestamp,
  	updated_at timestamp,
    foreign key (value_id) references datavalues(id)
);
create index on manydata(value_id);

PostgreSQL fiddle

K
ky0, 2021-04-01
@ky0

And what's so terrible about millions of records? As you speak - sampling speed is not basic.
If you are worried about the place - use some kind of compression method .

A
Armenian Radio, 2021-04-01
@gbg

A million lines is nothing to worry about.
You can, to create brakes and complacency, put the base on ZFS and enable compression.

R
Romses Panagiotis, 2021-04-01
@romesses

Well, save the delta if you really need to save space.
And for the temporary series , everything has long been invented.

The sampling rate is not important.
And 3 minutes is also good?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question