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

How to rebuild indexes of a table online using pg_repack

An index in PostgreSQL may become very bloated if there is no proper vacuuming or regular index maintenance. An index can be created online using the CONCURRENTLY option. However, switching the index to its original name or rebuilding a primary key index or a unique index may need to be done with some additional care. All of this can be made easy using pg_repack. In this recipe, we shall discuss how an index of all the indexes of a table can be rebuilt online using pg_repack.

Getting ready

There are currently no restrictions on what indexes can or cannot be rebuilt. However, it is important to test using a dry run before repacking a specific index or all the indexes of a table using pg_repack.

How to do it...

In the following sections, we shall see how to rebuild all the indexes of a table and how to rebuild a specific index of a table.

Rebuilding all the indexes of a table

Let's get started with the following steps:

  1. The...