PostgreSQL 14 Administration Cookbook - Simon Riggs - E-Book

PostgreSQL 14 Administration Cookbook E-Book

Simon Riggs

0,0
39,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

PostgreSQL is a powerful, open-source database management system with an enviable reputation for high performance and stability. With many new features in its arsenal, PostgreSQL 14 allows you to scale up your PostgreSQL infrastructure. With this book, you'll take a step-by-step, recipe-based approach to effective PostgreSQL administration.
This book will get you up and running with all the latest features of PostgreSQL 14 while helping you explore the entire database ecosystem. You’ll learn how to tackle a variety of problems and pain points you may face as a database administrator such as creating tables, managing views, improving performance, and securing your database. As you make progress, the book will draw attention to important topics such as monitoring roles, validating backups, regular maintenance, and recovery of your PostgreSQL 14 database. This will help you understand roles, ensuring high availability, concurrency, and replication. Along with updated recipes, this book touches upon important areas like using generated columns, TOAST compression, PostgreSQL on the cloud, and much more.
By the end of this PostgreSQL book, you’ll have gained the knowledge you need to manage your PostgreSQL 14 database efficiently, both in the cloud and on-premise.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 732

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



PostgreSQL 14 Administration Cookbook

Over 175 proven recipes for database administrators to manage enterprise databases effectively

Simon Riggs

Gianni Ciolli

BIRMINGHAM—MUMBAI

PostgreSQL 14 Administration Cookbook

Copyright © 2022 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Publishing Product Manager: Devika Battike

Senior Editor: David Sugarman

Content Development Editor: Joseph Sunil

Technical Editor: Rahul Limbachiya

Copy Editor: Safis Editing

Project Coordinator: Aparna Nair

Proofreader: Safis Editing

Indexer: Tejal Daruwale Soni

Production Designer: Alishon Mendonca

Marketing Coordinator: Priyanka Mhatre

First published: October 2010

Second Edition: April 2015

Third Edition: April 2017

Fourth Edition: May 2018

Fifth Edition: May 2019

Sixth Edition: April 2022

Production reference: 1240222

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80324-897-4

www.packt.com

Contributors

About the authors

Simon Riggs is a Postgres Fellow at EnterpriseDB (EDB), a member of the company's executive management team, and a major developer of PostgreSQL for over 15 years. At EDB, he contributes to technical strategy and works with key customers directly. Before this, Simon was the founder and CEO of 2ndQuadrant, acquired by EDB in 2020. Simon has contributed widely to PostgreSQL over the course of 17 years, initiating new projects, contributing ideas, and committing many important changes. He continues his work with the PostgreSQL community as a developer and on patch review. Simon is also a regular speaker at PostgreSQL conferences. Simon lives happily with his wife Karen in England.

Gianni Ciolli is the Vice President for Solutions Architecture at EnterpriseDB (EDB). As a PostgreSQL consultant, he has driven many successful enterprise deployments for customers in every part of the globe. Gianni is respected worldwide as a popular speaker and trainer at many PostgreSQL conferences in Europe and abroad over the last 14 years. He has worked with free and open source software since the 1990s as an active member of the community (the Prato Linux User Group and the Italian PostgreSQL Users Group). Gianni has a PhD in mathematics from the University of Florence. He lives in London with his son. His other interests include music, drama, poetry, and athletics.

About the reviewers

Marcelo Diaz is a software engineer with more than 15 years of experience, with a special focus on PostgreSQL. He is passionate about open source software and has promoted its application in critical and high-demand environments where he has worked as a software developer and consultant for both private and public companies. He currently works very happily at Cybertec and as a technical reviewer for Packt Publishing. He enjoys spending his leisure time with his daughter, Malvina, and his wife, Romina. He also likes playing football.

Tomas Vondra is a PostgreSQL committer and works as a principal database engineer at EnterpriseDB. He started working with PostgreSQL in 2003, initially as a user and developer of systems on top of PostgreSQL, learning various aspects of operating and tuning the database. Eventually, he started to contribute patches of increasing complexity. After some time, he was recognized as a major contributor and became a committer in 2018. At EnterpriseDB, he helps customers and users with all sorts of issues and focuses on features related to performance, query optimizer capabilities, extended statistics, and reliability. He's also the author of various plugins and extensions. He lives in Prague, Czech Republic.

Table of Contents

Preface

Chapter 1: First Steps

Introducing PostgreSQL 14

What makes PostgreSQL different?

How to get PostgreSQL

How to do it...

How it works...

There's more…

Connecting to the PostgreSQL server

Getting ready

How to do it…

How it works…

There's more…

See also

Enabling access for network/remote users

How to do it…

How it works…

There's more…

See also

Using the pgAdmin4 GUI tool

How to do it…

How it works…

Using the OmniDB GUI tool

How to do it…

See also

Using the psql query and scripting tool

Getting ready

How to do it…

How it works…

There's more…

See also

Changing your password securely

How to do it…

How it works…

Avoiding hardcoding your password

Getting ready

How to do it…

How it works…

There's more…

Using a connection service file

How to do it…

How it works…

Troubleshooting a failed connection

How to do it…

There's more…

PostgreSQL in the cloud

Getting ready

How to do it…

How it works…

There's more…

Chapter 2: Exploring the Database

What type of server is this?

How to do it…

There's more...

What version is the server?

How to do it…

How it works…

There's more…

What is the server uptime?

How to do it…

How it works…

See also

Locating the database server files

Getting ready

How to do it...

How it works...

There's more…

Locating the database server's message log

Getting ready

How to do it...

How it works...

There's more...

See also

Locating the database's system identifier

Getting ready

How to do it…

How it works…

Listing databases on the database server

How to do it…

How it works...

There's more...

How many tables are there in a database?

How to do it...

How it works…

There's more…

How much disk space does a database use?

How to do it...

How it works...

How much disk space does a table use?

How to do it…

How it works…

There's more…

Which are my biggest tables?

How to do it...

How it works…

How many rows are there in a table?

How to do it…

How it works...

Quickly estimating the number of rows in a table

How to do it…

How it works…

There's more…

Listing extensions in this database

How to do it…

How it works…

There's more…

See also

Understanding object dependencies

Getting ready

How to do it…

How it works…

There's more…

Chapter 3: Server Configuration

RTFM

How to do it…

How it works…

There's more…

Planning a new database

Getting ready

How to do it…

How it works…

There's more…

Setting configuration parameters for the database server

Getting ready

How to do it…

How it works…

There's more…

Setting configuration parameters in your programs

How to do it…

How it works…

There's more…

Finding the configuration settings for your session

How to do it…

How it works…

Finding parameters with non-default settings

How to do it…

How it works...

There's more...

Setting parameters for particular groups of users

How to do it…

How it works…

A basic server configuration checklist

Getting ready

How to do it…

There's more…

Adding an external module to PostgreSQL

Getting ready

How to do it…

How it works...

Using an installed module/extension

Getting ready

How to do it…

How it works...

Managing installed extensions

How to do it…

How it works…

There's more…

Chapter 4: Server Control

Overview of controlling the database server

Starting the database server manually

Getting ready

How to do it…

How it works…

Stopping the server safely and quickly

How to do it…

How it works…

See also

Stopping the server in an emergency

How to do it…

How it works…

Reloading the server configuration files

How to do it…

How it works…

There's more…

Restarting the server quickly

How to do it…

There's more…

Preventing new connections

How to do it…

How it works…

Restricting users to only one session each

How to do it…

How it works…

Pushing users off the system

How to do it…

How it works…

Deciding on a design for multitenancy

How to do it…

How it works…

Using multiple schemas

Getting ready

How to do it…

How it works…

Giving users their own private databases

Getting ready

How to do it…

How it works…

There's more…

See also

Running multiple servers on one system

Getting ready

How to do it…

How it works…

Setting up a connection pool

Getting ready

How to do it…

How it works…

There's more…

Accessing multiple servers using the same host and port

Getting ready

How to do it…

There's more…

Chapter 5: Tables and Data

Choosing good names for database objects

Getting ready

How to do it…

There's more…

Handling objects with quoted names

Getting ready

How to do it...

How it works…

There's more…

Enforcing the same name and definition for columns

Getting ready

How to do it...

How it works…

There's more…

Identifying and removing duplicates

Getting ready

How to do it…

How it works…

There's more…

Preventing duplicate rows

Getting ready

How to do it…

How it works…

There's more...

Finding a unique key for a set of data

Getting ready

How to do it…

How it works…

Generating test data

How to do it...

How it works…

There's more…

See also

Randomly sampling data

How to do it…

How it works...

Loading data from a spreadsheet

Getting ready

How to do it...

How it works...

There's more...

Loading data from flat files

Getting ready

How to do it...

How it works…

There's more…

Making bulk data changes using server-side procedures with transactions

Getting ready

How to do it…

There's more…

Chapter 6: Security

Overview of PostgreSQL security

Typical user roles

The PostgreSQL superuser

How to do it…

How it works…

There's more…

See also

Revoking user access to a table

Getting ready

How to do it…

How it works…

There's more…

Granting user access to a table

Getting ready

How to do it…

How it works...

There's more…

Granting user access to specific columns

Getting ready

How to do it…

How it works…

There's more…

Granting user access to specific rows

Getting ready

How to do it…

How it works…

There's more...

Creating a new user

Getting ready

How to do it...

How it works…

There's more…

Temporarily preventing a user from connecting

Getting ready

How to do it…

How it works...

There's more…

Removing a user without dropping their data

Getting ready

How to do it…

How it works…

Checking whether all users have a secure password

How to do it…

How it works…

Giving limited superuser powers to specific users

Getting ready

How to do it…

How it works…

There's more…

Auditing database access

Getting ready

Auditing access

Auditing SQL

Auditing table access

Managing the audit log

Auditing data changes

Always knowing which user is logged in

Getting ready

How to do it…

How it works…

There's more…

Integrating with LDAP

Getting ready

How to do it…

How it works…

There's more…

See also

Connecting using encryption (SSL/GSSAPI)

Getting ready

How to do it…

How it works…

There's more…

Using SSL certificates to authenticate

Getting ready

How to do it…

How it works…

There's more…

See also

Mapping external usernames to database roles

Getting ready

How to do it…

How it works…

There's more…

Using column-level encryption

Getting ready

How to do it…

How it works…

There's more…

See also

Setting up cloud security using predefined roles

Getting ready

How to do it…

How it works…

There's more…

Chapter 7: Database Administration

Writing a script that either succeeds entirely or fails entirely

How to do it…

How it works…

There's more…

Writing a psql script that exits on the first error

Getting ready

How to do it…

How it works…

There's more…

Using psql variables

Getting ready

How to do it…

How it works…

There's more…

Placing query output into psql variables

Getting ready

How to do it…

How it works…

There's more…

Writing a conditional psql script

Getting ready

How to do it…

How it works…

There's more…

Investigating a psql error

Getting ready

How to do it…

There's more…

Setting the psql prompt with useful information

Getting ready

How to do it…

How it works…

Using pgAdmin for DBA tasks

Getting ready

How to do it…

How it works...

There's more…

Scheduling jobs for regular background execution

Getting ready

How to do it…

How it works…

There's more…

Performing actions on many tables

Getting ready

How to do it…

How it works…

There's more…

Adding/removing columns on a table

How to do it…

How it works…

There's more…

Changing the data type of a column

Getting ready

How to do it…

How it works…

There's more…

Changing the definition of an enum data type

Getting ready

How to do it…

How it works…

There's more…

Adding a constraint concurrently

Getting ready

How to do it…

How it works…

There's more…

Adding/removing schemas

How to do it…

There's more…

Moving objects between schemas

How to do it…

How it works…

There's more…

Adding/removing tablespaces

Getting ready

How to do it…

How it works…

There's more…

Moving objects between tablespaces

Getting ready

How to do it…

How it works…

There's more…

Accessing objects in other PostgreSQL databases

Getting ready

How to do it…

How it works…

There's more…

Accessing objects in other foreign databases

Getting ready

How to do it…

How it works…

There's more…

Making views updatable

Getting ready

How to do it…

How it works…

There's more…

Using materialized views

Getting ready

How to do it…

How it works…

There's more…

Using GENERATED data columns

How to do it…

How it works…

There's more…

Using data compression

Getting ready

How to do it…

How it works…

There's more…

Chapter 8: Monitoring and Diagnosis

Overview of PostgreSQL monitoring

Cloud-native monitoring

Providing PostgreSQL information to monitoring tools

Finding more information about generic monitoring tools

Real-time viewing using pgAdmin

Getting ready

How to do it…

Checking whether a user is connected

Getting ready

How to do it…

How it works…

There's more…

Checking whether a computer is connected

How to do it…

There's more…

Repeatedly executing a query in psql

How to do it…

There's more…

Checking which queries are running

Getting ready

How to do it…

How it works…

There's more…

See also

Monitoring the progress of commands

Getting ready

How to do it…

How it works…

There's more…

Checking which queries are active or blocked

Getting ready

How to do it…

How it works…

There's more…

Knowing who is blocking a query

Getting ready

How to do it…

How it works…

Killing a specific session

How to do it…

How it works…

There's more…

Detecting an in-doubt prepared transaction

How to do it…

Knowing whether anybody is using a specific table

Getting ready

How to do it…

How it works…

There's more...

Knowing when a table was last used

Getting ready

How to do it…

How it works...

There's more…

Usage of disk space by temporary data

Getting ready

How to do it…

How it works…

There's more…

Understanding why queries slow down

Getting ready

How to do it…

How it works…

There's more…

See also

Analyzing the real-time performance of your queries

Getting ready

How to do it…

How it works…

There's more…

Investigating and reporting a bug

Getting ready

How to do it…

How it works…

Chapter 9: Regular Maintenance

Controlling automatic database maintenance

Getting ready

How to do it…

How it works…

There's more…

See also

Avoiding auto-freezing and page corruptions

How to do it…

Removing issues that cause bloat

Getting ready

How to do it…

How it works…

There's more…

Removing old prepared transactions

Getting ready

How to do it…

How it works…

There's more…

Actions for heavy users of temporary tables

How to do it…

How it works…

Identifying and fixing bloated tables and indexes

Getting ready

How to do it…

How it works…

There's more…

Monitoring and tuning a vacuum

Getting ready

How to do it…

How it works…

There's more…

Maintaining indexes

Getting ready

How to do it…

How it works…

There's more…

Finding unused indexes

How to do it…

How it works…

Carefully removing unwanted indexes

Getting ready

How to do it…

How it works…

Planning maintenance

How to do it…

How it works…

There's more…

Chapter 10: Performance and Concurrency

Finding slow SQL statements

Getting ready

How to do it…

How it works…

There's more…

Finding out what makes SQL slow

Getting ready

How to do it…

There's more…

See also

Reducing the number of rows returned

How to do it…

There's more…

Simplifying complex SQL queries

Getting ready

How to do it…

There's more…

Speeding up queries without rewriting them

How to do it…

There's more…

Discovering why a query is not using an index

Getting ready

How to do it…

How it works…

There's more…

Forcing a query to use an index

Getting ready

How to do it…

There's more…

Using parallel query

How to do it…

How it works…

Creating time-series tables using partitioning

How to do it…

How it works…

There's more…

Using optimistic locking to avoid long lock waits

How to do it…

How it works…

There's more…

Reporting performance problems

How to do it…

There's more…

Chapter 11: Backup and Recovery

Understanding and controlling crash recovery

How to do it…

How it works…

There's more…

Planning your backups

How to do it…

There's more…

Hot logical backups of one database

How to do it…

How it works…

There's more…

See also

Hot logical backups of all databases

How to do it…

How it works…

See also

Backups of database object definitions

How to do it…

There's more…

A standalone hot physical backup

Getting ready

How to do it…

How it works…

There's more…

Hot physical backups with Barman

Getting ready

How to do it…

How it works…

There's more…

Recovery of all databases

Getting ready

How to do it…

How it works…

There's more…

Recovery to a point in time

Getting ready

How to do it…

How it works…

There's more…

See also

Recovery of a dropped/damaged table

How to do it…

How it works…

See also

Recovery of a dropped/damaged database

How to do it…

Extracting a logical backup from a physical one

Getting ready

How to do it…

There's more…

Improving performance of logical backup/recovery

Getting ready

How to do it…

How it works…

There's more…

Improving performance of physical backup/recovery

Getting ready

How to do it...

How it works…

There's more…

See also

Validating backups

Getting ready

How to do it…

How it works…

There's more…

Chapter 12: Replication and Upgrades

Replication concepts

Topics

Basic concepts

History and scope

Practical aspects

Data loss

Single-master replication

Multinode architectures

Multi-master replication

Other approaches to replication

Replication best practices

Getting ready

How to do it…

There's more…

Setting up streaming replication

Getting ready

How to do it…

How it works…

There's more…

Setting up streaming replication security

Getting ready

How to do it…

How it works…

There's more…

Hot Standby and read scalability

Getting ready

How to do it…

How it works…

Managing streaming replication

Getting ready

How to do it…

There's more…

See also

Using repmgr

Getting ready

How to do it…

How it works…

There's more…

Using replication slots

Getting ready

How to do it…

There's more…

See also

Monitoring replication

Getting ready

How to do it…

There's more…

Performance and sync rep

Getting ready

How to do it...

How it works…

There's more…

Delaying, pausing, and synchronizing replication

Getting ready

How to do it…

There's more…

See also

Logical replication

Getting ready

How to do it…

How it works…

There's more…

BDR

Getting ready

How to do it…

How it works...

There's more…

Archiving transaction log data

Getting ready

How to do it…

There's more...

See also

Upgrading minor releases

Getting ready

How to do it…

How it works…

There's more…

Major upgrades in-place

Getting ready

How to do it…

How it works…

Major upgrades online

How to do it…

How it works...

Other Books You May Enjoy