1

我有一个像这样的表(Postgresql 9.6)

CREATE TABLE m_trade ( 
    "alias" Character Varying( 32 ),
    "ts" Bigint NOT NULL,
    "side" Character( 1 ),
    "price" Double Precision,
    "qty" Bigint );

有 50 000 000 行。

创建 timescaledb 扩展后 -

CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

我从空表创建 hyper_table -

CREATE TABLE d_trade ( 
    "alias" Character Varying( 32 ),
    "ts" Bigint NOT NULL,
    "side" Character( 1 ),
    "price" Double Precision,
    "qty" Bigint );


SELECT create_hypertable('d_trade', 'ts', chunk_time_interval => 86400 , number_partitions =>31);

在这张d_trade桌子上之后我得到

INDEX "d_trade_ts_idx"  and 

TRIGGER ts_insert_blocker BEFORE INSERT  

INSERT INTO
    "public"."d_trade"( "alias", "price", "qty", "side", "ts" )
select "alias", "price", "qty", "side", "ts" from m_trade

现在,如果我尝试m_trade通过

INSERT INTO
    "public"."m_trade"( "alias", "price", "qty", "side", "ts" )
VALUES
    ('TESTALS', 16000, 5, 2, 1545307519)

这将需要 1-1.5 毫秒,但这会延迟 4-5 毫秒

INSERT INTO
    "public"."d_trade"( "alias", "price", "qty", "side", "ts" )
VALUES
    ('TESTALS', 16000, 5, 2, 1545307519)

如何优化d_trade表上的插入速度?

4

1 回答 1

0

您如何衡量这种刀片的性能?如果您使用类似 EXPLAIN 的东西,timescaledb 需要额外的开销,这可能会使这种比较无效。尝试打开 \timing 。此外,timescaledb 在规模上比 postgresql 更好,所以我会尝试运行批处理语句,看看你是否仍然得到与上面相同的结果。

于 2019-01-19T17:55:22.450 回答