Statistics
54
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2025-12-08

AuthorY V Ravi Kumar, Arun Kumar Samayam, Phani Kadambari

This book is your one-stop resource on PostgreSQL system architecture, installation, management, maintenance, and migration. It will help you address the critical needs driving successful database management today: reliability and availability, performance and scalability, security and compliance, cost-effectiveness and flexibility, disaster recovery, and real-time analytics—all in one volume. Each topic in the book is thoroughly explained by industry experts and includes step-by-step instructions for configuring the features, a discussion of common issues and their solutions, and an exploration of real-world scenarios and case studies that illustrate how concepts work in practice. You won't find the book's comprehensive coverage of advanced topics, including migration from Oracle to PostgreSQL, heterogeneous replication, and backup & recovery, in one place—online or anywhere else. What You Will Learn Install PostgreSQL using source code and yum installation Back up and recover Migrate from Oracle database to PostgreSQL using ora2pg utility Replicate from PostgreSQL to Oracle database and vice versa using Oracle GoldenGate Monitor using Grafana, PGAdmin, and command line tools Maintain with VACUUM, REINDEX, etc. Who This Book Is For Intermediate and advanced PostgreSQL users, including PostgreSQL administrators, architects, developers, analysts, disaster recovery system engineers, high availability engineers, and migration engineers

Tags
No tags
Publisher: Apress
Publish Year: 2025
Language: 英文
Pages: 733
File Format: PDF
File Size: 39.0 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
Mastering PostgreSQL Administration Internals, Operations, Monitoring, and Oracle Migration Strategies Y V Ravi Kumar Arun Kumar Samayam Phani Kadambari
Mastering PostgreSQL Administration: Internals, Operations, Monitoring, and Oracle Migration Strategies ISBN-13 (pbk): 979-8-8688-1506-5 ISBN-13 (electronic): 979-8-8688-1507-2 https://doi.org/10.1007/979-8-8688-1507-2 Copyright © 2025 by Y V Ravi Kumar, Arun Kumar Samayam, and Phani Kadambari This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Shaul Elson Development Editor: Laura Berendson Coordinating Editor: Gryffin Winkler Cover designed by eStudioCalamar Cover Photo by Mylon Ollila on Unsplash Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a Delaware LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub (https://github.com/Apress). For more detailed information, please visit https://www. apress.com/gp/services/source-code. If disposing of this product, please recycle the paper Y V Ravi Kumar Irving, TX, USA Arun Kumar Samayam Dallas, TX, USA Phani Kadambari Lewisville, TX, USA
iii Table of Contents About the Authors ���������������������������������������������������������������������������������������������������� xi About the Technical Reviewers ����������������������������������������������������������������������������� xiii Acknowledgments ���������������������������������������������������������������������������������������������������xv Chapter 1: PostgreSQL System Architecture ������������������������������������������������������������ 1 Introduction ����������������������������������������������������������������������������������������������������������������������������������� 1 PostgreSQL Components �������������������������������������������������������������������������������������������������������������� 2 PostgreSQL Server Process Tree ������������������������������������������������������������������������������������������������� 14 PostgreSQL Architecture Flow ���������������������������������������������������������������������������������������������������� 16 Summary������������������������������������������������������������������������������������������������������������������������������������� 18 Chapter 2: PostgreSQL Installation and Initialization ��������������������������������������������� 19 Introduction ��������������������������������������������������������������������������������������������������������������������������������� 19 PostgreSQL Available Versions and Supported OS Platforms ����������������������������������������������������� 20 System Requirements for PostgreSQL Installation on Linux ������������������������������������������������������� 20 Environment Details �������������������������������������������������������������������������������������������������������������������� 21 Downloading PostgreSQL Software �������������������������������������������������������������������������������������������� 22 Installing PostgreSQL Using the Binary Packages (RPMs) ���������������������������������������������������������� 22 Exploring a few files under the data directory ���������������������������������������������������������������������� 40 Shutdown Modes in PostgreSQL Database Cluster��������������������������������������������������������������������� 47 Uninstallation of PostgreSQL Server (Installed Using RPMs) ������������������������������������������������������ 50 Installing PostgreSQL Server Using Source Code ����������������������������������������������������������������������� 55 Uninstallation of PostgreSQL Server (Installed Using Source Code) ������������������������������������������� 73 Summary������������������������������������������������������������������������������������������������������������������������������������� 74
iv Chapter 3: PostgreSQL Physical Structures ������������������������������������������������������������ 75 Introduction ��������������������������������������������������������������������������������������������������������������������������������� 75 PostgreSQL Database Cluster ����������������������������������������������������������������������������������������������������� 76 PostgreSQL Directory Structure �������������������������������������������������������������������������������������������������� 77 Databases in PostgreSQL ������������������������������������������������������������������������������������������������������������ 88 Tablespaces in PostgreSQL ��������������������������������������������������������������������������������������������������������� 99 Default Tablespaces ������������������������������������������������������������������������������������������������������������������ 100 Creating a New Tablespace ������������������������������������������������������������������������������������������������������� 102 Changing Default Tablespace ���������������������������������������������������������������������������������������������������� 103 Page Structure and Layout in PostgreSQL Database Cluster ���������������������������������������������������� 110 Query Processing in PostgreSQL ���������������������������������������������������������������������������������������������� 112 Connection Request Stage �������������������������������������������������������������������������������������������������� 112 Query Execution Stage �������������������������������������������������������������������������������������������������������� 113 Parser Stage ������������������������������������������������������������������������������������������������������������������������ 113 Execution Plan Generation Stage ���������������������������������������������������������������������������������������� 113 Execution Stage ������������������������������������������������������������������������������������������������������������������� 114 Inspecting Physical Data with the pg_filedump Utility �������������������������������������������������������������� 114 Other Administrative Operations ����������������������������������������������������������������������������������������������� 121 Altering a Tablespace ���������������������������������������������������������������������������������������������������������� 121 Dropping a Tablespace �������������������������������������������������������������������������������������������������������� 122 Temporary Tablespaces ������������������������������������������������������������������������������������������������������� 124 Index Objects on Separate Tablespace �������������������������������������������������������������������������������� 128 Advantages of Tablespaces ������������������������������������������������������������������������������������������������� 131 Cloning a Database �������������������������������������������������������������������������������������������������������������� 131 Dropping a Database in a Cluster ���������������������������������������������������������������������������������������� 134 Dropping Default Databases ������������������������������������������������������������������������������������������������ 135 Summary����������������������������������������������������������������������������������������������������������������������������������� 136 Table of ConTenTs
v Chapter 4: PostgreSQL Management of Database Server ������������������������������������� 137 Introduction ������������������������������������������������������������������������������������������������������������������������������� 137 Creating Database Using OS Command ������������������������������������������������������������������������������������ 138 Schemas in PostgreSQL ������������������������������������������������������������������������������������������������������������ 140 Creating a Schema �������������������������������������������������������������������������������������������������������������������� 142 Accessing Schema Objects in PostgreSQL ������������������������������������������������������������������������������� 148 Database Local Connectivity by User ���������������������������������������������������������������������������������������� 154 User Attributes �������������������������������������������������������������������������������������������������������������������������� 157 User Renaming �������������������������������������������������������������������������������������������������������������������������� 162 Schema Ownership ������������������������������������������������������������������������������������������������������������������� 162 Database Remote Connectivity by User ������������������������������������������������������������������������������������ 165 The pg_hba�conf File ���������������������������������������������������������������������������������������������������������������� 173 Authentication Method – Trust and Reject �������������������������������������������������������������������������������� 189 Predefined Roles in PostgreSQL ����������������������������������������������������������������������������������������������� 192 Extensions in PostgreSQL ��������������������������������������������������������������������������������������������������������� 197 Dropping Users in PostgreSQL �������������������������������������������������������������������������������������������������� 205 Dropping a Schema in PostgreSQL ������������������������������������������������������������������������������������������� 206 Dropping Database Using OS Command ����������������������������������������������������������������������������������� 209 Summary����������������������������������������������������������������������������������������������������������������������������������� 211 Chapter 5: PostgreSQL Backup and Recovery ������������������������������������������������������ 213 Introduction ������������������������������������������������������������������������������������������������������������������������������� 213 Why Backup a Database? ��������������������������������������������������������������������������������������������������������� 215 Importance of a Backup Strategy ��������������������������������������������������������������������������������������������� 216 Backup Types in PostgreSQL ����������������������������������������������������������������������������������������������������� 217 SQL Dump ��������������������������������������������������������������������������������������������������������������������������������� 218 File System-Level Backup ��������������������������������������������������������������������������������������������������������� 219 Continuous Archiving and Point-in-Time Recovery (PITR) �������������������������������������������������������� 220 Using External Tools ������������������������������������������������������������������������������������������������������������������ 221 Table of ConTenTs
vi Barman ������������������������������������������������������������������������������������������������������������������������������������� 221 Installing Barman ���������������������������������������������������������������������������������������������������������������� 223 Configuring Barman ������������������������������������������������������������������������������������������������������������ 224 pgBackRest ������������������������������������������������������������������������������������������������������������������������������� 233 Installation and Configuration of pgBackRest Tool �������������������������������������������������������������� 233 Real-World Practical Backup and Recovery Scenarios ������������������������������������������������������������� 244 Scenario 1: Backup and Restore a Single Table ������������������������������������������������������������������ 244 Scenario 2: Backup and Restore a Table Structure Without the Data ���������������������������������� 249 Scenario 3: Backup and Restore the Table Data Without the Structure ������������������������������� 253 Scenario 4: Backup and Restore Multiple Tables at a Time ������������������������������������������������� 257 Scenario 5: Backup and Restore a Table in Custom Format ������������������������������������������������ 263 Scenario 5a: Backup and Restore a Table Using pg_dump in tar Format ���������������������������� 265 Scenario 5b: Backup and Restore a Table Using pg_dump in dir Format ���������������������������� 266 Scenario 6: Backup Multiple Tables and Restore One Table in Custom Format ������������������� 268 Scenario 7: Backup and Restore a Schema Within a Database ������������������������������������������� 270 Scenario 8: Backup Multiple Schemas and Restore a Single Schema Within a Database �� 274 Scenario 9: Backup and Restore an Entire Database ���������������������������������������������������������� 279 Scenario 10: Restore a Backup to a New Database ������������������������������������������������������������ 284 Scenario 11: Improve Backup Performance with Parallel Jobs ������������������������������������������� 287 Scenario 12: Restore a Single Table from a Full Database Backup ������������������������������������� 287 Scenario 13: Logical Backup of a Complete Server and Restore Specific Databases ��������� 289 Scenario 14: Backup of Global Database Objects ���������������������������������������������������������������� 292 Scenario 15: Physical Backup of the Complete Server �������������������������������������������������������� 292 Scenario 15a: Verification of Physical Backups (pg_verifybackup) Before Restore ������������ 294 Scenario 16: Restore Procedures ���������������������������������������������������������������������������������������� 298 Scenario 16a: Restore to a New Instance ���������������������������������������������������������������������������� 298 Scenario 16b: Restore to an Existing Instance �������������������������������������������������������������������� 302 Scenario 17: Perform a Point-in-Time Recovery (PITR) ������������������������������������������������������� 305 Scenario 18: Backup and Restore Using Barman ���������������������������������������������������������������� 316 Scenario 19: Backup and Restore Using pgBackRest ��������������������������������������������������������� 333 Summary����������������������������������������������������������������������������������������������������������������������������������� 358 Table of ConTenTs
vii Chapter 6: PostgreSQL Routine Maintenance ������������������������������������������������������� 359 Introduction ������������������������������������������������������������������������������������������������������������������������������� 359 Analyze�������������������������������������������������������������������������������������������������������������������������������������� 360 Vacuum in PostgreSQL �������������������������������������������������������������������������������������������������������������� 365 Key Purposes of vacuum ����������������������������������������������������������������������������������������������������� 365 Types of vacuum ������������������������������������������������������������������������������������������������������������������ 366 VACUUM FULL in PostgreSQL ���������������������������������������������������������������������������������������������� 383 Key Points About VACUUM FULL ������������������������������������������������������������������������������������������ 383 PostgreSQL vacuum Commands – Summary Table ������������������������������������������������������������� 388 Vacuum and Analyze Threshold Settings in postgresql�conf ����������������������������������������������� 388 vacuumdb Commands for Various Scenarios ���������������������������������������������������������������������� 390 Reindexing in PostgreSQL ��������������������������������������������������������������������������������������������������������� 392 TIP: REINDEX TABLE <table_name> ������������������������������������������������������������������������������������ 396 Reindexing in PostgreSQL – Key Options ���������������������������������������������������������������������������� 398 PostgreSQL Catalog Views for Size Monitoring ������������������������������������������������������������������������� 398 Finding the Largest Tables in the Database ������������������������������������������������������������������������������ 399 Finding and Removing Unused Tables and Indexes ������������������������������������������������������������������ 400 Clear Write-Ahead Logging (WAL) Logs to Free Up Space in Database Server ������������������������� 400 Best Practices to Prevent Disk Space Issues in PostgreSQL Cluster ���������������������������������������� 401 Log File Maintenance in PostgreSQL ���������������������������������������������������������������������������������������� 402 Summary����������������������������������������������������������������������������������������������������������������������������������� 403 Chapter 7: PostgreSQL Monitoring Using PgAdmin and Grafana �������������������������� 405 Introduction ������������������������������������������������������������������������������������������������������������������������������� 405 Monitoring System Resources and OS-Level Metrics ��������������������������������������������������������������� 405 Understanding Real-Time System Behavior ����������������������������������������������������������������������������� 413 PostgreSQL System Views: Real-Time Insights, No Extra Setup ����������������������������������������������� 423 Administering Databases Using pgAdmin ��������������������������������������������������������������������������������� 428 Installation and Configuration of pgAdmin �������������������������������������������������������������������������� 428 Installing pgAdmin 4 on Windows ��������������������������������������������������������������������������������������� 431 Connectivity Between pgAdmin and pg_server ������������������������������������������������������������������ 434 Registering PostgreSQL Server in pgAdmin ������������������������������������������������������������������������ 435 Table of ConTenTs
viii Integrating PostgreSQL with Monitoring Solutions (Grafana) ��������������������������������������������������� 458 Installation and Configuration of Grafana ��������������������������������������������������������������������������������� 458 Downloading Grafana on Windows �������������������������������������������������������������������������������������� 458 Installing Grafana on Windows �������������������������������������������������������������������������������������������� 459 Connecting to Grafana ��������������������������������������������������������������������������������������������������������� 464 Adding a PostgreSQL Data Source in Grafana ��������������������������������������������������������������������� 465 Building a Dashboard in Grafana ����������������������������������������������������������������������������������������� 470 Creating a Bar Chart in the Dashboard �������������������������������������������������������������������������������� 471 Adding a New Bar Chart Panel to the Existing Dashboard �������������������������������������������������� 473 Adding a New XY Chart Panel to the Existing Dashboard ���������������������������������������������������� 476 Adding Multiple Series to the XY Chart �������������������������������������������������������������������������������� 478 Mapping Series of Multi-country Visualization �������������������������������������������������������������������� 479 Summary����������������������������������������������������������������������������������������������������������������������������������� 484 Chapter 8: Data Migration from Oracle to PostgreSQL Using Ora2Pg ������������������� 485 Introduction ������������������������������������������������������������������������������������������������������������������������������� 485 Why Migrate to PostgreSQL ������������������������������������������������������������������������������������������������������ 485 Migration Tools �������������������������������������������������������������������������������������������������������������������������� 486 Migration Best Practices ����������������������������������������������������������������������������������������������������������� 487 Oracle to PostgreSQL Migration Using Ora2Pg ������������������������������������������������������������������������� 488 Migration Approach ������������������������������������������������������������������������������������������������������������������� 489 Migration Prerequisites ������������������������������������������������������������������������������������������������������������� 490 Pre-migration Phase: Prepare Environment for Migration �������������������������������������������������������� 491 Install Perl Modules Required for DBD::Oracle and Ora2Pg ������������������������������������������������������ 494 Install Ora2Pg ���������������������������������������������������������������������������������������������������������������������������� 504 Migration Phase: Migrate Oracle Schemas to PostgreSQL Database ��������������������������������������� 509 Migrating HR Schema Using Direct Load Method ��������������������������������������������������������������������� 513 Migrating CO Schema Using COPY (Bulk Load) Method ������������������������������������������������������������ 531 Migrating SH Schema Using INSERT Method ���������������������������������������������������������������������������� 543 Migration Issues ������������������������������������������������������������������������������������������������������������������������ 553 Summary����������������������������������������������������������������������������������������������������������������������������������� 573 Table of ConTenTs
ix Chapter 9: Data Replication from Oracle to PostgreSQL Using Oracle GoldenGate ������������������������������������������������������������������������������������������������ 575 Introduction ������������������������������������������������������������������������������������������������������������������������������� 575 GoldenGate Replication Configuration Prerequisites ���������������������������������������������������������������� 578 Configure Source Database (Oracle) Ready for Replication ������������������������������������������������ 578 Configure Target Database (PostgreSQL) Ready for Replication ������������������������������������������ 583 Configure Oracle GoldenGate Hub ��������������������������������������������������������������������������������������������� 586 What Is Oracle GoldenGate Hub? ����������������������������������������������������������������������������������������� 586 Install Oracle Client ������������������������������������������������������������������������������������������������������������� 587 Install GoldenGate Software ������������������������������������������������������������������������������������������������ 594 Install Oracle GoldenGate for Oracle Database �������������������������������������������������������������������� 595 Install Oracle GoldenGate for PostgreSQL ��������������������������������������������������������������������������� 601 Create the Deployments ������������������������������������������������������������������������������������������������������������ 607 Create Deployment for Source Oracle Database ����������������������������������������������������������������� 607 Create Deployment for Target PostgreSQL Database ���������������������������������������������������������� 619 Configure GoldenGate on Target Deployment ���������������������������������������������������������������������� 646 Replication Configuration – Create Dist Path in Source Deployment ���������������������������������������� 658 Summary����������������������������������������������������������������������������������������������������������������������������������� 672 Chapter 10: New Features of PostgreSQL 17 �������������������������������������������������������� 673 Introduction ������������������������������������������������������������������������������������������������������������������������������� 673 Downloading PostgreSQL 17 Software Binaries ����������������������������������������������������������������������� 674 Installing PostgreSQL Using Binary Packages (RPMs) �������������������������������������������������������������� 674 New Features: Incremental Backups in PostgreSQL 17 ������������������������������������������������������������ 697 New Features: Logical Replication from Standby Servers in PostgreSQL 17 ���������������������������� 716 New Features: Combining I/Os in PostgreSQL 17 ��������������������������������������������������������������������� 717 New Features: Query Planner Improvements in PostgreSQL 17 ����������������������������������������������� 718 New Features: Introducing Split and Merge Partitions in PostgreSQL 17 ��������������������������������� 719 Summary����������������������������������������������������������������������������������������������������������������������������������� 719 Index ��������������������������������������������������������������������������������������������������������������������� 721 Table of ConTenTs
xi About the Authors Y. V. Ravi Kumar is a recipient of the prestigious EB1-A “Einstein Visa” for Extraordinary Ability in the United States. He brings over 27 years of multinational leadership experience across the United States, Seychelles, and India in the banking, financial services, and insurance (BFSI) sectors. A seasoned technologist, Ravi is an Oracle Certified Master, Oracle ACE Director Alum, Snowflake Data Superhero, and Snowflake Squad Member. He holds a wide range of certifications, including Oracle Certified Professional (OCP) in versions 8i through 19c and Oracle Certified Expert (OCE) in GoldenGate, RAC, Performance Tuning, Oracle Cloud Infrastructure (OCI), Terraform, and Oracle Engineered Systems (Exadata, ZDLRA, and ODA). He is also certified in Oracle Security, Maximum Availability Architecture (MAA), Snowflake Pro, PostgreSQL, MySQL, and MySQL HeatWave and is a multi-cloud architect certified in OCI, AWS, and GCP. In addition, he is TOGAF certified and a Senior Member of the IEEE. Ravi Kumar has co-authored six books, including Oracle Database Upgrade and Migration Methods; Oracle High Availability, Disaster Recovery, and Cloud Services; and Mastering MySQL Administration, and has served as a technical reviewer on six more titles: Oracle 19c AutoUpgrade Best Practices, Oracle Autonomous Database in Enterprise Architecture, End-to-End Observability with Grafana, Maximum Availability Architecture (MAA) with Oracle GoldenGate MicroServices in HUB Architecture, The Cloud Computing Journey: Design and Deploy Resilient and Secure Multi-cloud Systems with Practical Guidance, and Azure FinOps Essentials. Ravi Kumar has published over 100 technical articles across platforms such as Oracle Technology Network, ORAWORLD Magazine, UKOUG, and Redgate. A frequent speaker at international conferences, he has presented at Oracle OpenWorld four times and delivered sessions at numerous user groups including IOUG, NYOUG, AUSOUG, and Quest. His work includes designing data centers and implementing mission-critical databases for central banks, and his contributions have been recognized by Oracle in their OCM list and Spotlight on Success stories.
xii Arun Kumar Samayam is an experienced technology architect and a seasoned database professional with a profound passion for innovation. He is a Principal Cloud Solutions Architect in the Cloud and Engineering platform team at a global airline company. He is part of the Cloud Center of Excellence (CCoE) team, where he drives the organization’s cloud transformation journey through cloud governance practices. Before this role, Arun worked as a Product Technical Leader for the Enterprise Database Services team, where he had the opportunity to develop and hone his technical proficiency through engineering, managing, and supporting multiple database platforms like Oracle, MySQL, PostgreSQL, SQL server, and MongoDB. In addition, Arun is a multi-cloud certified professional, and his industry knowledge and experience have made him a speaker at prestigious events like Oracle OpenWorld, where he shared his insights and expertise on database products. Sri Ram Phani Kiran Kadambari is a seasoned IT professional with over 16 years of experience in database management, cloud solutions, and diverse technology domains. Passionate about databases, he specializes in Oracle (including Engineered Systems), PostgreSQL, MySQL with HeatWave, and Snowflake, along with extensive expertise in cloud platforms such as Oracle Cloud Infrastructure (OCI), AWS, and Azure. Phani’s technical skills have been instrumental in helping organizations successfully migrate their databases and mission-critical applications to the cloud. Phani’s journey began as a database trainer, and his passion for knowledge-sharing has driven him to mentor and train countless professionals, guiding them to build successful careers in database engineering. He holds multiple certifications in Oracle, MySQL, PostgreSQL, Snowflake, and Oracle Cloud Infrastructure. A respected contributor to the database community, Phani shared his insights as a speaker at KSAOUG Connect – 2024, where he presented on MySQL High Availability and Disaster Recovery. He has also served as a technical reviewer for the book Mastering MySQL Administration (Apress, 2024), further showcasing his commitment to advancing the field. Phani’s blend of technical expertise, industry experience, and dedication to mentoring makes him a valuable contributor to the IT and database community. abouT The auThors
xiii About the Technical Reviewers Velu Natarajan is a seasoned expert with over 20 years of experience architecting scalable, high-performance data and database solutions across a wide range of platforms. His passion lies in the relentless pursuit of modernizing data platforms – ensuring they are not only efficient and high-performing but also scalable and durable to meet the evolving needs of the industry. As an industry trailblazer, Velu has been an early advocate for Cloud FinOps frameworks, leveraging them to drive business success and achieve significant cost savings. As a leader in the Database Cloud Center of Excellence (CCoE), Velu plays a crucial role in advancing his organization’s cloud transformation journey. His deep expertise in database practices enables him to lead initiatives that ensure seamless migrations, business continuity, and operational efficiency. Velu’s pioneering work with Cloud FinOps has been instrumental in delivering measurable business outcomes. His application of the FinOps framework to control costs in cloud-based data platforms earned him the Discover President Award in 2024. Through effective collaboration with cross-functional teams, he has optimized performance, managed costs, and established best practices – developing self-service tools and processes, identifying potential issues, and creating comprehensive cost management plans. A respected contributor to the data and financial operations community, Velu has shared his insights at prestigious events such as Snowflake Summit 2024, where he spoke on optimizing performance and cost on Snowflake, maximizing business value, reducing budget risk, and enhancing the user experience. He served as a technical reviewer for Azure FinOps Essentials and is currently co-authoring FinOps for Snowflake – further demonstrating his commitment to advancing financial operations and data platform excellence.
xiv Velu holds certifications as an AWS Certified Database Specialty, FinOps Certified Practitioner, and Snowflake Architect and is widely recognized for his expertise in data products and his dedication to excellence. Outside of work, he enjoys playing soccer and watching epic movies. Raghavendra S (Raghav) is a Database Cloud Architect who specializes in designing and implementing cloud- based database solutions for organizations. With a deep understanding of both database management systems and cloud computing technologies, he helps businesses leverage the power of the cloud to optimize their database operations. His expertise lies in developing architecture strategies that align with business goals, ensuring scalability, high availability, and performance of database systems in the cloud. He has hands-on experience with leading cloud platforms, including Oracle Cloud Infrastructure (OCI), Amazon Web Services (AWS), and Google Cloud Platform (GCP). Raghav works closely with stakeholders to assess their database requirements, plan migration strategies, and design secure and cost-effective cloud-based database solutions. He possesses a strong understanding of database technologies such as Oracle Database, MySQL, and PostgreSQL, enabling him to provide expert guidance on data modeling, schema design, and query optimization. He also has a solid understanding of big data technologies, including Hadoop, HDFS, Hive, HBase, Kafka, and Data Lake/Lakehouse architectures. abouT The TeChniCal reviewers
xv Acknowledgments I am grateful to God who gave me all the strength, courage, perseverance, and patience in this sincere and honest attempt of knowledge sharing. This seventh book of mine as a co-author would not have been possible without the following people: Shri Yenugula Venkata Pathi and Smt. Yenugula Krishna Kumari, my parents who instilled in me good thoughts and values, and Shri B. Suresh Kamath (founder of LaserSoft and Patterns Cognitive), my mentor, my guru, my strength, and my guide, who has inspired me for the last 27 years. B. Suresh Kamath is an immensely talented and technically sound individual. He taught me how to be well read with no compromises. He led by example in being content yet hungry for knowledge. He motivated me to go that extra mile in attempting and experimenting with newer technologies/environments and in being regularly out of my comfort zone. Anitha Ravi Kumar, my wife, was immensely tolerant with me. “Behind every successful man, there is a good woman,” as they say. I believe she is the embodiment of this well-known belief. Special thanks to my daughter, Sai Hansika, and my son, Sai Theeraz, for giving me time to write a seventh book in the last seven years. I would like to thank Velu Natarajan and Raghavendra S (Raghav) for accepting to be technical reviewers for this book. Special thanks to Shaul Elson, Gryffin Winkler, Nirmal Selvaraj, Celestin Suresh John, and Laura Berendson at Apress for giving me the opportunity to write my sixth book for Apress. Thank you to the readers for picking up this book. We have attempted to be as simple and straightforward as possible when sharing this knowledge, and we truly believe that it will help you to steadily deep dive into various interesting concepts and procedures. I would also like to thank the complete Infolob Global team – Vijay Cherukuri, Tim Fox, Josh Turnbull, Nivas Nadimpalli, Satyendra Pasalapudi – and LaserSoft colleagues. —Venkata Ravi Kumar Yenugula I am forever grateful for the love and support of those who have shaped my life journey and made this book possible.
xvi To my parents, Ram Kumar and Lakshmi Sarada, for nurturing me with unwavering love, kindness, and the freedom to pursue my passions. Your encouragement and support have fueled my determination to pursue my dreams. To my beloved wife, Ramya, and our daughter, Iraa, whose boundless love and unwavering support have been the bedrock of strength in my life. Your belief in me has propelled me forward, urging me to strive for excellence in all endeavors. To my mentor, Venkata Ravi Kumar Yenugula, for recognizing my potential, guiding me through challenges, and opening doors to new opportunities. Your wisdom, dedication, and noble pursuit of knowledge have been a constant source of inspiration. To my co-authors, Venkata Ravi Kumar Yenugula and Phani Kadambari, and technical reviewers, Velu Natarajan and Raghavendra S – your dedication, collaboration, and unwavering support throughout the writing process have enriched this book and made it truly special. To my esteemed American Airlines leaders, Rasika Vaidya and Echo Jiang, for their unwavering support and encouragement on this journey. To my Apress publishing team – Shaul Elson, Gryffin Winkler, and Nirmal Selvaraj – thank you for entrusting me with the opportunity. I am confident this book will be a practical guide for many aspiring database technologists. Thank you all for being an integral part of this incredible journey. —Arun Kumar Samayam Writing the very first book in my career has been an incredible journey, and I am deeply grateful to the many people who supported me along the way. I want to use this opportunity to express my gratitude to God and bow down to my parents, Shri Kadambari Rama Badri Raju and Smt. Satyavathi, for this life, their teachings, and invaluable lessons at every phase of my life. Special mention to my sister, Smt. Poornima Garimella, whose sacrifice, support, and encouragement inspired me to strive for my achievements. Special thanks to my beloved wife, Praneetha Kadambari, undoubtedly the pillar in my life for providing unconditional love and support in whatever I do and the decisions I take. I thank our daughters Aadhya and Nihidaa for their mature understanding and giving me space and time to complete this book. aCknowledgmenTs
xvii My respectful obeisance and my heartfelt gratitude to my gurus: – Shri Namburi Bhima Shankar Acharya, a revered individual, whose blessings have brought me here today. – M.V. Madhusudan, Founder and M.D. of Wilshire Software Technologies, who offered me my first opportunity as a Database Administrator and played a pivotal role in shaping my career. – Venkata Ramakrishna Gandi, more of a brother than a mentor. His guidance has inspired me to continuously learn and maintain a calm, composed mindset in every situation. – Venkata Ravi Kumar Yenugula, an inspiration to many aspirants whose mentorship has played a significant role in shaping my profes- sional growth. I am grateful to my co-authors, Arun Kumar Samayam and Y V Ravi Kumar, and the technical reviewers, Velu Natarajan and Raghavendra S, for considering me for this project and for their time and efforts in contributing to and producing great content. I extend my thanks to all my friends, well-wishers, and my colleagues at work for their continuous encouragement and support to develop individually and professionally. To my Apress publishing team – Shaul Elson, Gryffin Winkler, Nirmal Selvaraj, and Laura Berendson – thank you for your trust and the opportunity given to write my first book. —Sri Ram Phani Kiran Kadambari aCknowledgmenTs
1 © Y V Ravi Kumar, Arun Kumar Samayam, and Phani Kadambari 2025 Y. V. Ravi Kumar et al., Mastering PostgreSQL Administration, https://doi.org/10.1007/979-8-8688-1507-2_1 CHAPTER 1 PostgreSQL System Architecture Introduction In this chapter, we learn about the origin of PostgreSQL, its architecture, and its components and understand the various components of PostgreSQL during a client connection request. We cover the following topics: • Origin of PostgreSQL • PostgreSQL key architectural components • PostgreSQL server process tree • PostgreSQL architecture flow PostgreSQL is one of the most popular open source object-relational database management systems (ORDBMS). It is based on POSTGRES, Version 4.2, initially developed at the University of California at Berkeley’s Computer Science department. PostgreSQL is based on the Berkeley code and follows the SQL standard, offering various features we will cover in this book. The PostgreSQL architecture is designed to handle transactions efficiently and maintain data integrity, supporting concurrent sessions. In this chapter, we will learn about the various components of the PostgreSQL internal architecture and their functions. PostgreSQL follows a typical client/server architecture. The client and server are usually on different hosts and communicate over a TCP/IP network connection. Several core components work together to handle queries, manage data storage, and ensure efficient execution of the query operations.
2 PostgreSQL Components The key components in a PostgreSQL architecture are 1. Server process 2. Utility process 3. System memory 4. Physical files Each of these core components further relies on several minor components. Let’s learn about each core component in detail and its function. 1. Server process A server process consists of the following components: Postmaster process: This is the central process that starts and controls all other PostgreSQL processes. It listens for incoming client connections and spawns background processes to handle each connection. postgres background process: Each incoming client connection is served by a dedicated backend process responsible for query parsing, planning, execution, and client interaction. The server process is represented in the figure below. Chapter 1 postgresQL system arChiteCture
3 Figure 1-1. PostgreSQL server process In Figure 1-1, P1/P2/P3 are the backend processes, and BW1/BW2/ BW3 are the corresponding background worker processes. 2. Utility process The utility process is a collection of auxiliary processes. These secondary or supplementary processes perform all the tasks initiated by the server process. Let’s learn about the different auxiliary processes. Background writer: The background writer handles periodic writes of dirty buffers from shared memory to the disk. Dirty buffers are modified data that has yet to be written to the disk and can get lost if a server restart happens. So flushing the data from the shared buffers is essential, and the background writer handles this periodically, freeing up space from the shared buffer. Chapter 1 postgresQL system arChiteCture