<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammad Adil Shahid</title>
    <description>The latest articles on DEV Community by Muhammad Adil Shahid (@muhammadadilshahid1054).</description>
    <link>https://dev.to/muhammadadilshahid1054</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1102822%2F47d9d932-0185-48cd-b80c-2bd6be96c783.png</url>
      <title>DEV Community: Muhammad Adil Shahid</title>
      <link>https://dev.to/muhammadadilshahid1054</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muhammadadilshahid1054"/>
    <language>en</language>
    <item>
      <title>Understanding the Internal Layout of the Heap Table in PostgreSQL</title>
      <dc:creator>Muhammad Adil Shahid</dc:creator>
      <pubDate>Fri, 21 Jul 2023 12:16:41 +0000</pubDate>
      <link>https://dev.to/muhammadadilshahid1054/understanding-the-internal-layout-of-the-heap-table-in-postgresql-106d</link>
      <guid>https://dev.to/muhammadadilshahid1054/understanding-the-internal-layout-of-the-heap-table-in-postgresql-106d</guid>
      <description>&lt;p&gt;The data file that basically contains the heap table and index is divided into pages of fixed length. If the data file space gets filled completely, postgreSql adds a new empty page to the end of the file.&lt;/p&gt;

&lt;p&gt;A page within a table contains three kinds of data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Heap tuple(s):&lt;/strong&gt; A heap tuple is a record data itself. They are stacked in order from the bottom of the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Line pointer(s):&lt;/strong&gt; A line pointer that is also known as &lt;em&gt;item pointer&lt;/em&gt; is a 4 byte long pointer that points to each heap tuple. Line pointers form a structure of array that represent the index of the tuples. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Header data:&lt;/strong&gt; It is the data that is added at the beginning of the page and contains general information about the page. Header data is defined by the structure PageHeaderData and 24 byte long.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Writing Heap Tuples
&lt;/h3&gt;

&lt;p&gt;While writing heap tuples, there are two main paramters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;pd_lower&lt;/code&gt; is used to point to the line pointer of the page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;pd_upper&lt;/code&gt; is used to point to the heap tuple  of the page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Reading Heap Tuples
&lt;/h3&gt;

&lt;p&gt;While reading heap tuples there are two scans in postgresql:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In &lt;strong&gt;sequential scan&lt;/strong&gt;, all tuples in all pages are sequentially read by scanning all line pointers in each page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In a &lt;strong&gt;B-tree index scan&lt;/strong&gt;, an index file contains index tuples.  Each index file is composed of an index key and a TID that points to the target heap table.&lt;br&gt;
PostgreSQL reads the heap tuple using the TID&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.tourl"&gt;https://www.interdb.jp/pg/pgsql01.html&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A brief overview on Heap Only Tuple and Index Only Scans</title>
      <dc:creator>Muhammad Adil Shahid</dc:creator>
      <pubDate>Sat, 08 Jul 2023 20:12:00 +0000</pubDate>
      <link>https://dev.to/muhammadadilshahid1054/a-brief-overview-on-heap-only-tuple-and-index-only-scans-3pf7</link>
      <guid>https://dev.to/muhammadadilshahid1054/a-brief-overview-on-heap-only-tuple-and-index-only-scans-3pf7</guid>
      <description>&lt;p&gt;Here we are going to discuss two features of postgresSQL that are very useful in enhancing its performance i.e.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Heap Only Tuple (HOT)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Index Only Scan&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Heap Only Tuple
&lt;/h2&gt;

&lt;p&gt;So basically in postgresSQL, when a row/tuple is updated, it is added as the new version. That tuple will have two versions the old one that is marked as deleted and the updated one that is marked as updated. But there is a problem in this case i.e. we have to manage two versions of a row.&lt;/p&gt;

&lt;p&gt;To solve this problem, we use HOT. In Heap only tuple, we check the space on the page where old version tuple is located and if there is enough space, we create the updated version on the same page where old version is present.&lt;/p&gt;

&lt;h2&gt;
  
  
  Index Only Scan
&lt;/h2&gt;

&lt;p&gt;In psotgresSQL, when a database query needs the index and data of column, we have to go to the table to get that column. This process involves a lot of disk I/O and eventually this thing results in very slow execution of query.&lt;/p&gt;

&lt;p&gt;To solve this problem, here comes the index only scans. To reduce that I/O cost, index-only scans directly use the index key without accessing the corresponding table page when all entries of the SELECT statement are included in the index key. But there is certain criteria to use index-only scans:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The query must retrieve only those columns that are included in index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Index type must support index-only scans such as b-tree index.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.tourl"&gt;https://www.interdb.jp/pg/pgsql07.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.tourl"&gt;https://www.postgresql.org/docs/current/indexes-index-only-scans.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgres</category>
      <category>postgressql</category>
    </item>
    <item>
      <title>Vacuum Processing in PostgresSQL</title>
      <dc:creator>Muhammad Adil Shahid</dc:creator>
      <pubDate>Thu, 29 Jun 2023 19:26:24 +0000</pubDate>
      <link>https://dev.to/muhammadadilshahid1054/vacuum-processing-in-postgressql-240k</link>
      <guid>https://dev.to/muhammadadilshahid1054/vacuum-processing-in-postgressql-240k</guid>
      <description>&lt;p&gt;Vacuum processing is one of the core mechanism in PostgresSQL. It basically involves the removal of dead tuples in the database. In order to remove the dead tuples, it involves two modes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Concurrent VACUUM&lt;/li&gt;
&lt;li&gt;Full VACUUM&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Concurrent VACUUM:
&lt;/h2&gt;

&lt;p&gt;Concurrent VACUUM also known as VACUUM. It removes dead tuple for each page of the table and other transactions can read the data while the process is still running. It involves three blocks:&lt;/p&gt;

&lt;h4&gt;
  
  
  First Block:
&lt;/h4&gt;

&lt;p&gt;This block performs the freeze processing and removes index tuples that points to dead tuples.&lt;/p&gt;

&lt;h4&gt;
  
  
  Second Block:
&lt;/h4&gt;

&lt;p&gt;This block removes the dead tuples and update both Free space map (FSM) and Visibility map (VM).&lt;/p&gt;

&lt;h4&gt;
  
  
  Third Block:
&lt;/h4&gt;

&lt;p&gt;This block performs the cleanup after the deletion of indexes and update both the statistics and the system catalog.&lt;/p&gt;

&lt;h4&gt;
  
  
  Post-processing:
&lt;/h4&gt;

&lt;p&gt;When the vacuum processing is complete, after updating both statistics and system catalogs related to vacuum processing, it removes unnecessary parts of the clog if possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Visiblity Map:
&lt;/h2&gt;

&lt;p&gt;Vacuum processing is quite costly so visibility map was introduced. Each table has a visibility map that holds the visibility of the page in table file and determines the dead tuples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Freeze Processing:
&lt;/h2&gt;

&lt;p&gt;Freeze Processing has two modes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lazy Mode:&lt;/strong&gt; When freeze processing scans only pages that contain dead tuples using the visibility map of the target tables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Eager Mode:&lt;/strong&gt; It scans all pages to inspect all tuples in tables and update relevant system catalogs and removes unnecessary files.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Full VACUUM:
&lt;/h2&gt;

&lt;p&gt;Concurrent vacuum is essential but it is not sufficient so here comes the full vacuum. It not only removes the dead tuples but also reduced the table size. But two things should be considered here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nobody can access the table when Full VACUUM is processing.&lt;/li&gt;
&lt;li&gt;At most twice the disk space is used temporarily.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.tourl"&gt;https://www.interdb.jp/pg/pgsql06.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>sql</category>
      <category>postgressql</category>
    </item>
    <item>
      <title>Concurrency Control in PostgresSQL</title>
      <dc:creator>Muhammad Adil Shahid</dc:creator>
      <pubDate>Thu, 29 Jun 2023 18:16:15 +0000</pubDate>
      <link>https://dev.to/muhammadadilshahid1054/concurrency-control-in-postgressql-2oe</link>
      <guid>https://dev.to/muhammadadilshahid1054/concurrency-control-in-postgressql-2oe</guid>
      <description>&lt;p&gt;Concurrency control is the process of maintaining atomicity and isolation when two transactions run concurrently in the database. &lt;/p&gt;

&lt;p&gt;There are three types of concurrency control techniques:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-version Concurrency Control (MVCC)&lt;/strong&gt; is the technique that allows multiple transactions in database without blocking each other. PostgresSQL and some other RDMS uses the version of MVCC called as &lt;strong&gt;Snapshot Isolation (SI)&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Strict Two-Phase Locking (S2PL)&lt;/strong&gt; is the technique that uses locks while accessing the shared resources in database. It means that if one transactions is happening, the lock will prevent other transactions to access the shared resource.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Optimistic Concurrency Control&lt;/strong&gt; works by reducing the need of locks during transactions in database. It supposes that the conflicts are not often. As described by its name, OCC works optimistically and allows transactions to happen but if the conflict occurs,  OCC revert the transaction that causes the conflict.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Transaction ID:
&lt;/h3&gt;

&lt;p&gt;The unique identifier (txid) assigned by the transaction manager to a transaction is known as transaction ID.&lt;/p&gt;

&lt;p&gt;PostgresSQL has three types of txids:&lt;br&gt;
&lt;strong&gt;0&lt;/strong&gt; means invalid txid.&lt;br&gt;
&lt;strong&gt;1&lt;/strong&gt; means Bootstrap that is used in the initialization of database cluster.&lt;br&gt;
&lt;strong&gt;2&lt;/strong&gt; means Frozen txid that is used in the for MVCC.&lt;/p&gt;

&lt;h3&gt;
  
  
  Commit Log:
&lt;/h3&gt;

&lt;p&gt;Commit log holds the statuses of transactions. This log is allocated to the shared memory and is used throughout the transaction processing.&lt;br&gt;
There are four transactions statuses in the commit log:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;IN_PROGRESS&lt;/code&gt; when transaction is in progress.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;COMMITTED&lt;/code&gt; when transaction completed successfully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ABORTED&lt;/code&gt; when transaction encounters some errors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;SUB_COMMITTED&lt;/code&gt; when transaction goes under some custom implementations.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Transaction Snapshot:
&lt;/h3&gt;

&lt;p&gt;Transaction snapshot refers to the dataset that stores all the information about the transaction like whether it is active, at a certain time for an individual transaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Serial Snapshot Isolation:
&lt;/h3&gt;

&lt;p&gt;This concurrency method is used to make sure the high level of isolation. One transaction never gets the effect of other transactions in database and it can never read the data that is added by another transactions in the database but not committed successfully i.e. serialization.&lt;/p&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.tourl"&gt;https://www.interdb.jp/pg/pgsql05.html&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Foreign Data Wrappers (FDWs) in PostgresSQL</title>
      <dc:creator>Muhammad Adil Shahid</dc:creator>
      <pubDate>Wed, 28 Jun 2023 20:49:59 +0000</pubDate>
      <link>https://dev.to/muhammadadilshahid1054/foreign-data-wrappers-fdws-in-postgressql-4m0c</link>
      <guid>https://dev.to/muhammadadilshahid1054/foreign-data-wrappers-fdws-in-postgressql-4m0c</guid>
      <description>&lt;p&gt;In this blog we will understand foreign data wrappers. &lt;br&gt;
Foreign Data Wrappers(FDWs) is the library in PostgresSQL that allows to access the data like tables from External sources. To manage the foreign tables that are on a remote server, FDWs use SQL Management of External Data (SQL/MED). &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The analyzer/analyser creates the query tree of the input SQL using definitions of the foreign tables which are stored in catalog.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To get connected to the remote server, the planner uses specific libraries. For example, while connecting to the remote PostgresSQL server, the library that will be used by postgres_fdw is &lt;em&gt;libpq&lt;/em&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;use_remote_estimate&lt;/code&gt; is used to control the &lt;em&gt;EXPLAIN&lt;/em&gt; command use. If the use_remote_estimate` option is &lt;em&gt;ON&lt;/em&gt;, then the planner wil execute the &lt;em&gt;EXPLAIN&lt;/em&gt; command to estimate the cost of each path.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The planner uses the plan tree's scan paths of the foreign tables to create the plain SQL statements and this process is known as deparsing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the process of deparsing, the executor takes those plain SQL statements and send them to the remote server. The method of sending those SQL statements depends on the developer of each extension. For instance, the foreign data wrappers in mysql i.e. mysql_fdw sends the SQL statement without using a transaction. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then FDW receive the results from the remote server and converts it into the PostgresSQL readable data.&lt;/p&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.tourl"&gt;https://www.interdb.jp/pg/pgsql04.html&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learning the Science behind Query Processing, its Cost Estimation and Join Operations in PostgresSQL</title>
      <dc:creator>Muhammad Adil Shahid</dc:creator>
      <pubDate>Tue, 27 Jun 2023 20:20:24 +0000</pubDate>
      <link>https://dev.to/muhammadadilshahid1054/learning-the-science-behind-query-processing-its-cost-estimation-and-join-operations-in-postgressql-3mlp</link>
      <guid>https://dev.to/muhammadadilshahid1054/learning-the-science-behind-query-processing-its-cost-estimation-and-join-operations-in-postgressql-3mlp</guid>
      <description>&lt;p&gt;Here we will discuss query processing, cost estimation of query and joins. So lets get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  I. Query Processing
&lt;/h2&gt;

&lt;p&gt;Query processing comprises of 5 parts explained below:&lt;br&gt;
&lt;strong&gt;1. Parser:&lt;/strong&gt;&lt;br&gt;
This is the first part of query processing. It is responsible for generating the parse tree from SQL statement. It checks the syntax of the SQL statement while building parse tree.&lt;br&gt;
&lt;strong&gt;2. Analyzer/Analyser:&lt;/strong&gt;&lt;br&gt;
Analyzer/Analyser takes the parse tree from the parser and do semantic analysis on it. After this analysis, it generates another tree known as query tree. The root of this query tree contains the metadata about the query such as the type of the query(SELECT, INSERT etc).&lt;br&gt;
&lt;strong&gt;3. Rewriter:&lt;/strong&gt;&lt;br&gt;
Next comes the Rewriter, it transforms the query tree according to the rule systems given in pg_rules system catalog. It basically works on the optimization of the query tree.&lt;br&gt;
&lt;strong&gt;4. Planner:&lt;/strong&gt;&lt;br&gt;
The planner receives the query tree from the rewriter and generates the plan tree. This tree describes the plan about the execution of the query.&lt;br&gt;
&lt;strong&gt;5. Executor:&lt;/strong&gt;&lt;br&gt;
The executor takes the plan tree designed by the planner and executes it. The plan tree is composed of nodes. Each node contains some information that executor requires during processing.&lt;/p&gt;

&lt;h2&gt;
  
  
  II. Cost Estimation in Single-Table Query
&lt;/h2&gt;

&lt;p&gt;PostgreSQL's query optimization is based on cost. Costs are estimated by the functions defined in &lt;em&gt;costsize.c&lt;/em&gt;. In PostgresSQL, there are three types of costs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The startup cost is the cost expended before the first tuple is fetched.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The run cost is the cost to fetch all tuples.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The total cost is the sum of the costs of both startup and run costs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Creating the Plan Tree of a Single-Table Query
&lt;/h3&gt;

&lt;p&gt;The planner creates a plan for the execution of the query and it involves three parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Preprocessing:&lt;/strong&gt; In preprocessing, the planner do some simplification of target lists, normalization of boolean expression and flattening of AND/OR expressions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Getting the cheapest Access path:&lt;/strong&gt; In this segment, the planner estimates the costs of all possible access paths and selects the most cheapest one. For this purpose, it creates a &lt;code&gt;RelOpInfo&lt;/code&gt; structure to store the access paths and corresponding costs. From this structure, it selects the cheapest path.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Plan Tree:&lt;/strong&gt; In the last part, the planner generates the plan tree from the access path. The root of this tree is a &lt;code&gt;PlannedStmt&lt;/code&gt; structure. It contains 19 fields and here are 4 representative fields: &lt;em&gt;commandType&lt;/em&gt; that stores the type of operation, &lt;em&gt;rtable&lt;/em&gt; that stores rangeTable enteries, &lt;em&gt;relationOids&lt;/em&gt; that stores oids of the related tables for this query, &lt;em&gt;plantree&lt;/em&gt; stores a plan tree that is composed of all plan nodes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Working of Executor:&lt;/strong&gt;&lt;br&gt;
The executor process the queries by taking the plan nodes from the end. &lt;code&gt;EXPLAIN&lt;/code&gt; command is used to understand the working of executor as it shows the plan tree almost as it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  III. Join Operations
&lt;/h2&gt;

&lt;p&gt;PostgresSQL supports three join operations that are discussed below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Nested loop join&lt;/strong&gt; is the most fundamental join and it works by iterating through each row of a table and matching it with corresponding rows of another table. It is effective in case when one table is small than the other.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Merge Join&lt;/strong&gt; traverse through both tables with sorted list of join keys and match the rows with same join keys.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hash join&lt;/strong&gt; as described by name uses hash function to join. In this method, hash table is created from one table and used to find the matching rows from the other table.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.tourl"&gt;https://www.interdb.jp/pg/pgsql03.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.tourl"&gt;https://www.interdb.jp/pg/pgsql0302.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.tourl"&gt;https://www.interdb.jp/pg/pgsql0303.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>postgressql</category>
      <category>database</category>
    </item>
    <item>
      <title>Understanding the process and memory architecture in PostgreSQL</title>
      <dc:creator>Muhammad Adil Shahid</dc:creator>
      <pubDate>Mon, 26 Jun 2023 19:14:25 +0000</pubDate>
      <link>https://dev.to/muhammadadilshahid1054/understanding-the-process-and-memory-architecture-in-postgresql-5515</link>
      <guid>https://dev.to/muhammadadilshahid1054/understanding-the-process-and-memory-architecture-in-postgresql-5515</guid>
      <description>&lt;p&gt;PostgreSQL is a client/server type relational database management system. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It has multi-process architecture .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Runs on single host.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we will discuss the types of processes in it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Processes in PostgresSQL server
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Postgres Server Process&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The parent process of all the process is Postgres server process, also known as &lt;em&gt;postmaster&lt;/em&gt; in previous versions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;All other types of processes are initiated by this process. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The default port number on which Postgres server listens is &lt;code&gt;5432&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;More than one PostgreSQL servers can run on the same host but their port number should be different.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Backend Process&lt;/strong&gt;&lt;br&gt;
Backend Process (also known as postgres) is started by postgres server process. Its responsibility is to handle all the queries of the connected client. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;As it is allowed to operate only one database, you have to specify the database while connecting to the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is connects to clients by a single TCP connection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PostgresSQL allows multiple clients connection simultaneously but you have specify the maximum number of clients that can connected at a time and this configuration is done through &lt;code&gt;max_connections&lt;/code&gt; parameter. The default value of this parameter is 100.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Background Process&lt;/strong&gt;&lt;br&gt;
Each feature/function has its own background process. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;CHECKPOINT&lt;/code&gt; is used to write dirty buffers from memory to disks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;VACUUM&lt;/code&gt; is used to remove the dead tuples to free up the space.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Replication Associated Process&lt;/strong&gt;&lt;br&gt;
The processes that are used to manage the replication of database are known are replication associated processes. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
They are used to perform the &lt;em&gt;streaming replication&lt;/em&gt; in which a change in primary database is also done in other replicas of it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Background Worker Process&lt;/strong&gt;&lt;br&gt;
These custom background processes that are implemented by user are known are background worker process.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
In addition to the conventional database operations, these processes can also do other tasks. In short, user can add customized tasks in addition to regular operations&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Memory architecture in PostgresSQL server
&lt;/h2&gt;

&lt;p&gt;Next comes the memory architecture of PostgreSQL that has two types&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Local Memory Area&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This area is allocated by backend processes for their own use.&lt;/li&gt;
&lt;li&gt;It is further divided into sub-areas whose sizes are either fixed or variable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Shared Memory Area&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This area is allocated by PostgreSQL server when it starts up.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is divided into fixed sub-areas.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.tourl"&gt;https://www.interdb.jp/pg/pgsql02.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>apache</category>
      <category>database</category>
    </item>
    <item>
      <title>Exploring the Structure and Layout of a Database Cluster</title>
      <dc:creator>Muhammad Adil Shahid</dc:creator>
      <pubDate>Sun, 25 Jun 2023 18:23:03 +0000</pubDate>
      <link>https://dev.to/muhammadadilshahid1054/exploring-the-structure-and-layout-of-a-database-cluster-logical-components-physical-organization-and-tablespaces-15ki</link>
      <guid>https://dev.to/muhammadadilshahid1054/exploring-the-structure-and-layout-of-a-database-cluster-logical-components-physical-organization-and-tablespaces-15ki</guid>
      <description>&lt;p&gt;Before diving into the structure of database cluster, we first need to understand what database cluster is.&lt;/p&gt;

&lt;p&gt;Database cluster is the collection of databases. This collection is managed by a server named PostgreSQL server. This server runs on a single host. Now let's discuss the its structure. &lt;/p&gt;

&lt;h4&gt;
  
  
  Logical Structure of Database Clusters
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
Just like database cluster is the collection of databases, database is the collection of database objects. These objects are used to store and reference the data. Some examples of database objects are tables, index, views, sequence and function.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These database objects are managed in PostgreSQL by Object identifiers OIDs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In PostgreSQL, databases are also database objects, logically separated from eachother.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Physical Structure of Database Cluster
&lt;/h4&gt;

&lt;p&gt;Database cluster is the base directory while database is its subdirectory. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
The subdirectory of the database contains at least one file of tables and indexes and particular data or configuration files. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Layout of database cluster, databases and tables
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The base directories (database cluster) contains some files and subdirectories. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The databases are under the base directory and their names are same as that of Object identifiers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tables and indexes are managed by individual OIDs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data files are managed by relfilenode variable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Tablespaces
&lt;/h4&gt;

&lt;p&gt;The additional data area outside the base directory is known as tablespaces. &lt;br&gt;
When you issue a command &lt;code&gt;CREATE TABLESPACE&lt;/code&gt;, a tablespace is created under the provided directory.  &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
