Ray*_*yCh 3 mysql postgresql storage types data-storage
我计划从 MySQL 迁移到 PostgreSQL,因为我想使用 TimescaleDB。
一切看起来都很好,直到我检查了 PostgreSQL (v11.2) 与 MySQL (v5.6) 使用的存储大小相比。对于完全相同的行数 (1,440,000) 和内容:
MySQL 和 PostgreSQL 的数字就像 for like(即包括索引和其他约束),PostgreSQL + TimescaleDB 有向表添加时间戳的开销。有关的表如下所示:
create table cell(
cell_id serial not null
,ts timestamp not null
,parent_id int references parent( parent_id )
,instance_id smallint
,v float
,a float
,t float
,s1 float
,s2 float
,s3 float
,s4 float
,s5 float
,primary key( cell_id )
);
create index ix_cell_pid on cell( parent_id );
create index ix_cell_inst on cell( instance_id );
Run Code Online (Sandbox Code Playgroud)
为什么 PostgreSQL 比 MySQL 占用更多的存储空间?
是否有某种方法可以将其显着降低到 MySQL 级别?
timestamp在您的情况下,添加一列不应超过 11 MB(1440000 * 8 字节,不添加填充)。
VACUUM FULL为了公平比较,您在测量大小之前是否在 Postgres 中运行过?我怀疑表和索引膨胀。
有关的:
在 MySQL 中,数据类型float是占用4 个字节的单精度浮点类型。
在 Postgres 中同样float是双精度浮点类型,占用8 个字节(别名:float8或double precision)。
这应该可以解释另外 44 MB 的差异。要将苹果与苹果进行比较,请创建具有 4 字节real列(别名float4)的 Postgres 表。注意与 MySQL 的区别, wherereal用于 8 字节浮点数!不幸的分歧。
MySQL 手册:https
://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html Postgres 手册:https : //www.postgresql.org/docs/current/datatype-numeric.html
有关的:
你显示了两个索引。根据它们的用途,一个多列索引可能能够在 Postgres 中替换两者 -在这种特殊情况下占用的磁盘空间与它替换的两个中的一个一样多(使用给定的规范节省约 50 MB)。
create index ix_cell_pid on cell( parent_id, instance_id );
Run Code Online (Sandbox Code Playgroud)
考虑: