思有所皈,绪有所依

给万千思绪,寻一寄存之所

PostgreSQL支持全文检索,但是中文的全文检索需要安装zhparser插件。阿里云上购买的PostgreSQL,某些版本不支持,升级到14最新的小版本,或者15才支持。

阅读全文 »

表的大小如果超过了物理内存就应该分区了,分区有两种方式:

  1. 新建表可以在建表的时候指定分区字段

    1
    2
    3
    4
    5
    6
    7
    8
    9
    CREATE TABLE measurement (
    city_id int not null,
    logdate date not null,
    peaktemp int,
    unitsales int
    ) PARTITION BY RANGE (logdate);

    CREATE TABLE measurement_y2006m02 PARTITION OF measurement
    FOR VALUES FROM ('2006-02-01') TO ('2006-03-01');
  2. 对现有表使用继承和创建触发器的方式

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    CREATE TABLE measurement (
    city_id int not null,
    logdate date not null,
    peaktemp int,
    unitsales int
    );

    CREATE TABLE measurement_y2006m02 (
    CHECK ( logdate >= DATE '2006-02-01' AND logdate < DATE '2006-03-01' )
    ) INHERITS (measurement);

    CREATE INDEX measurement_y2006m02_logdate ON measurement_y2006m02 (logdate);

    CREATE OR REPLACE FUNCTION measurement_insert_trigger()
    RETURNS TRIGGER AS $$
    BEGIN
    IF ( NEW.logdate >= DATE '2006-02-01' AND
    NEW.logdate < DATE '2006-03-01' ) THEN
    INSERT INTO measurement_y2006m02 VALUES (NEW.*);
    ELSIF ( NEW.logdate >= DATE '2006-03-01' AND
    NEW.logdate < DATE '2006-04-01' ) THEN
    INSERT INTO measurement_y2006m03 VALUES (NEW.*);
    ...
    ELSIF ( NEW.logdate >= DATE '2008-01-01' AND
    NEW.logdate < DATE '2008-02-01' ) THEN
    INSERT INTO measurement_y2008m01 VALUES (NEW.*);
    ELSE
    RAISE EXCEPTION 'Date out of range. Fix the measurement_insert_trigger() function!';
    END IF;
    RETURN NULL;
    END;
    $$
    LANGUAGE plpgsql;

决定要搭一个自己的博客,是受了《程序员的思维训练:开发认知潜能的九堂课》的启发,External support is part of your mind(大脑之外的思维工具,也会成为你思维头脑的一部分)。

阅读全文 »
0%