バージョンごとのドキュメント一覧

F.30. pg_prewarm — リレーションデータをバッファキャッシュにプリロードする #

<title>pg_prewarm &mdash; preload relation data into buffer caches</title>

The <filename>pg_prewarm</filename> module provides a convenient way to load relation data into either the operating system buffer cache or the <productname>PostgreSQL</productname> buffer cache. Prewarming can be performed manually using the <filename>pg_prewarm</filename> function, or can be performed automatically by including <literal>pg_prewarm</literal> in <xref linkend="guc-shared-preload-libraries"/>. In the latter case, the system will run a background worker which periodically records the contents of shared buffers in a file called <filename>autoprewarm.blocks</filename> and will, using 2 background workers, reload those same blocks after a restart. pg_prewarmはオペレーティングシステムのバッファキャッシュまたはPostgreSQLのバッファキャッシュいずれかにリレーションデータをロードするための便利な方法を提供します。 プレウォームはpg_prewarm関数を使って手動で行うこともできますし、pg_prewarmshared_preload_librariesに含めることで自動でも実行できます。 後者の場合には、システムは、定期的にautoprewarm.blocksという名前のファイルに共有バッファの内容を記録するバックグラウンドワーカーを実行し、再起動後には2つのバックグラウンドワーカー使って同じブロックを再ロードします。

F.30.1. 関数 #

<title>Functions</title>
pg_prewarm(regclass, mode text default 'buffer', fork text default 'main',
           first_block int8 default null,
           last_block int8 default null) RETURNS int8

The first argument is the relation to be prewarmed. The second argument is the prewarming method to be used, as further discussed below; the third is the relation fork to be prewarmed, usually <literal>main</literal>. The fourth argument is the first block number to prewarm (<literal>NULL</literal> is accepted as a synonym for zero). The fifth argument is the last block number to prewarm (<literal>NULL</literal> means prewarm through the last block in the relation). The return value is the number of blocks prewarmed. 第1引数はプレウォーム(あらかじめロード)したいリレーションを指定します。 第2引数はプレウォームに使用する方法を指定します。詳細は以下でさらに説明します。第3引数はプレウォームされるリレーションフォークを指定します、これは通常mainです。 第4引数は、プレウォームを開始するブロックを指定します(NULLはゼロとみなされます)。 第5引数は終了ブロックを指定します(NULL はリレーションの最後のブロックまで指定したとみなされます)。 返り値は、プレウォームされたブロック数です。

There are three available prewarming methods. <literal>prefetch</literal> issues asynchronous prefetch requests to the operating system, if this is supported, or throws an error otherwise. <literal>read</literal> reads the requested range of blocks; unlike <literal>prefetch</literal>, this is synchronous and supported on all platforms and builds, but may be slower. <literal>buffer</literal> reads the requested range of blocks into the database buffer cache. プレウォームに使用する方法としては以下の3種類が使用可能です。 prefetchは、オペレーティングシステムに非同期のプレフェッチをリクエストします。もしオペレーティングシステムやビルド時にプレフェッチをサポートしていない場合はエラーとなります。 readは、ブロックの要求された範囲を読み込みます。prefetchとは違って、すべてのプラットフォームにサポートするようにビルドされていますが、速度が遅くなります。 bufferは、データベースのバッファキャッシュに要求された範囲を読み込みます。

Note that with any of these methods, attempting to prewarm more blocks than can be cached &mdash; by the OS when using <literal>prefetch</literal> or <literal>read</literal>, or by <productname>PostgreSQL</productname> when using <literal>buffer</literal> &mdash; will likely result in lower-numbered blocks being evicted as higher numbered blocks are read in. Prewarmed data also enjoys no special protection from cache evictions, so it is possible that other system activity may evict the newly prewarmed blocks shortly after they are read; conversely, prewarming may also evict other data from cache. For these reasons, prewarming is typically most useful at startup, when caches are largely empty. これらの方法のいずれかでもキャッシュ出来るよりも多くのブロックをプレウォームしようとすると注意が必要です。prefetchreadのようなOSのキャッシュを使用する場合、または PostgreSQLbufferにキャッシュする場合、高い番号のブロックが読み込まれると低い番号のブロックが追い出されます。 プレウォームは、キャッシュに対して特別な保護をしていないので、それが他のシステムにとって可能であるように、それらが読み込まれた直後に、新しいプレウォームによって追い出すことが可能です。逆に、プレウォームはキャッシュから他のデータを追い出すこともあります。 これらの理由から、プレウォームはキャッシュが主に空のとき、一般的には起動時にもっとも有用です。

autoprewarm_start_worker() RETURNS void

Launch the main autoprewarm worker. This will normally happen automatically, but is useful if automatic prewarm was not configured at server startup time and you wish to start up the worker at a later time. 自動プレウォームワーカーを起動します。 通常これは自動的に行なわれますが、サーバーのスタート時に自動プレウォームが設定されておらず、後でワーカーを起動したい場合に有用です。

autoprewarm_dump_now() RETURNS int8

Update <filename>autoprewarm.blocks</filename> immediately. This may be useful if the autoprewarm worker is not running but you anticipate running it after the next restart. The return value is the number of records written to <filename>autoprewarm.blocks</filename>. 直ちにautoprewarm.blocksを更新します。 これは、自動プレウォームワーカーが動いていなくて、次の再起動後に自動プレウォームワーカーを動かそうと考えているときに有用かもしれません。 戻り値はautoprewarm.blocksに書き込まれたブロック数です。

F.30.2. 設定パラメータ #

<title>Configuration Parameters</title>
pg_prewarm.autoprewarm (boolean)

Controls whether the server should run the autoprewarm worker. This is on by default. This parameter can only be set at server start. サーバーが自動プレウォームワーカーを起動すべきかどうかを制御します。 デフォルトはonです。 このパラメータはサーバ起動時のみ設定可能です。

pg_prewarm.autoprewarm_interval (integer)

This is the interval between updates to <literal>autoprewarm.blocks</literal>. The default is 300 seconds. If set to 0, the file will not be dumped at regular intervals, but only when the server is shut down. これはautoprewarm.blocksを更新する間隔です。 デフォルトは300秒です。 0に設定すると、このファイルは定常間隔では更新されず、サーバーが停止する時にだけ更新されます。

These parameters must be set in <filename>postgresql.conf</filename>. Typical usage might be: これらのパラメータはpostgresql.confで設定しなければなりません。 典型的な使用法は以下の通りです。

# postgresql.conf
shared_preload_libraries = 'pg_prewarm'

pg_prewarm.autoprewarm = true
pg_prewarm.autoprewarm_interval = 300s

F.30.3. 作者 #

<title>Author</title>

Robert Haas