DBA: cambiando los "elefantes" en el cruce

Como DBA normales, esperábamos el lanzamiento de un par de versiones menores para PostgreSQL 13, que deberían complacernos con muchas cosas útiles , y ahora estamos listos para transferir la base de datos de nuestro servicio de monitoreo para este DBMS de la versión 12 a la 13 .





Pero, ¿cómo hacer esto con un tiempo de inactividad mínimo, o mejor sin él? La funcionalidad de Contenedores de datos externos vendrá al rescate , o mejor dicho, postgres_fdw .





Estructura de la base de la fuente

Algunos detalles sobre la estructura de la base de nuestro servicio, que nos ayudan a registrar muy rápidamente los datos entrantes, los conté en los artículos "Escribiendo en PostgreSQL en la subluz: 1 host, 1 día, 1TB" y "Ahorrando un centavo en grandes volúmenes en PostgreSQL " . En pocas palabras, el particionamiento competente de la base de datos resuelve muchos problemas de rendimiento.





, 100-150GB . tst



PostgreSQL 12:





CREATE TABLE archive(
  dt
    date
, val
    integer
)
PARTITION BY RANGE(dt); --   

CREATE TABLE archive_20210401 --   
  PARTITION OF archive
    FOR VALUES FROM ('2021-04-01') TO ('2021-04-02');
    -- dt >= '2021-04-01' AND dt < '2021-04-02'

CREATE TABLE archive_20210402
  PARTITION OF archive
    FOR VALUES FROM ('2021-04-02') TO ('2021-04-03');
      
      



dt



, PARTITION BY RANGE



FOR VALUES FROM (dt) TO (dt + 1)



PARTITION BY LIST



, - , .





, :





INSERT INTO archive
VALUES
  ('2021-04-01', 1)
, ('2021-04-02', 2)
RETURNING
  tableoid::regclass
, *;
      
      



 tableoid        |  dt        | val
archive_20210401 | 2021-04-01 |   1
archive_20210402 | 2021-04-02 |   2
      
      



tableoid



- , ( - ), . "PostgreSQL Antipatterns: ".





""

, , 1-2 "" "" .





PostgreSQL 13 , . , v12 :5439



, v13 :5440



.





:





CREATE TABLE archive(
  dt
    date
, val
    integer
)
PARTITION BY RANGE(dt);

CREATE TABLE archive_20210403
  PARTITION OF archive
    FOR VALUES FROM ('2021-04-03') TO ('2021-04-04');

      
      



IMPORT FOREIGN SCHEMA, (, , ...). , , :





CREATE EXTENSION postgres_fdw;

CREATE SERVER postgresql_12
  FOREIGN DATA WRAPPER postgres_fdw
    OPTIONS (host '127.0.0.1', port '5439', dbname 'tst');

CREATE USER MAPPING FOR postgres
  SERVER postgresql_12
    OPTIONS (user 'postgres', password 'postgres');
      
      



, :





CREATE FOREIGN TABLE archive_old
  PARTITION OF archive
    FOR VALUES FROM ('-infinity') TO ('2021-04-03')
    -- dt < '2021-04-03'
  SERVER postgresql_12
    OPTIONS(table_name 'archive');
      
      



PARTITION BY RANGE



BY LIST



, .





, :





INSERT INTO archive
VALUES
  ('2021-04-01', 1)
, ('2021-04-02', 2)
, ('2021-04-03', 3)
RETURNING
  tableoid::regclass
, *;
      
      



 tableoid        |  dt        | val
archive_old      | 2021-04-01 |   1 --  
archive_old      | 2021-04-02 |   2
archive_20210403 | 2021-04-03 |   3 --  
      
      



FDW

- , FDW- updatable



, - use_remote_estimate



fetch_size



.





, FDW-, - PARTITION BY HASH



, .








All Articles