PostgreSQL La base de donnees la plus sophistiquee au monde.

Forums PostgreSQL.fr

Le forum officiel de la communauté francophone de PostgreSQL

Vous n'êtes pas identifié(e).

#1 24/01/2023 10:00:42

duple
Membre

partitionnement, copy et ressource :

Bonjour,
Nous avons une assez large table avec à peu près 2millins d'enregistrement. Nous voulons exécuter la commande suivante: ALTER TABLE la_table  ATTACH PARTITION new_table FOR VALUES IN (NULL);
Cette commande met environ 8h à s'executer, il y aurait il moyen d'améliorer ce temps de traitement ? Entre autre, connaitriez vous quel paramètre entre en jeu lors de l'execution de cette commande ? (shared_buffer ? work_mem ? maintenance_work_mem ?)
Par ailleurs, à peu près la même question pour une commande copy => çà joue avec shared_buffer ou work_mem ?

Merci déjà de l'attention que vous porteriez sur le sujet.
Cordialement,

Hors ligne

#2 24/01/2023 10:14:25

Marc Cousin
Membre

Re : partitionnement, copy et ressource :

Vous avez tous les index qui doivent être là sur la partition finale ? Comme le dit la doc, "This form attaches an existing table (which might itself be partitioned) as a partition of the target table. The table can be attached as a partition for specific values using FOR VALUES or as a default partition by using DEFAULT. For each index in the target table, a corresponding one will be created in the attached table; or, if an equivalent index already exists, it will be attached to the target table's index, as if ALTER INDEX ATTACH PARTITION had been executed". Donc si il manque des index, ils vont être créés au moment de l'ALTER TABLE, alors que vous pourriez les avoir pré-créés (éventuellement en CONCURRENTLY, je ne connais pas votre cas d'utilisation).
Il peut aussi se retrouver à faire une vérification de votre "FOR VALUES" si il n'y a pas de contrainte CHECK sur la partition au moment de l'ATTACH: "If the new partition is a regular table, a full table scan is performed to check that existing rows in the table do not violate the partition constraint. It is possible to avoid this scan by adding a valid CHECK constraint to the table that allows only rows satisfying the desired partition constraint before running this command. The CHECK constraint will be used to determine that the table need not be scanned to validate the partition constraint. This does not work, however, if any of the partition keys is an expression and the partition does not accept NULL values. If attaching a list partition that will not accept NULL values, also add NOT NULL constraint to the partition key column, unless it's an expression."


Marc.

Hors ligne

#3 24/01/2023 14:24:30

duple
Membre

Re : partitionnement, copy et ressource :

Merci,

Et si la table à attacher possède des index, celles si  resteront donc toujours comme index de la nouvelle partition de la table cible et ne seront pas recréé au moment de l'ATTACH ?

Hors ligne

#4 24/01/2023 14:58:30

Marc Cousin
Membre

Re : partitionnement, copy et ressource :

Il me semble oui, mais regardez la doc sur ALTER TABLE, c'est assez détaillé


Marc.

Hors ligne

#5 25/01/2023 14:54:25

duple
Membre

Re : partitionnement, copy et ressource :

Ok merci beaucoup pour ces informations

Hors ligne

Pied de page des forums