I have a short question concerning my database size. I need to insert data in a database. Before the insert, some calculations need to be done.
The point is: from 50 mb plain data (~700,000 lines), this results in 600 mb db size. This is a factor 12! I am sure I am doing something wrong here. Could you help me to reduze the size of my db? Source of database size is the web postgres admin interface.
Here's the insert:
CREATE TYPE CUSTOMER_TYPE AS ENUM
('enum1', 'enum2', 'enum3', '...', 'enum15'); ## max lenght of enum names ~15
CREATE TABLE CUSTOMER(
CUSTOMER_ONE TEXT PRIMARY KEY NOT NULL, ## max 35 char String
ATTRIBUTE_ONE TEXT UNIQUE, ## max 35 char String
ATTRIBUTE_TWO TEXT UNIQUE, ## max 51 char String
ATTRIBUTE_THREE TEXT UNIQUE, ## max 52 char String
ATTRIBUTE_FOUR TEXT UNIQUE, ## max 64 char String
ATTRIBUTE_FIFE TEXT UNIQUE, ## 1-80 char String
CUSTOMER_TYPE PRIVATEKEYTYPE ## see enum
);
I don't really need that enum since I can insert it without, too. Does a enum have an effect on the database size?
Is there a way to reduce the size? Is it possible to reach factor x4 (instead of x12)? If not, I could delete some of the columns, if necessary.
Maybe there are other Postgres data types for character data?
After feedback here, my updated table looks now like this:
CREATE TABLE CUSTOMER(
CUSTOMER_ONE TEXT PRIMARY KEY NOT NULL, ## max 35 char String
ATTRIBUTE_ONE TEXT UNIQUE, ## max 35 char String
ATTRIBUTE_TWO TEXT, ## max 51 char String
ATTRIBUTE_THREE TEXT, ## max 52 char String
ATTRIBUTE_FOUR TEXT, ## max 64 char String
ATTRIBUTE_FIFE TEXT, ## 1-80 char String
CUSTOMER_TYPE PRIVATEKEYTYPE ## see enum
);
Before: 12x
Now: 7x :)
Are there any more possible optimizations? (Except deleting columns?) Maybe other data types using less space?