Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2018 April PostgreSQL: Load table into Buffer Cache, Increase the Speed of Accessing data

PostgreSQL: Load table into Buffer Cache, Increase the Speed of Accessing data

SQLRam

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I am sharing a demonstration on how to load a table data into the Buffer Cache of PostgreSQL?

If your table available in the Buffer Cache, you can reduce the cost of DISK I/O. The similar feature of Memory Engine or Database In-Memory concept.

But this is not always good, because compare to DISK we have always the limited size of Memory and memory is also require of OS. But in some special cases, we can load frequently used table into Buffer Cache of PostgreSQL.

Before loading any table into the Buffer Cache, you must check the size of the table and the available size of Buffer Cache.

Using pg_prewarm module we can do this. It provides a convenient way to load relation data into either the operating system buffer cache or the PostgreSQL buffer cache.

Once you perform the below test, next question would be “How to check the status of Buffer Cache for each table?”
Please visit tomorrow’s article for this solution…

PostgreSQL: Script to check the status of Shared Buffer (Use pg_buffercache)

Please check the below demonstration:

Create two sample tables:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
CREATE TABLE tbl_ItemTransactions_1
(
TranID SERIAL
,TransactionDate TIMESTAMPTZ
,TransactionName TEXT
);
INSERT INTO tbl_ItemTransactions_1
(TransactionDate, TransactionName)
SELECT x, 'dbrnd'
FROM generate_series('2010-01-01 00:00:00'::timestamptz, '2018-02-01 00:00:00'::timestamptz,'1 minutes'::interval) a(x);
 
CREATE TABLE tbl_ItemTransactions_2
(
TranID SERIAL
,TransactionDate TIMESTAMPTZ
,TransactionName TEXT
);
INSERT INTO tbl_ItemTransactions_2
(TransactionDate, TransactionName)
SELECT x, 'dbrnd'
FROM generate_series('2010-01-01 00:00:00'::timestamptz, '2018-02-01 00:00:00'::timestamptz,'1 minutes'::interval) a(x);

Create pg_prewarm extension:

1
CREATE EXTENSION pg_prewarm;

Now, prefatch the tbl_ItemTransactions_1 table using pg_prewarm:

1
SELECT pg_prewarm('tbl_ItemTransactions_1');

Check the execution plan of tbl_ItemTransactions_1:
The execution plan of prefatched table is quite faster than normal table.

1
2
3
4
EXPLAIN ANALYZE SELECT *FROM tbl_ItemTransactions_1;
 
Planning time: 0.130 ms
Execution time: 356.237 ms

Check the execution plan of tbl_ItemTransactions_2:

1
2
3
4
EXPLAIN ANALYZE SELECT *FROM tbl_ItemTransactions_2;
 
Planning time: 0.210 ms
Execution time: 752.010 ms

Apr 8, 2018Anvesh Patel
PostgreSQL: Can't update a table without finishing execution of functionPostgreSQL: Script to check the status of Shared Buffer (Use pg_buffercache)
Comments: 1
  1. mukesh
    June 5, 2018 at 12:27 am

    wow, again new thing got to know from dbrnd. This cache solution is really working for us. thanks

    ReplyCancel

Leave a Reply Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

ImageApril 8, 2018 1 Comment PostgreSQLAnvesh Patel, Buffer Cache, database, database research and development, dbrnd, Memory Engine, pg_prewarm, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Monitoring, PostgreSQL Performance, PostgreSQL Performance Tuning, PostgreSQL Programming, PostgreSQL Tips and Tricks, Table Performance
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....