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?
UNIQUEon every column doesn't really make sense to me, but: each unique constraint is implemented through a unique index. So you have 6 indexes on that table, one for each column (except the customer_type). – Dec 14 '17 at 13:10http://localhost:8051/#/details-pg/pg10isn't helpful - my computer has no application listening on port 8051 – Dec 14 '17 at 13:10The link is just you know from where I got the size information (web postgres admin interface) since I dont know if rightclick on the db folder reflect the actual size.
– A.c Dec 14 '17 at 13:18CUSTOMER_TYPE PRIVATEKEYTYPE.CUSTOMER_TYPEis the type name, guess you reversed that. Reveals that you altered the table definition manually for the question, which may have introduced errors in translation. – Erwin Brandstetter Dec 14 '17 at 15:09