Book Image

PostgreSQL 13 Cookbook

By : Vallarapu Naga Avinash Kumar
Book Image

PostgreSQL 13 Cookbook

By: Vallarapu Naga Avinash Kumar

Overview of this book

PostgreSQL has become the most advanced open source database on the market. This book follows a step-by-step approach, guiding you effectively in deploying PostgreSQL in production environments. The book starts with an introduction to PostgreSQL and its architecture. You’ll cover common and not-so-common challenges faced while designing and managing the database. Next, the book focuses on backup and recovery strategies to ensure your database is steady and achieves optimal performance. Throughout the book, you’ll address key challenges such as maintaining reliability, data integrity, a fault-tolerant environment, a robust feature set, extensibility, consistency, and authentication. Moving ahead, you’ll learn how to manage a PostgreSQL cluster and explore replication features for high availability. Later chapters will assist you in building a secure PostgreSQL server, along with covering recipes for encrypting data in motion and data at rest. Finally, you’ll not only discover how to tune your database for optimal performance but also understand ways to monitor and manage maintenance activities, before learning how to perform PostgreSQL upgrades during downtime. By the end of this book, you’ll be well-versed with the essential PostgreSQL 13 features to build enterprise relational databases.
Table of Contents (14 chapters)
12
About Packt

Viewing the execution plans using EXPLAIN in PostgreSQL

EXPLAIN in PostgreSQL can be used to print the execution plan considered by the PostgreSQL optimizer for a given query. However, to see the actual cost and time consumed by SQL, we must use EXPLAIN ANALYZE. In this recipe, we will discuss how EXPLAIN can be used to identify an area where a query needs to be optimized.

Getting ready

In order to run EXPLAIN, we need to have a SQL statement that has its bind variables substituted with the actual values. Otherwise, EXPLAIN returns an error. In addition to that, while running EXPLAIN ANALYZE, we must always avoid running it on a SQL statement that is performing a DML or a DDL. This is because it executes the statement and prints the execution plan and actual cost information. In emergency situations, we may carefully open a transaction and run EXPLAIN ANALYZE on a statement and roll it back immediately.

How to do it...

EXPLAIN is available in PostgreSQL by default. The following are...