Re: Attach tabla con datos a partición nativa

From: Hellmuth Vargas <hivs77(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Lista Postgres ES <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Attach tabla con datos a partición nativa
Date: 2021-05-03 16:11:06
Message-ID: CAN3Qy4osZBgOT31yyOwOPxUSNmirtsX1sUBk7+8x0nyPTx0mCw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Hola Alvaro

Efectivamente, hice la prueba

create table public.llamadas_with_pklocal as select * from public.llamadas;
alter table public.llamadas_with_pklocal alter column id set not null;
alter table public.llamadas_with_pklocal alter column fecha set not null;
alter table public.llamadas_with_pklocal alter column uniqueid set not null;
alter table public.llamadas_with_pklocal alter column tipo_evento set not
null;

alter table public.llamadas_with_pklocal add primary key (id, fecha);

checkpoint

CREATE TABLE public.llamadas_particion_pklocal
(
id bigserial NOT NULL,
fecha timestamp with time zone NOT NULL,
uniqueid character varying(255) NOT NULL,
tipo_evento character varying(255) NOT NULL,
CONSTRAINT llamadas_particion_pklocal_pkey PRIMARY KEY (id,fecha)
)PARTITION BY RANGE(fecha);

checkpoint

/*
bash-4.1$ du --max-depth=1
16 ./log
16 ./pg_logical
4 ./pg_commit_ts
1616756 ./base
28 ./pg_multixact
4 ./pg_serial
12 ./pg_subtrans
12 ./pg_notify
4 ./pg_tblspc
1900552 ./pg_wal
48 ./pg_stat_tmp
4 ./pg_stat
4 ./pg_replslot
4 ./pg_snapshots
4 ./pg_twophase
584 ./global
4 ./pg_dynshmem
12 ./pg_xact
3518128 .

*/

ALTER TABLE public.llamadas_particion_pklocal ATTACH PARTITION
public.llamadas_with_pklocal FOR VALUES FROM ('2020-11-01 00:00:00' ) TO
('2021-03-30 23:59:59');
-- Query returned successfully with no result in 1.6 secs.

checkpoint

/*
bash-4.1$ du --max-depth=1
16 ./log
16 ./pg_logical
4 ./pg_commit_ts
1616756 ./base
28 ./pg_multixact
4 ./pg_serial
12 ./pg_subtrans
12 ./pg_notify
4 ./pg_tblspc
1900552 ./pg_wal
48 ./pg_stat_tmp
4 ./pg_stat
4 ./pg_replslot
4 ./pg_snapshots
4 ./pg_twophase
584 ./global
4 ./pg_dynshmem
12 ./pg_xact
3518128 .

*/

Muchas Gracias!!!

El lun, 3 de may. de 2021 a la(s) 10:44, Alvaro Herrera (
alvherre(at)alvh(dot)no-ip(dot)org) escribió:

> Hellmuth Vargas escribió:
> > Hola Avaro
> >
> > Hice el correspondiente laboratorio en una instancia dedicada de
> PostgreSQL
> > 11.11, uno con una tabla "padre" con primariy key definido y otra con
> tabla
> > "padre" sin el primary key, aqui los resultados
>
> Eh, me expresé mal (error de cafeína insuficiente). Lo que yo quería
> sugerir es que en la *partición* crearas el índice antes de hacer el
> ATTACH. Eso lo puedes hacer con CONCURRENTLY. Al momento de hacer
> ATTACH, el sistema va a detectar que el índice que necesita ya existe y
> entonces no necesita crearlo. Eso sí, tiene que ser un índice con
> exactamente las mismas propiedades que el que está en la tabla padre.
>
> --
> Álvaro Herrera 39°49'30"S 73°17'W
>

--
Cordialmente,

Ing. Hellmuth I. Vargas S.
Esp. Telemática y Negocios por Internet
Oracle Database 10g Administrator Certified Associate
EnterpriseDB Certified PostgreSQL 9.3 Associate

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2021-05-03 16:15:59 Re: Attach tabla con datos a partición nativa
Previous Message Alvaro Herrera 2021-05-03 15:44:25 Re: Attach tabla con datos a partición nativa