nmakb
nmakb

Reputation: 1235

Are direct reads possible in postgresql

Oracle has this concept of direct reads, where a session reads data from a table directly into its session memory bypassing buffer cache. Is something similar possible in postgres? Does a session always gets data from shared buffer?

Upvotes: 2

Views: 639

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246788

You are mixing up two things.

  • the kernel cache where the kernel caches files to serve reads and writes more efficiently

  • the database shared memory cache (shared buffers) where the database caches table and index blocks

All database use the latter (Oracle calls it “database buffer cache”), because without caching performance would be abysmal.

With direct I/O you avoid the kernel cache, that is, all read and write requests go directly to disk.

There is no way in PostgreSQL to use direct I/O.

However, it has been recognized that buffered I/O comes with its own set of problems (e.g., a write request may succeed, a sync request that tells the kernel to flush the data to disk may fail, but the next sync request for the same (unpersisted!) data may not return an error any more). Relevant people hold the opinion that it might be a good idea to move to direct I/O eventually to avoid having to deal with such problems, but that would be a major change, and I wouldn't hold my breath until it happens.

Upvotes: 2

Related Questions