0Pricing
PostgreSQL Performance & Query Optimization · Aula

Ajuste de E/S de disco e pontos de verificação

Ajuste o comportamento da E/S de disco e as configurações dos pontos de verificação para reduzir picos de gravação e melhorar a capacidade de resposta geral do sistema.

Ajuste de E/S de disco e pontos de verificação é uma aula grátis de PostgreSQL Performance & Query Optimization no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de PostgreSQL Performance & Query Optimization, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de PostgreSQL Performance & Query Optimization inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Disk I/O & Performance

Disk Input/Output (I/O) is a critical factor for PostgreSQL performance. It refers to how fast your database can read and write data to storage.

Slow disk I/O often becomes a major bottleneck, leading to slower query execution and overall system unresponsiveness.

Understanding and tuning I/O-related settings is key to a high-performing PostgreSQL instance.

Understanding Checkpoints

A checkpoint is a crucial process in PostgreSQL that ensures data durability and helps with crash recovery.

During a checkpoint, all "dirty" data pages (data that has been changed in memory but not yet written to disk) are flushed from the shared_buffers to the data directory on disk.

This guarantees that at least up to the checkpoint, all committed changes are safely stored on persistent storage.

The Checkpoint Process

Checkpoints are typically triggered in two main ways:

  • When a certain amount of time has passed (controlled by checkpoint_timeout).
  • When a certain amount of Write-Ahead Log (WAL) data has been generated (controlled by max_wal_size).

When a checkpoint occurs, PostgreSQL writes a special record to the WAL, indicating that all data pages prior to that point have been flushed to disk. This can be an I/O-intensive operation.

Tuning `checkpoint_timeout`

The checkpoint_timeout parameter defines the maximum time between automatic WAL checkpoints. The default is 5 minutes.

A longer timeout means checkpoints are less frequent, but each checkpoint will flush more data, potentially causing larger I/O spikes. A shorter timeout means more frequent, but smaller, I/O operations.

Finding the right balance helps smooth out disk activity.

ALTER SYSTEM SET checkpoint_timeout = '10min';
SELECT pg_reload_conf();

`max_wal_size` Parameter

The max_wal_size parameter sets the maximum size of the Write-Ahead Log (WAL) that can accumulate before a checkpoint is forced.

If the amount of WAL generated exceeds this limit, a checkpoint will occur immediately, regardless of the checkpoint_timeout setting.

Increasing this value allows more WAL to accumulate, leading to less frequent but potentially larger checkpoints. The default is 1GB.

ALTER SYSTEM SET max_wal_size = '4GB';
SELECT pg_reload_conf();

`min_wal_size` for Recovery

The min_wal_size parameter specifies the minimum size of WAL segments that should be retained. This helps ensure there's enough WAL available for recovery processes.

If WAL files are recycled too quickly, it can lead to write amplification when new WAL files are created. Setting a reasonable min_wal_size (e.g., 1GB) can help prevent this and ensure faster recovery after a crash.

ALTER SYSTEM SET min_wal_size = '1GB';
SELECT pg_reload_conf();

`checkpoint_completion_target`

This parameter determines the target fraction of checkpoint_timeout that a checkpoint should aim to complete within.

For example, if checkpoint_completion_target is 0.9 and checkpoint_timeout is 10 minutes, PostgreSQL will try to spread the checkpoint's I/O over 9 minutes.

A higher value (closer to 1.0) spreads the I/O more evenly, reducing the impact of checkpoint-related write spikes. The default is 0.9.

ALTER SYSTEM SET checkpoint_completion_target = 0.95;
SELECT pg_reload_conf();

`random_page_cost` and Planner

While not directly a checkpoint setting, random_page_cost significantly influences the query planner's decisions related to disk I/O.

It represents the planner's estimate of the cost of fetching a non-sequentially accessed disk page. The default is 4.0.

Lowering this value (e.g., to 1.0-2.0 for SSDs) tells the planner that random I/O is less expensive, potentially encouraging it to choose index scans more often. Adjust this carefully based on your storage type.

ALTER SYSTEM SET random_page_cost = 1.5;
SELECT pg_reload_conf();

OS-Level I/O Schedulers

Beyond PostgreSQL's internal settings, the operating system's I/O scheduler also plays a role in disk performance.

On Linux, common schedulers include noop (for virtualized environments/SSDs), deadline (for balanced throughput/latency), and CFQ (for fairness among processes).

Choosing the right I/O scheduler for your workload and storage type can provide further performance gains, though this is outside PostgreSQL's direct configuration.

Checkpoint Tuning Check

Which of the following PostgreSQL parameters are primarily used to control the frequency and spread of checkpoint I/O, aiming to reduce write spikes?

Disk I/O & Checkpoint Recap

In this lesson, we explored the critical role of disk I/O in PostgreSQL performance and how checkpoints ensure data durability.

We learned how to tune key parameters:

  • checkpoint_timeout: Controls checkpoint frequency.
  • max_wal_size: Limits WAL accumulation before a forced checkpoint.
  • min_wal_size: Ensures sufficient WAL retention.
  • checkpoint_completion_target: Spreads checkpoint I/O over time.
  • random_page_cost: Influences the query planner's I/O assumptions.

Properly configuring these settings can significantly reduce I/O spikes and improve overall system responsiveness.

Perguntas Frequentes

A aula “Ajuste de E/S de disco e pontos de verificação” é grátis?

Sim — o texto completo de “Ajuste de E/S de disco e pontos de verificação” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de PostgreSQL Performance & Query Optimization, atualize para CoddyKit PRO. O curso de PostgreSQL Performance & Query Optimization inclui 4 aulas no total.

O que vou aprender em “Ajuste de E/S de disco e pontos de verificação”?

Ajuste o comportamento da E/S de disco e as configurações dos pontos de verificação para reduzir picos de gravação e melhorar a capacidade de resposta geral do sistema. Você pratica PostgreSQL Performance & Query Optimization com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar PostgreSQL Performance & Query Optimization?

Nenhuma experiência prévia é necessária. PostgreSQL Performance & Query Optimization no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.

Quanto tempo leva a aula “Ajuste de E/S de disco e pontos de verificação”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de PostgreSQL Performance & Query Optimization?

Sim. Cada aula de PostgreSQL Performance & Query Optimization inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Principais parâmetros do postgresql.conf
  2. Ajuste de memória (shared_buffers, work_mem)
  3. Ajuste de E/S de disco e pontos de verificação
  4. Ajustando as constantes de custo do planejador de consultas
← Voltar para PostgreSQL Performance & Query Optimization