{"id":438,"date":"2023-09-24T21:00:09","date_gmt":"2023-09-24T18:00:09","guid":{"rendered":"http:\/\/pgdataeraold.local\/?p=438"},"modified":"2023-09-24T21:00:09","modified_gmt":"2023-09-24T18:00:09","slug":"process-architecture","status":"publish","type":"post","link":"https:\/\/pgdataera.com\/en\/process-architecture\/","title":{"rendered":"Process Architecture"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"858\" height=\"452\" src=\"http:\/\/pgdataeraold.local\/wp-content\/uploads\/2023\/11\/14.-proses-mimarisi.png\" alt=\"\" class=\"wp-image-1410\" srcset=\"https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/14.-proses-mimarisi.png 858w, https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/14.-proses-mimarisi-300x158.png 300w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/figure><\/div>\n\n\n<p>We can divide the processes into 4 main groups.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Postgres Process (Formerly Postmaster)<\/li>\n\n\n\n<li>Background Process<\/li>\n\n\n\n<li>Backend (server) Process<\/li>\n\n\n\n<li>User\/Client Process<\/li>\n<\/ol>\n\n\n\n<p><mark style=\"background-color:var(--ast-global-color-6)\" class=\"has-inline-color\">Note: The Stats collector process is included in the core system with version 15, it is not<br>a separate process.<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Postgres Process<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"postgresql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ps -ef | grep postgres\n\npostgres 2450 1 \/usr\/lib\/postgresql\/14\/bin\/postgres -D\n\/var\/lib\/postgresql\/14\/main -c config_file=\/etc\/postgresql\/14\/main\/postgresql.conf\npostgres 2451 2450 14\/main: logger\npostgres 2453 2450 14\/main: checkpointer\npostgres 2454 2450 14\/main: background writer\npostgres 2455 2450 14\/main: walwriter\npostgres 2456 2450 14\/main: stats collector\npostgres 2457 2450 14\/main: pg_cron launcher\npostgres 2458 2450 14\/main: logical replication launcher\n\nll \/usr\/lib\/postgresql\/14\/bin\/postmaster\n\/usr\/lib\/postgresql\/14\/bin\/postmaster --&gt; postgres<\/pre>\n\n\n\n<p>Postgres process in Debian-based Linux (path is different in RHEL-based Linux.)<\/p>\n\n\n\n<p>It is the parent process that first opens in the instance and starts other processes. As<br>can be seen in the example, the parent process ID is 2450. Other Postgres processes<br>have the parent ID as 2450.<\/p>\n\n\n\n<p><strong>Postgres process;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It takes the memory from the operating system.<\/li>\n\n\n\n<li>Starts background processes.<\/li>\n\n\n\n<li>If necessary, it performs the recovery process.<\/li>\n\n\n\n<li>It listens to the network and accepts the connection requests to the Postgresql<br>database (it acts as a listener).<\/li>\n\n\n\n<li>By default, it listens to TCP 5432 port, it can be changed (need to stop and<br>start the instance).<\/li>\n\n\n\n<li>Writes operation or error messages during boot to the log file (\/var\/log\/postgresql\/postgresql-\u2026..log).<\/li>\n\n\n\n<li>A postgres process can manage one cluster (the concept of cluster is explained<br>in the Storage section)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Background (Utility) Processes<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"postgresql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pgrep -a postgres\n2450 \/usr\/lib\/postgresql\/14\/bin\/postgres -D \/var\/lib\/\npostgresql\/14\/main -c config_file=\/etc\/postgresql\/14\/main\/\npostgresql.conf\n2451 postgres: 14\/main: logger\n2453 postgres: 14\/main: checkpointer\n2454 postgres: 14\/main: background writer\n2455 postgres: 14\/main: walwriter\n2456 postgres: 14\/main: stats collector\n2457 postgres: 14\/main: pg_cron launcher\n2458 postgres: 14\/main: logical replication launcher\n\npstree -p 2450\npostgres(2450)\u2500\u252c\u2500postgres(2451)\n\u251c\u2500postgres(2453)\n\u251c\u2500postgres(2454)\n\u251c\u2500postgres(2455)\n\u251c\u2500postgres(2456)\n\u251c\u2500postgres(2457)\n\u2514\u2500postgres(2458)<\/pre>\n\n\n\n<p>When we examine the ID of the parent (main) postgres process with pstree,<br>background and backend\/server processes are seen.<br>These are the processes required for the instance to work.<br>They are initialized when the instance is started.<br>Some of them starts working with the activated feature.<br>BG Writer, Logger, Checkpointer, WAL writer, Autovacuum launcher, Archiver, Stats<br>collector, WAL sender\/receiver etc<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\"><strong>Backgorund Writer Proses<\/strong><\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"850\" height=\"225\" src=\"http:\/\/pgdataeraold.local\/wp-content\/uploads\/2023\/11\/15.-backgroung-writer-proses.png\" alt=\"\" class=\"wp-image-1412\" srcset=\"https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/15.-backgroung-writer-proses.png 850w, https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/15.-backgroung-writer-proses-300x79.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-green-cyan-color has-alpha-channel-opacity has-vivid-green-cyan-background-color has-background is-style-wide\" \/>\n\n\n\n<p>When the space in the shared buffer is insufficient, it writes the rarely used dirty buffer<br>areas to the disk and makes these areas available again.<br>Writes asynchronously.<br>When it is not writing (idle), it waits in sleep mode, it does not close itself.<br>How long it can stay in sleep mode can be set with the <code>bgwriter_delay<\/code> parameter.<br>It runs every 200ms, which is the default value.<\/p>\n\n\n\n<p><code><strong>bgwriter_lru_maxpages<\/strong><\/code>: It determines how many blocks (pages) will be<br>written in each run.<br><code><strong>bgwriter_lru_multiplier:<\/strong><\/code> It is used to reach the required clean buffer<br>amount.<br>(When the multiplier value is 2, and if 50 blocks of clean buffer space is required, 100<br>blocks of dirty shared buffer space are written to disk and marked as clean buffer.)<\/p>\n\n\n\n<p>Dirty Buffer: New or processed data blocks in memory.<br>Clean Buffer: Available memory space.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Checkpoint Proses<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"571\" height=\"173\" src=\"http:\/\/pgdataeraold.local\/wp-content\/uploads\/2023\/11\/image-21.png\" alt=\"\" class=\"wp-image-1413\" srcset=\"https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/image-21.png 571w, https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/image-21-300x91.png 300w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-green-cyan-color has-alpha-channel-opacity has-vivid-green-cyan-background-color has-background is-style-wide\" style=\"margin-top:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20)\" \/>\n\n\n\n<p>Checkpoint locates address where the recovery process will start (transaction<br>sequence).<br>At checkpoint time, all data blocks in <code><strong>dirty buffer<\/strong><\/code> are written to disk and special records<br>of the checkpoint are written to the log (replorigin) file. (The metadata information of<br>the changes made in the database beforehand is written to the WAL\/REDO files.)<\/p>\n\n\n\n<p>At the same time, transaction information recorded on the disk is entered into the WAL<br>file. And the blocks in the shared buffer are marked as clean so they can be reused.<\/p>\n\n\n\n<p><mark style=\"background-color:var(--ast-global-color-6)\" class=\"has-inline-color\">For example, during electrical\/hardware failure etc. The physical shutdown of the<br>server causes the database to become inconsistent. In such cases, recovery starts<br>while the database is opened.<\/mark> <\/p>\n\n\n\n<p>The recovery process receives the latest checkpoint<br>information and re-runs the transactions that could not be written to the disk from the<br>WAL files, making the data files consistent and starts the instance.<\/p>\n\n\n\n<p>When the checkpoint occurs, it will write all the data blocks in the <code><strong>dirty buffer<\/strong><\/code> to disk,<br>which will cause I\/O load. I\/O starts from the checkpoint start point and completes<br>before the next checkpoint, therefore, the checkpoint process is limited.<\/p>\n\n\n\n<p>The frequency of checkpoint operation is determined by the <code><strong>checkpoint_timeout<\/strong><\/code><br>parameter. The default value is 5 minutes. So, the checkpointer starts the checkpoint<br>process every 5 minutes or at <code><strong>max_wal_size<\/strong><\/code>, whichever is reached first.<br>If WAL has not been written since the previous checkpoint, that is, there is no<br>transaction, the checkpoint is not performed even if the <code><strong>checkpoint_timeout<\/strong><\/code> period<br>has passed.<\/p>\n\n\n\n<p>If the <code><strong>checkpoint_timeout<\/strong><\/code> and\/or <code><strong>max_wal_size<\/strong><\/code> values are reduced,<br>frequent checkpoints will occur, but the recovery time will be shortened. Since<br>frequent checkpoints will be costly, it should be kept in balance. The database needs to<br>be adjusted according to its intended use and load.<br>To identify if checkpoint is happening too frequently, the <code><strong>checkpoint_warning<\/strong><\/code><br>parameter can be set, which will record the warning messages in the log file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">WAL Writer Proses<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"183\" src=\"http:\/\/pgdataeraold.local\/wp-content\/uploads\/2023\/11\/17.-wal-writer-proses.png\" alt=\"\" class=\"wp-image-1414\" srcset=\"https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/17.-wal-writer-proses.png 692w, https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/17.-wal-writer-proses-300x79.png 300w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-green-cyan-color has-alpha-channel-opacity has-vivid-green-cyan-background-color has-background is-style-wide\" style=\"margin-top:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20)\" \/>\n\n\n\n<p>The Checkpointer process frequently performs the checkpoint operation. Changes in<br>data are written to disk asynchronously.<br>Modified data blocks are kept in the shared buffer.<br>The metadata records of the change are kept in the WAL buffer.<br>When the commit happens, the REDO records in the WAL buffer are written to the WAL<br>segments.<\/p>\n\n\n\n<p><strong>wal_level:<\/strong> Defines which records WAL files contain.<br>The default value is replica. This value is sufficient for WAL archiving, and hot standby<br>(read only).<br>In minimal, it deletes all logs except the information required in crash and immediate<br>shutdown situations. Not suitable for base backup. The database does not contain<br>the necessary information for base backup restore and recovery operations. For base<br>backup, it should be a replica or logical.<br>In addition to replica in logical, it also contains decoding information required for<br>logical standby.<\/p>\n\n\n\n<p><strong>wal_writer_delay:<\/strong> Determines how often the wal buffer is flushed and its<br>contents are written to disk.<\/p>\n\n\n\n<p><strong>wal_keep_size:<\/strong> Determines the minimum WAL size that should be kept in the<br><code>pg_wal<\/code> directory. If your standby servers lag behind for any reason, it updates itself<br>with the WAL files in pg_wal.<\/p>\n\n\n\n<p><strong>min_wal_size:<\/strong> As long as the disk usage of WAL files is smaller than this size, it<br>will be overwritten and reused in checkpoint operations instead of deleting old WAL<br>files. Thus, the disk space specified here is reserved. The default value is 80 MB.<\/p>\n\n\n\n<p><strong>max_wal_size:<\/strong> The size that is allowed to grow during the automatic checkpoint<br>process. It is the soft limit, under heavy load, when <code>archive_command<\/code> receives an error<br>and cannot archive, or when <code>wal_keep_size<\/code> is given a high value, it can exceed the<br>size specified here.<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">WAL Archiver Proses<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"697\" height=\"170\" src=\"http:\/\/pgdataeraold.local\/wp-content\/uploads\/2023\/11\/18.-wal-arsiv-.png\" alt=\"\" class=\"wp-image-1415\" srcset=\"https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/18.-wal-arsiv-.png 697w, https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/18.-wal-arsiv--300x73.png 300w\" sizes=\"auto, (max-width: 697px) 100vw, 697px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-green-cyan-color has-alpha-channel-opacity has-vivid-green-cyan-background-color has-background is-style-wide\" \/>\n\n\n\n<p>The WAL archiver process archives WAL files to keep backup and standby servers up<br>to date. It is disabled by default. It is an optional parameter. It is activated with the<br><code><strong>archive_mode<\/strong><\/code> parameter. It has two modes; \u2018<code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">on<\/code>\u2019 and \u2018<code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">always<\/code>\u2019.<br>There is no difference in normal operation. But if \u2018<code>always<\/code>\u2019 is selected, it will continue to<br>archive even in recovery and standby mode.<br><code>wal_level<\/code> determines how much details are written to WA files.<br>Its minimal value is not sufficient for archiving, so it cannot be enabled.<\/p>\n\n\n\n<p><mark style=\"background-color:#b2edff\" class=\"has-inline-color\"><code>archive_command = 'rsync -av %p \/RA\/archive\/<\/code><\/mark><kbd><mark style=\"background-color:#b2edff\" class=\"has-inline-color\">'<\/mark><\/kbd><br>Pgbackrest and other backup tools take different values according to the environments used.                                                             Example: <code><mark style=\"background-color:#b2edff\" class=\"has-inline-color\">archive_command = 'pgbackrest --stanza=mx_stanza archive-push %p'<\/mark><\/code><\/p>\n\n\n\n<p><mark style=\"background-color:var(--ast-global-color-6)\" class=\"has-inline-color\">Note:<\/mark><\/p>\n\n\n\n<p><mark style=\"background-color:var(--ast-global-color-6)\" class=\"has-inline-color\">1. Because online backup and standby servers are essential for critical databases,<br>enabling WAL archiving is almost mandatory.<\/mark><\/p>\n\n\n\n<p><mark style=\"background-color:var(--ast-global-color-6)\" class=\"has-inline-color\">2.The database activities like a dump, restore, batch, etc. can be considered for these<br>settings. Stopping archiving before heavy WAL-generating operations will be beneficial<br>for performance.<br>(<code>archive_mode off, wal_level = minimal and max_wal_senders =0<\/code>). It needs instance restart after the setting.<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">Logger Proses<\/h2>\n\n\n\n<p>It is the process that writes the events in the database to the current log file.<br>Logging collector is turned off by default and only stderr messages are directed to the<br>system\u2019s default log directory when it is turned off.<br>(<code data-enlighter-language=\"postgresql\" class=\"EnlighterJSRAW\">\/var\/log\/postgresql\/postgresql-14-main.log<\/code>)<br>When enabled with <code><strong>logging_collector = on<\/strong><\/code> (restart required), the logger<br>process opens and starts writing log files to the directory specified in the <code>log_directory<\/code><br>parameter.<\/p>\n\n\n\n<p>For example: <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">\/var\/lib\/postgresql\/14\/main\/log\/postgresql-09-23.log<\/code><br>The full path can also be given (the postgres user must have write access to the folder).<br>If path is not given, it is recorded by default to the location <kbd><strong>\/var\/log\/postgresql.<\/strong><\/kbd><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">Autovacuum Launcher Proses<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"701\" height=\"280\" src=\"http:\/\/pgdataeraold.local\/wp-content\/uploads\/2023\/11\/19.-autovacuum-launcher.png\" alt=\"\" class=\"wp-image-1416\" srcset=\"https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/19.-autovacuum-launcher.png 701w, https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/19.-autovacuum-launcher-300x120.png 300w\" sizes=\"auto, (max-width: 701px) 100vw, 701px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-green-cyan-color has-alpha-channel-opacity has-vivid-green-cyan-background-color has-background is-style-wide\" \/>\n\n\n\n<p>It is an optional process. It is enabled by default (<code><strong>autovacuum=on<\/strong><\/code>).<br>Autovacuum worker processes make idle(dead) areas in datafiles usable again.<br>Autovacuum launcher runs these worker processes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">Vacuum<\/h2>\n\n\n\n<p>When a row in a table is deleted, Postgresql does not immediately delete these lines<br>from the data file.<br>These lines are marked as deleted.<br>Likewise, updating a row roughly corresponds to a delete and an insert operation.<br>The state of the row before the update is still in the data file. As a result, idle(dead)<br>areas that cannot be used in data files are created. These idle fields are called dead<br>records.<br>The vacuum process marks dead records as reusable.<br>The vacuum process does not lock the table.<br>The vacuum command can be run manually<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">Vacuum Full<\/h2>\n\n\n\n<p>It deletes the records marked as reusable by the Vacuum process, reorganizes the<br>table, and restores the idle areas to the system.<br>Vacuum full creates an empty data file.<br>It copies the <code>non-dead record <\/code>to the new datafile and empties the original file.<br>Note, vacuum full operation locks the table in exclusive mode. It should be preferred<br>when the transaction is less. If necessary, it should be stopped.<br>There must be enough space on the disk as it will create a copy of the table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">Vacuum analyze<\/h2>\n\n\n\n<p>It reads the number of records in the tables and generates statistics for the query<br>planner.<br>The Autovacuum launcher process also automates these vacuum commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">Stats Collector Proses<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"823\" height=\"418\" src=\"http:\/\/pgdataeraold.local\/wp-content\/uploads\/2023\/09\/image-10.png\" alt=\"\" class=\"wp-image-446\" srcset=\"https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/09\/image-10.png 823w, https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/09\/image-10-300x152.png 300w\" sizes=\"auto, (max-width: 823px) 100vw, 823px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-green-cyan-color has-alpha-channel-opacity has-vivid-green-cyan-background-color has-background is-style-wide\" \/>\n\n\n\n<p>It is an optional process, and enabled by default.<br>It is a subsystem that collects and reports activity information in the database.<br>It can aggregate the number of accesses to tables and indexes at the disk block and row<br>level.<br>It can check the number of rows in each table, do analysis and vacuum operations.<br>It can track the number of times user-defined functions are called\/executed and how<br>long they take.<\/p>\n\n\n\n<p>Postgresql can report all the instantaneous activities in the database.<br><mark style=\"background-color:var(--ast-global-color-6)\" class=\"has-inline-color\"><strong>For example<\/strong>, commands, connections, and sessions run by server processes. This<br>property is independent of the collector process.<\/mark><\/p>\n\n\n\n<p>These statistics are kept in the directory listed in the <code>stats_temp_directory<\/code><br>parameter. In databases operating under heavy load, keeping this directory on fast<br>disks such as RAM-based disk\/SSD will increase performance. When the Instance is<br>stopped, a permanent copy of the statistics is copied to the <code data-enlighter-language=\"postgresql\" class=\"EnlighterJSRAW\">$PGDATA\/pg_stat_tmp<\/code> directory. Thus, stats are not lost when it is stopped and started.<\/p>\n\n\n\n<p>If the instance is stopped inconsistently (immediate shutdown, server crash), statistics<br>will be lost as it will be started with recovery. Likewise, it is lost in the point-in-time<br>recovery process. (With version 15, the core is integrated into the system, it no longer<br>works as a separate process.)<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-3-color has-text-color has-background\" style=\"border-width:2px;border-radius:10px;background:linear-gradient(147deg,rgb(238,238,238) 74%,rgb(169,184,195) 96%);margin-top:0;margin-bottom:0;font-style:normal;font-weight:800;letter-spacing:2px;line-height:2\"><code>#Activate\/deactivate statistics;\n<strong>alter system set track_counts='on<\/strong>'<strong>;<\/strong>\n\n#Statistics of commands run by session \/ server processes\n<strong>alter system set track_activities='on\/off';<\/strong>\n\n#User defined functions\n<strong>alter system set track_functions = 'none, pl, all';<\/strong>\n\n# I\/O monitoring\n<strong>alter system set track_io_timing= 'on\/off';<\/strong>\n\n#Default de\u011ferlere geri d\u00f6nmek i\u00e7in;\n<strong>alter system reset track_activities;\nalter system reset track_counts;\nalter system reset track_functions;\nalter system reset track_io_timing;<\/strong><\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-green-cyan-color has-alpha-channel-opacity has-vivid-green-cyan-background-color has-background is-style-wide\" \/>\n\n\n\n<p>Gathering statistics will add overhead to the database. When the detailed analysis is<br>required, statistics can be enabled and then disabled.<br><strong>track_counts: <\/strong>Determines whether to collect activity statistics in the database,<br>and statistics about indexes and tables. It is enabled by default because autovacuum<br>needs this information.<br><strong>track_activities:<\/strong> It controls the monitoring of the commands currently<br>executed by the server process. It is enabled by default. Superuser can make changes.<br>The superuser and session owner can query the reports here. It does not create a<br>security vulnerability.<br><strong>track_functions: <\/strong>Enables tracking of user-defined functions.<br><strong>track_io_timing:<\/strong> Enables monitoring of block read and write operations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">Statistics System Views<\/h2>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-3-color has-text-color has-background\" style=\"border-width:2px;border-radius:10px;background:linear-gradient(147deg,rgb(238,238,238) 73%,rgb(169,184,195) 100%);font-size:12px;font-style:normal;font-weight:900;letter-spacing:2px;line-height:2.5\"><code><strong>postgres=# \\d pg_stat<\/strong>\npg_stat_activity              pg_statistic\npg_stat_all_indexes           pg_statistic_ext\npg_stat_all_tables            pg_statistic_ext_data\npg_stat_archiver              pg_statistic_ext_data_stxoid_index\npg_stat_bgwriter              pg_statistic_ext_name_index\npg_stat_database              pg_statistic_ext_oid_index\npg_stat_database_conflicts    pg_statistic_ext_relid_index\npg_stat_gssapi                pg_statistic_relid_att_inh_index\npg_statio_all_indexes         pg_stat_progress_analyze\n....<\/code><\/pre>\n\n\n\n<p>Statistics collected from dynamic statistics views can be queried.<br>If we connect with <code data-enlighter-language=\"postgresql\" class=\"EnlighterJSRAW\">psql<\/code> and type <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\"> \\pg_stat<\/code>  and press tab twice, the above list<br>will be displayed.<br><mark style=\"background-color:var(--ast-global-color-6)\" class=\"has-inline-color\"><strong>Note:<\/strong> By examining this statistical information, performance improvement can be<br>made by moving tables or tablespaces with a lot of I\/O operations to the fast disks.<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">WAL Sender\/Receiver<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"848\" height=\"376\" src=\"http:\/\/pgdataeraold.local\/wp-content\/uploads\/2023\/11\/21.-wal-sender-receiver.png\" alt=\"\" class=\"wp-image-1417\" srcset=\"https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/21.-wal-sender-receiver.png 848w, https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/21.-wal-sender-receiver-300x133.png 300w\" sizes=\"auto, (max-width: 848px) 100vw, 848px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-green-cyan-color has-alpha-channel-opacity has-vivid-green-cyan-background-color has-background is-style-wide\" \/>\n\n\n\n<p>These processes perform replication in active\/passive cluster architectures. The WAL<br>receiver process runs on the slave(standby) server(node) and connects to the master<br>(primary) server(node) via TCP\/IP.<\/p>\n\n\n\n<p>The master node has the WAL sender process. WAL sender is responsible for sending<br>WAL files to slave node. The WAL receiver is also responsible for receiving these WAL<br>files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">Backend (Server) Proses<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"849\" height=\"421\" src=\"http:\/\/pgdataeraold.local\/wp-content\/uploads\/2023\/11\/22.-backend-proses.png\" alt=\"\" class=\"wp-image-1418\" srcset=\"https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/22.-backend-proses.png 849w, https:\/\/pgdataera.com\/wp-content\/uploads\/2023\/11\/22.-backend-proses-300x149.png 300w\" sizes=\"auto, (max-width: 849px) 100vw, 849px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-green-cyan-color has-alpha-channel-opacity has-vivid-green-cyan-background-color has-background is-style-wide\" \/>\n\n\n\n<p>Each session corresponds to a backend\/server process.<br>It is the process that executes users\u2019 requests (<code><strong>select, insert, update<\/strong><\/code> etc.)<br>on the Postgresql side.<br>Each session takes its own backend memory space from the system for its use.<br>Maximum number of backend\/server processes is limited by the <code><strong>max_connections<\/strong><\/code><br>parameter.<br>The default value is 100.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:28px\">Client\/User Proses<\/h2>\n\n\n\n<p>A program or tool that connects to a database server or network.<br><mark style=\"background-color:#90e9b8\" class=\"has-inline-color\">Example: Pgadmin, psql web application, java application etc.<\/mark><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We can divide the processes into 4 main groups. Note: The Stats collector process is included in the core system with version 15, it is nota separate process. Postgres Process Postgres process in Debian-based Linux (path is different in RHEL-based Linux.) It is the parent process that first opens in the instance and starts other <a href=\"https:\/\/pgdataera.com\/en\/process-architecture\/\" class=\"more-link\">&#8230;<span class=\"screen-reader-text\">  Process Architecture<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[277],"tags":[],"class_list":["post-438","post","type-post","status-publish","format-standard","hentry","category-postgresql-database-architecture"],"_links":{"self":[{"href":"https:\/\/pgdataera.com\/en\/wp-json\/wp\/v2\/posts\/438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pgdataera.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pgdataera.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pgdataera.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pgdataera.com\/en\/wp-json\/wp\/v2\/comments?post=438"}],"version-history":[{"count":0,"href":"https:\/\/pgdataera.com\/en\/wp-json\/wp\/v2\/posts\/438\/revisions"}],"wp:attachment":[{"href":"https:\/\/pgdataera.com\/en\/wp-json\/wp\/v2\/media?parent=438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pgdataera.com\/en\/wp-json\/wp\/v2\/categories?post=438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pgdataera.com\/en\/wp-json\/wp\/v2\/tags?post=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}