Obrigado a todos pelas dicas e comentários.
   Verificando a recomendação do Teles, vi que nos logs aparecem bastante
atividade dos 'checkpoints'. Vou fazer as mudanças e testá-las em breve.
Como rever o resto das dicas.

 O OP não detalhou o ... ADD CONSTRAINT ... Pode ser tanto criação de PK

> quanto de FK. Se for o primeiro, com um m_w_m de 6GB as tabelas devem
> ter dezenas ou centenas de gigabytes. No segundo caso, pode ser
> múltiplas FKs numa mesma tabela grande ou algum plano ruim na
> verificação da FK (é possível mas acho pouco provável já que é um
> simples LEFT JOIN). Enfim, sem os comandos ALTER TABLE ... ADD
> CONSTRAINT e uma saída do pg_stat_activity e/ou pg_locks que evidenciam
> tais problemas fica difícil dizer o que está ocorrendo.
>
>
   Em relação ao tipo de operação um tempo alto que tive foi devido criação
de PK. Abaixo tem alguns logs:

2015-06-28 02:59:10 BRT [45995]: [557b1e55.b3ab] [9757-1]
db=<banco>,user=postgres,client=[local] 67257:5/9537 CONTEXT:  SQL
statement "SELECT fk."id_ponto_venda" FROM ONLY
"<esquema01>"."tb_venda_online_parcial" fk LEFT OU
TER JOIN ONLY "<esquema01>"."tb_ponto_venda" pk ON ( pk."id"
OPERATOR(pg_catalog.=) fk."id_ponto_venda") WHERE pk."id" IS NULL AND
(fk."id_ponto_venda" IS NOT NULL)"
2015-06-28 02:59:10 BRT [45995]: [557b1e55.b3ab] [9758-1]
db=<banco>,user=postgres,client=[local] 0:5/0 LOG:  duration: 7911899.043
ms  statement: ALTER TABLE ONLY tb_venda_online_parcial
            ADD CONSTRAINT tb_venda_online_parcial_fk3 FOREIGN KEY
(id_ponto_venda) REFERENCES tb_ponto_venda(id);

2015-06-28 03:02:32 BRT [45994]: [557b1e55.b3aa] [13440-1]
db=<banco>,user=postgres,client=[local] 67445:4/13221 LOG:  duration:
7252998.586 ms  plan:
        Query Text: SELECT fk."id_terminal" FROM ONLY
"<esquema02>"."tb_venda_online_parcial" fk LEFT OUTER JOIN ONLY
"<esquema02>"."tb_terminal_venda" pk ON ( pk."id" OPERATOR(pg_catalog.=)
fk."id_terminal") WHERE pk."id" IS NULL AND (fk."id_terminal" IS NOT NULL)
        Hash Anti Join  (cost=1972.95..3624761.84 rows=6621 width=8)
          Hash Cond: (fk.id_terminal = pk.id)
          ->  Seq Scan on tb_venda_online_parcial fk
(cost=0.00..2877924.20 rows=49658198 width=8)
                Filter: (id_terminal IS NOT NULL)
          ->  Hash  (cost=1482.42..1482.42 rows=39242 width=8)
                Buckets: 4096  Batches: 1  Memory Usage: 1533kB
                ->  Seq Scan on tb_terminal_venda pk  (cost=0.00..1482.42
rows=39242 width=8)

2015-06-28 03:02:32 BRT [45994]: [557b1e55.b3aa] [13441-1]
db=<banco>,user=postgres,client=[local] 67445:4/13221 CONTEXT:  SQL
statement "SELECT fk."id_terminal" FROM ONLY
"<esquema02>"."tb_venda_online_parcial" fk LEFT OUTER JOIN ONLY
"<esquema02>"."tb_terminal_venda" pk ON ( pk."id" OPERATOR(pg_catalog.=)
fk."id_terminal") WHERE pk."id" IS NULL AND (fk."id_terminal" IS NOT NULL)"
2015-06-28 03:02:32 BRT [45994]: [557b1e55.b3aa] [13442-1]
db=<banco>,user=postgres,client=[local] 0:4/0 LOG:  duration: 7253008.067
ms  statement: ALTER TABLE ONLY tb_venda_online_parcial
            ADD CONSTRAINT tb_venda_online_parcial_fk2 FOREIGN KEY
(id_terminal) REFERENCES tb_terminal_venda(id);

2015-06-28 04:57:34 BRT [45994]: [557b1e55.b3aa] [13460-1]
db=<banco>,user=postgres,client=[local] 67605:4/13240 LOG:  duration:
6901817.428 ms  plan:
        Query Text: SELECT fk."id_operador_terminal" FROM ONLY
"<esquema02>"."tb_venda_online_parcial" fk LEFT OUTER JOIN ONLY
"<esquema02>"."tb_operador_terminal" pk ON ( pk."id" OPERATOR(pg_catalog.=)
fk."id_operador_terminal") WHERE pk."id" IS NULL AND
(fk."id_operador_terminal" IS NOT NULL)
        Hash Anti Join  (cost=2740.02..3315202.42 rows=6621 width=8)
          Hash Cond: (fk.id_operador_terminal = pk.id)
          ->  Seq Scan on tb_venda_online_parcial fk
(cost=0.00..2877924.20 rows=49658198 width=8)
                Filter: (id_operador_terminal IS NOT NULL)
          ->  Hash  (cost=1696.12..1696.12 rows=83512 width=8)
                Buckets: 16384  Batches: 1  Memory Usage: 3263kB
                ->  Seq Scan on tb_operador_terminal pk
(cost=0.00..1696.12 rows=83512 width=8)
2015-06-28 04:57:34 BRT [45994]: [557b1e55.b3aa] [13461-1]
db=<banco>,user=postgres,client=[local] 67605:4/13240 CONTEXT:  SQL
statement "SELECT fk."id_operador_terminal" FROM ONLY
"<esquema02>"."tb_venda_online_parcial" fk LEFT
OUTER JOIN ONLY "<esquema02>"."tb_operador_terminal" pk ON ( pk."id"
OPERATOR(pg_catalog.=) fk."id_operador_terminal") WHERE pk."id" IS NULL AND
(fk."id_operador_terminal" IS NOT NULL)"
2015-06-28 04:57:34 BRT [45994]: [557b1e55.b3aa] [13462-1]
db=<banco>,user=postgres,client=[local] 0:4/0 LOG:  duration: 6901824.244
ms  statement: ALTER TABLE ONLY tb_venda_online_parcial
            ADD CONSTRAINT tb_venda_online_fk4 FOREIGN KEY
(id_operador_terminal) REFERENCES tb_operador_terminal(id);


   Vi também que demora na criação dos indices. Pensei em colocar um disco
dedicado com mais IOPS e criar um novo ponto de montagem para
'<base>/pgsql_tmp'.
   Assim que fizer o próximo restore e pegar novos tempos, volto a informar.

-- 
Atenciosamente,
Aldrey Galindo
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a