100% found this document useful (4 votes)
2K views52 pages

Learn PostgreSQL - Second Edition - . - All Chapter Instant Download

Learn

Uploaded by

tipowashaffa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
2K views52 pages

Learn PostgreSQL - Second Edition - . - All Chapter Instant Download

Learn

Uploaded by

tipowashaffa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Download the full version of the textbook now at textbookfull.

com

Learn PostgreSQL - Second Edition -.-

https://textbookfull.com/product/learn-postgresql-
second-edition/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

PostgreSQL Server Programming - Second Edition Dar

https://textbookfull.com/product/postgresql-server-programming-second-
edition-dar/

textbookfull.com

PostgreSQL 9 Administration Cookbook - Second Edition


Simon Riggs

https://textbookfull.com/product/postgresql-9-administration-cookbook-
second-edition-simon-riggs/

textbookfull.com

Learn Python Programming Second Edition Fabrizio Romano

https://textbookfull.com/product/learn-python-programming-second-
edition-fabrizio-romano/

textbookfull.com

Nations of nothing but poetry modernism transnationalism


and synthetic vernacular writing 1st Edition Hart

https://textbookfull.com/product/nations-of-nothing-but-poetry-
modernism-transnationalism-and-synthetic-vernacular-writing-1st-
edition-hart/
textbookfull.com
Teaching physical education for learning Seventh Edition.
Edition Rink

https://textbookfull.com/product/teaching-physical-education-for-
learning-seventh-edition-edition-rink/

textbookfull.com

Trigonometry Booster with Problems and Solutions Rejaul


Makshud

https://textbookfull.com/product/trigonometry-booster-with-problems-
and-solutions-rejaul-makshud/

textbookfull.com

Nanophotocatalysis and Environmental Applications Energy


Conversion and Chemical Transformations Inamuddin

https://textbookfull.com/product/nanophotocatalysis-and-environmental-
applications-energy-conversion-and-chemical-transformations-inamuddin/

textbookfull.com

Metaheuristic Algorithms for Image Segmentation Theory and


Applications Diego Oliva

https://textbookfull.com/product/metaheuristic-algorithms-for-image-
segmentation-theory-and-applications-diego-oliva/

textbookfull.com

Criminal Courts A Contemporary Perspective Craig T.


Hemmens

https://textbookfull.com/product/criminal-courts-a-contemporary-
perspective-craig-t-hemmens/

textbookfull.com
Emergent Complexity from Nonlinearity in Physics
Engineering and the Life Sciences Proceedings of the XXIII
International Conference on Nonlinear Dynamics of
Electronic Systems Como Italy 7 11 September 2015 1st
https://textbookfull.com/product/emergent-complexity-from-
Edition Giorgio Mantica
nonlinearity-in-physics-engineering-and-the-life-sciences-proceedings-
of-the-xxiii-international-conference-on-nonlinear-dynamics-of-
electronic-systems-como-italy-7-11-septemb/
textbookfull.com
Learn PostgreSQL
Second Edition

Use, manage, and build secure and scalable databases


with PostgreSQL 16

Luca Ferrari
Enrico Pirozzi

BIRMINGHAM—MUMBAI
Learn PostgreSQL
Second Edition

Copyright © 2023 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.

Senior Publishing Product Manager: Gebin George


Acquisition Editor – Peer Reviews: Gaurav Gavas
Project Editor: Meenakshi Vijay
Content Development Editor: Elliot Dallow
Copy Editor: Safis Editing
Technical Editor: Kushal Sharma
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Presentation Designer: Rajesh Shirsath
Developer Relations Marketing Executive: Vignesh Raju

First published: October 2020


Second edition: October 2023

Production reference: 1251023

Published by Packt Publishing Ltd.


Grosvenor House
11 St Paul’s Square
Birmingham
B3 1RB, UK.

ISBN 978-1-83763-564-1

www.packt.com
To my beautiful wife, Emanuela; I love her like Santa loves his reindeer.

To my great son, Diego, who changed our lives on 1283788200.

To my parents, Miriam and Anselmo: my greatest fans since day one.

– Luca Ferrari

In loving memory of my father, Ilario.

– Enrico Pirozzi
Contributors

About the authors


Luca Ferrari has been passionate about computer science since the Commodore 64 era, and
today holds a master’s degree (with honors) and a Ph.D. from the University of Modena and Reggio
Emilia. He has written several research papers, technical articles, and book chapters. In 2011, he
was named an adjunct professor by Nipissing University. An avid Unix user, he is a strong advo-
cate of open-source, and in his free time, he collaborates on a few projects. He first encountered
PostgreSQL back in the days of release 7.3; he was a founder and former president of the Italian
PostgreSQL Users’ Group (ITPUG). He also talks regularly at technical conferences and events
and delivers professional training.

Enrico Pirozzi has been passionate about computer science since he was a 13-year-old. His first
computer was a Commodore 64, and today he holds a master’s degree from the University of Bo-
logna. He has participated as a speaker at national and international conferences on PostgreSQL.
He first encountered PostgreSQL back in release 7.2, he was a co-founder of the first PostgreSQL
Italian mailing list and the first Italian PostgreSQL website, and he talks regularly at technical
conferences and events and delivers professional training. Right now, he is employed as a Post-
greSQL database administrator at Zucchetti Hospitality (Zucchetti Group S.p.a).
About the reviewers
Chris Mair holds a master’s degree from the University of Trento, Italy, and has been freelance
since 2003. His portfolio consists of contributions to over 25 companies, including consultancy
work on database programming, performance optimization, and seamless migrations. Chris has
expertise in system and network programming, data processing, ML, and more. He has a particular
affinity for PostgreSQL. He has taught over 200 courses on various IT topics and is passionate
about open-source software.

Silvio Trancanella is a software engineer with around 12 years of experience in backend devel-
opment, mainly using Java Enterprise and PostgreSQL. He has always been fascinated by database
management and was immediately drawn to PostgreSQL from the very beginning of his career.
He worked for about 10 years on tourism industry software, developing and maintaining critical
services that relied on the PostgreSQL DBMS.
Learn more on Discord
To join the Discord community for this book – where you can share feedback, ask questions to
the author, and learn about new releases – follow the QR code below:

https://discord.gg/jYWCjF6Tku
Table of Contents

Preface  xxv

Chapter 1: Introduction to PostgreSQL  1

Technical requirements ������������������������������������������������������������������������������������������������������ 2


PostgreSQL at a glance �������������������������������������������������������������������������������������������������������� 2
A brief history of PostgreSQL • 4
What’s new in PostgreSQL 16? • 5
PostgreSQL release policy, version numbers, and life cycle • 5
Exploring PostgreSQL terminology ������������������������������������������������������������������������������������� 6
Installing PostgreSQL ������������������������������������������������������������������������������������������������������� 10
What to install • 11
Installing PostgreSQL from binary packages • 12
Using the book’s Docker images • 13
Installing PostgreSQL on GNU/Linux Debian, Ubuntu, and derivatives • 14
Installing PostgreSQL on Fedora Linux • 15
Installing PostgreSQL on FreeBSD • 16
Installing PostgreSQL from sources • 17
Installing PostgreSQL via pgenv • 18
Summary �������������������������������������������������������������������������������������������������������������������������� 19
References ������������������������������������������������������������������������������������������������������������������������� 20
viii Table of Contents

Chapter 2: Getting to Know Your Cluster  21

Technical requirements ���������������������������������������������������������������������������������������������������� 22


Managing your cluster ������������������������������������������������������������������������������������������������������ 22
pg_ctl • 22
PostgreSQL processes • 28
Connecting to the cluster ��������������������������������������������������������������������������������������������������� 31
The template databases • 31
The psql command-line client • 33
Entering SQL statements via psql • 35
A glance at the psql commands • 38
Introducing the connection string • 39
Solving common connection problems ����������������������������������������������������������������������������� 40
Database “foo” does not exist • 40
Connection refused • 40
No pg_hba.conf entry • 41
Exploring the disk layout of PGDATA �������������������������������������������������������������������������������� 42
Objects in the PGDATA directory • 43
Tablespaces • 45
Exploring configuration files and parameters ������������������������������������������������������������������� 46
Summary �������������������������������������������������������������������������������������������������������������������������� 48
Verify your knowledge ������������������������������������������������������������������������������������������������������ 49
References ������������������������������������������������������������������������������������������������������������������������� 49

Chapter 3: Managing Users and Connections  51

Technical requirements ���������������������������������������������������������������������������������������������������� 52


Introduction to users and groups �������������������������������������������������������������������������������������� 52
Managing roles ����������������������������������������������������������������������������������������������������������������� 53
Creating new roles • 53
Role passwords, connections, and availability • 54
Using a role as a group • 55
Table of Contents ix

Removing an existing role • 57


Inspecting existing roles • 58
Managing incoming connections at the role level ������������������������������������������������������������� 61
The syntax of pg_hba.conf • 62
Order of rules in pg_hba.conf • 64
Merging multiple rules into a single one • 64
Using groups instead of single roles • 65
Using files instead of single roles • 66
Inspecting pg_hba.conf rules • 67
Including other files in pg_hba.conf • 68
Summary �������������������������������������������������������������������������������������������������������������������������� 68
Verify your knowledge ������������������������������������������������������������������������������������������������������ 69
References ������������������������������������������������������������������������������������������������������������������������� 69

Chapter 4: Basic Statements  71

Technical requirements ���������������������������������������������������������������������������������������������������� 72


Using the Docker image • 72
Connecting the database • 72
Creating and managing databases ������������������������������������������������������������������������������������ 73
Creating a database • 73
Managing databases • 74
Introducing schemas • 74
PostgreSQL and the public schema • 74
The search_path variable • 75
The correct way to start working • 75
Listing all tables • 76
Making a new database from a modified template • 77
Dropping tables and databases • 78
Dropping tables • 78
Dropping databases • 79
Making a database copy • 79
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
x Table of Contents

Confirming the database size • 80


The psql method • 80
The SQL method • 81
Behind the scenes of database creation • 81
Managing tables ��������������������������������������������������������������������������������������������������������������� 84
The EXISTS option • 85
Managing temporary tables • 86
Managing unlogged tables • 88
Creating a table • 89
Understanding basic table manipulation statements ������������������������������������������������������� 90
Inserting and selecting data • 90
NULL values • 94
Sorting with NULL values • 96
Creating a table starting from another table • 97
Updating data • 98
Deleting data • 99
Summary ������������������������������������������������������������������������������������������������������������������������� 101
Verify your knowledge ����������������������������������������������������������������������������������������������������� 101
References ����������������������������������������������������������������������������������������������������������������������� 102

Chapter 5: Advanced Statements  105

Technical requirements �������������������������������������������������������������������������������������������������� 105


Exploring the SELECT statement ������������������������������������������������������������������������������������ 105
Using the like clause ������������������������������������������������������������������������������������������������������� 106
Using ilike ����������������������������������������������������������������������������������������������������������������������� 108
Using distinct ������������������������������������������������������������������������������������������������������������������ 108
Using limit and offset �������������������������������������������������������������������������������������������������������� 111
Using subqueries �������������������������������������������������������������������������������������������������������������� 112
Subqueries and the IN/NOT IN condition • 113
Subqueries and the EXISTS/NOT EXISTS condition • 116
Table of Contents xi

Learning about joins �������������������������������������������������������������������������������������������������������� 117


Using INNER JOIN • 119
INNER JOIN versus EXISTS/IN • 120
Using LEFT JOINS • 121
Using RIGHT JOIN • 125
Using FULL OUTER JOIN • 127
Using LATERAL JOIN • 129
Aggregate functions �������������������������������������������������������������������������������������������������������� 130
UNION/UNION ALL • 133
EXCEPT/INTERSECT • 135
Using UPSERT ������������������������������������������������������������������������������������������������������������������ 137
UPSERT – the PostgreSQL way • 137
Learning the RETURNING clause for INSERT ������������������������������������������������������������������ 140
Returning tuples out of queries • 141
UPDATE related to multiple records • 141
MERGE • 142
Exploring UPDATE ... RETURNING • 144
Exploring DELETE ... RETURNING • 145
Exploring CTEs ���������������������������������������������������������������������������������������������������������������� 145
CTE concept • 145
CTE in PostgreSQL since version 12 ��������������������������������������������������������������������������������� 146
CTE – use cases • 147
Query recursion • 149
Recursive CTEs • 150
Summary ������������������������������������������������������������������������������������������������������������������������� 151
Verify your knowledge ����������������������������������������������������������������������������������������������������� 152
References ������������������������������������������������������������������������������������������������������������������������ 153

Chapter 6: Window Functions  155

Technical requirements ��������������������������������������������������������������������������������������������������� 155


Using basic statement window functions ������������������������������������������������������������������������ 156
xii Table of Contents

Using the PARTITION BY function and WINDOW clause • 157


Introducing some useful functions • 158
The ROW_NUMBER function • 159
The ORDER BY clause • 159
FIRST_VALUE • 160
LAST_VALUE • 161
RANK • 161
DENSE_RANK • 162
The LAG and LEAD functions • 163
The CUME_DIST function • 165
The NTILE function • 165
Using advanced statement window functions ����������������������������������������������������������������� 167
The frame clause • 167
ROWS BETWEEN start_point and end_point • 168
RANGE BETWEEN start_point and end_point • 174
Summary ������������������������������������������������������������������������������������������������������������������������ 178
Verify your knowledge ����������������������������������������������������������������������������������������������������� 179
References ����������������������������������������������������������������������������������������������������������������������� 180

Chapter 7: Server-Side Programming  181

Technical requirements �������������������������������������������������������������������������������������������������� 182


Exploring data types ������������������������������������������������������������������������������������������������������� 182
The concept of extensibility • 182
Standard data types • 182
Boolean data type • 183
Numeric data type • 184
Integer types • 185
Numbers with a fixed precision data type • 186
Numbers with an arbitrary precision data type • 186
Character data type • 188
Chars with fixed-length data types • 188
Table of Contents xiii

Chars with variable length with a limit data types • 190


Chars with a variable length without a limit data types • 191
Date/timestamp data types • 192
Date data types • 192
Timestamp data types • 195
The NoSQL data type �������������������������������������������������������������������������������������������������������� 197
The hstore data type • 198
The JSON data type • 201
Exploring functions and languages ��������������������������������������������������������������������������������� 205
Functions • 205
SQL functions • 206
Basic functions • 206
SQL functions returning a set of elements • 207
SQL functions returning a table • 208
Polymorphic SQL functions • 210
PL/pgSQL functions • 211
First overview • 211
Dropping functions • 213
Declaring function parameters • 213
IN/OUT parameters • 214
Function volatility categories • 216
Control structure • 219
Conditional statements • 220
IF statements • 220
CASE statements • 222
Loop statements • 225
The record type • 226
Exception handling statements • 228
Security definer • 229
Summary ������������������������������������������������������������������������������������������������������������������������� 231
Verify your knowledge ����������������������������������������������������������������������������������������������������� 231
xiv Table of Contents

References ����������������������������������������������������������������������������������������������������������������������� 232

Chapter 8: Triggers and Rules  233

Technical requirements �������������������������������������������������������������������������������������������������� 234


Exploring rules in PostgreSQL ����������������������������������������������������������������������������������������� 234
Understanding the OLD and NEW variables • 234
Rules on INSERT • 235
The ALSO option • 236
The INSTEAD OF option • 237
Rules on DELETE/UPDATE • 239
Creating the new_tags table • 240
Creating two tables • 241
Managing rules on INSERT, DELETE, and UPDATE events • 242
INSERT rules • 243
DELETE rules • 245
UPDATE rules • 247
Managing triggers in PostgreSQL ������������������������������������������������������������������������������������ 249
Trigger syntax • 250
Triggers on INSERT • 252
The TG_OP variable • 257
Triggers on UPDATE / DELETE • 257
Event triggers ������������������������������������������������������������������������������������������������������������������ 264
An example of an event trigger • 265
Summary ������������������������������������������������������������������������������������������������������������������������ 267
Verify your knowledge ���������������������������������������������������������������������������������������������������� 268
References ����������������������������������������������������������������������������������������������������������������������� 269

Chapter 9: Partitioning  271

Technical requirements ��������������������������������������������������������������������������������������������������� 271


Basic concepts ������������������������������������������������������������������������������������������������������������������ 271
Range partitioning • 273
Table of Contents xv

List partitioning • 274


Hash partitioning • 275
Table inheritance • 276
Dropping tables • 280
Exploring declarative partitioning ���������������������������������������������������������������������������������� 280
List partitioning • 281
Range partitioning • 284
Partition maintenance • 288
Attaching a new partition • 288
Detaching an existing partition • 289
Attaching an existing table to the parent table • 290
The default partition �������������������������������������������������������������������������������������������������������� 291
Partitioning and tablespaces ������������������������������������������������������������������������������������������� 292
A simple case study ��������������������������������������������������������������������������������������������������������� 295
Summary ������������������������������������������������������������������������������������������������������������������������ 303
Verify your knowledge ���������������������������������������������������������������������������������������������������� 303
References ����������������������������������������������������������������������������������������������������������������������� 305

Chapter 10: Users, Roles, and Database Security  307

Technical requirements �������������������������������������������������������������������������������������������������� 308


Understanding roles ������������������������������������������������������������������������������������������������������� 308
Properties related to new objects • 308
Properties related to superusers • 309
Properties related to replication • 309
Properties related to RLS • 309
Changing properties of existing roles: the ALTER ROLE statement • 310
Renaming an existing role • 310
SESSION_USER versus CURRENT_USER • 311
Per-role configuration parameters • 312
Inspecting roles • 313
Roles that inherit from other roles • 316
xvi Table of Contents

Understanding how privileges are resolved • 319


Role inheritance overview • 323
ACLs �������������������������������������������������������������������������������������������������������������������������������� 323
Default ACLs • 327
Knowing the default ACLs • 330
Granting and revoking permissions ��������������������������������������������������������������������������������� 331
Permissions related to tables • 332
Column-based permissions • 333
Permissions related to sequences • 337
Permissions related to schemas • 339
ALL objects in the schema • 341
Permissions related to programming languages • 342
Permissions related to routines • 342
Permissions related to databases • 343
Other GRANT and REVOKE statements • 344
Assigning the object owner • 344
Inspecting ACLs • 345
RLS ���������������������������������������������������������������������������������������������������������������������������������� 346
Role password encryption ����������������������������������������������������������������������������������������������� 352
SSL connections �������������������������������������������������������������������������������������������������������������� 353
Configuring the cluster for SSL • 353
Connecting to the cluster via SSL • 354
Summary ������������������������������������������������������������������������������������������������������������������������ 355
Verify your knowledge ���������������������������������������������������������������������������������������������������� 356
References ����������������������������������������������������������������������������������������������������������������������� 356

Chapter 11: Transactions, MVCC, WALs, and Checkpoints  359

Technical requirements �������������������������������������������������������������������������������������������������� 360


Introducing transactions ������������������������������������������������������������������������������������������������ 360
Comparing implicit and explicit transactions • 362
Time within transactions • 368
Table of Contents xvii

More about transaction identifiers – the XID wraparound problem • 369


Virtual and real transaction identifiers • 371
Multi-version concurrency control • 373
Transaction isolation levels �������������������������������������������������������������������������������������������� 379
READ UNCOMMITTED • 381
READ COMMITTED • 381
REPEATABLE READ • 381
SERIALIZABLE • 382
Explaining MVCC ������������������������������������������������������������������������������������������������������������ 384
Savepoints ���������������������������������������������������������������������������������������������������������������������� 387
Deadlocks ����������������������������������������������������������������������������������������������������������������������� 390
How PostgreSQL handles persistency and consistency: WALs ���������������������������������������� 393
WALs • 393
WALs as a rescue method in the event of a crash • 397
Checkpoints • 398
Checkpoint configuration parameters • 399
checkpoint_timeout and max_wal_size • 400
Checkpoint throttling • 402
Manually issuing a checkpoint • 403
VACUUM ������������������������������������������������������������������������������������������������������������������������� 403
Manual VACUUM • 404
Automatic VACUUM • 410
Summary ������������������������������������������������������������������������������������������������������������������������ 412
Verify your knowledge ����������������������������������������������������������������������������������������������������� 413
References ����������������������������������������������������������������������������������������������������������������������� 414

Chapter 12: Extending the Database – the Extension Ecosystem  415

Technical requirements ��������������������������������������������������������������������������������������������������� 415


Introducing extensions ��������������������������������������������������������������������������������������������������� 416
The extension ecosystem • 417
Extension components • 418
xviii Table of Contents

The control file • 419


The script file • 420
Managing extensions ������������������������������������������������������������������������������������������������������� 421
Creating an extension • 421
Viewing installed extensions • 422
Finding out available extension versions • 423
Altering an existing extension • 424
Removing an existing extension • 427
Exploring the PGXN client ���������������������������������������������������������������������������������������������� 428
Installing pgxnclient on Debian GNU/Linux and derivatives • 429
Installing pgxnclient on Fedora Linux and Red Hat-based distributions • 429
Installing pgxnclient on FreeBSD • 429
Installing pgxnclient from sources • 429
The pgxnclient command-line interface • 430
Installing extensions ������������������������������������������������������������������������������������������������������� 432
Installing the extension via pgxnclient • 432
Installing the extension manually • 433
Using the installed extension • 436
Removing an installed extension • 437
Removing an extension via pgxnclient • 439
Removing a manually compiled extension • 439
Creating your own extension ������������������������������������������������������������������������������������������ 439
Defining an example extension • 439
Creating extension files • 440
Installing the extension • 442
Creating an extension upgrade • 443
Performing an extension upgrade • 445
Summary ������������������������������������������������������������������������������������������������������������������������ 446
Verify your knowledge ���������������������������������������������������������������������������������������������������� 446
References ����������������������������������������������������������������������������������������������������������������������� 447
Table of Contents xix

Chapter 13: Query Tuning, Indexes, and Performance Optimization  449

Technical requirements �������������������������������������������������������������������������������������������������� 450


Execution of a statement ������������������������������������������������������������������������������������������������ 450
Execution stages • 451
The optimizer • 452
Nodes that the optimizer uses • 454
Sequential nodes • 454
Parallel nodes • 457
When does the optimizer choose a parallel plan? • 458
Utility nodes • 459
Node costs • 460
Indexes ��������������������������������������������������������������������������������������������������������������������������� 462
Index types • 462
Creating an index • 463
Inspecting indexes • 465
Dropping an index • 468
Invalidating an index • 469
Rebuilding an index • 470
The EXPLAIN statement �������������������������������������������������������������������������������������������������� 470
EXPLAIN output formats • 473
EXPLAIN ANALYZE • 474
EXPLAIN options • 476
Examples of query tuning ���������������������������������������������������������������������������������������������� 480
ANALYZE and how to update statistics ���������������������������������������������������������������������������� 491
Auto-explain ������������������������������������������������������������������������������������������������������������������� 494
Summary ������������������������������������������������������������������������������������������������������������������������ 498
Verify your knowledge ���������������������������������������������������������������������������������������������������� 499
References ���������������������������������������������������������������������������������������������������������������������� 500
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
xx Table of Contents

Chapter 14: Logging and Auditing  503

Technical requirements �������������������������������������������������������������������������������������������������� 503


Introduction to logging ��������������������������������������������������������������������������������������������������� 504
Where to log • 505
When to log • 508
What to log • 512
Extracting information from logs – pgBadger ������������������������������������������������������������������ 514
Installing pgBadger • 514
Configuring PostgreSQL logging for pgBadger usage • 515
Using pgBadger • 516
Scheduling pgBadger • 521
Implementing auditing ��������������������������������������������������������������������������������������������������� 524
Installing PgAudit • 525
Configuring PostgreSQL to exploit PgAudit • 526
Configuring PgAudit • 527
Auditing by session • 528
Auditing by role • 530
Summary ������������������������������������������������������������������������������������������������������������������������ 532
Verify your knowledge ���������������������������������������������������������������������������������������������������� 532
References ����������������������������������������������������������������������������������������������������������������������� 533

Chapter 15: Backup and Restore  535

Technical requirements �������������������������������������������������������������������������������������������������� 536


Introducing types of backups and restores ���������������������������������������������������������������������� 536
Exploring logical backups ������������������������������������������������������������������������������������������������ 537
Dumping a single database • 539
Restoring a single database • 543
Limiting the amount of data to backup • 547
Compression • 548
Dump formats and pg_restore • 549
Table of Contents xxi

Performing a selective restore • 552


Dumping a whole cluster • 555
Parallel backups • 556
Backup automation • 558
The COPY command • 559
Exploring physical backups �������������������������������������������������������������������������������������������� 563
Performing a manual physical backup • 564
pg_verifybackup • 566
Starting the cloned cluster • 567
Restoring from a physical backup • 568
Basic concepts behind PITR �������������������������������������������������������������������������������������������� 569
Summary ������������������������������������������������������������������������������������������������������������������������ 570
Verify your knowledge ���������������������������������������������������������������������������������������������������� 570
References ������������������������������������������������������������������������������������������������������������������������ 571

Chapter 16: Configuration and Monitoring  573

Technical requirements �������������������������������������������������������������������������������������������������� 574


Cluster configuration ������������������������������������������������������������������������������������������������������ 574
Inspecting all the configuration parameters • 576
Finding configuration errors • 578
Nesting configuration files • 579
Configuration contexts • 580
Main configuration settings • 581
WAL settings • 582
Memory-related settings • 584
Process information settings • 585
Networking-related settings • 585
Archive and replication settings • 586
Vacuum and autovacuum-related settings • 587
Optimizer settings • 587
Statistics collector • 587
xxii Table of Contents

Modifying the configuration from a live system • 588


Configuration generators • 589
Monitoring the cluster ���������������������������������������������������������������������������������������������������� 592
Information about running queries and sessions • 593
Inspecting locks • 594
Inspecting databases • 596
Inspecting tables and indexes • 597
More statistics • 599
Advanced statistics with pg_stat_statements ���������������������������������������������������������������� 600
Installing the pg_stat_statements extension • 600
Using pg_stat_statements • 601
Resetting data collected from pg_stat_statements • 602
Tuning pg_stat_statements • 602
Summary ������������������������������������������������������������������������������������������������������������������������ 603
Verify your knowledge ���������������������������������������������������������������������������������������������������� 603
References ���������������������������������������������������������������������������������������������������������������������� 604

Chapter 17: Physical Replication  607

Technical requirements ������������������������������������������������������������������������������������������������� 608


Exploring basic replication concepts ������������������������������������������������������������������������������ 609
Physical replication and WALs • 609
The wal_level directive • 610
Preparing the environment setup for streaming replication • 610
Managing streaming replication ������������������������������������������������������������������������������������� 612
Basic concepts of streaming replication • 612
Asynchronous replication environment • 614
The wal_keep_segments option • 615
The slot way • 616
The pg_basebackup command • 616
Asynchronous replication • 617
Replica monitoring • 619
Table of Contents xxiii

Synchronous replication • 620


PostgreSQL settings • 621
Cascading replication • 623
Delayed replication • 626
Promoting a replica server to a primary • 626
Summary ������������������������������������������������������������������������������������������������������������������������ 627
Verify your knowledge ���������������������������������������������������������������������������������������������������� 628
References ����������������������������������������������������������������������������������������������������������������������� 628

Chapter 18: Logical Replication  631

Technical requirements ��������������������������������������������������������������������������������������������������� 631


Understanding the basic concepts of logical replication ������������������������������������������������� 632
Comparing logical replication and physical replication �������������������������������������������������� 635
Exploring a logical replication setup and new logical replication features on PostgreSQL 16 �
636
Logical replication environment settings • 636
The replica role • 637
Primary server – postgresql.conf • 637
Replica server – postgresql.conf • 638
The pg_hba.conf file • 639
Logical replication setup • 639
Monitoring logical replication • 641
Read-only versus write-allowed • 643
DDL commands • 649
Disabling logical replication • 651
Making a logical replication using a physical replication instance • 652
Summary ������������������������������������������������������������������������������������������������������������������������ 657
Verify your knowledge ���������������������������������������������������������������������������������������������������� 658
References ����������������������������������������������������������������������������������������������������������������������� 658
xxiv Table of Contents

Chapter 19: Useful Tools and Extensions  661

Technical requirements �������������������������������������������������������������������������������������������������� 662


Exploring the pg_trgm extension ������������������������������������������������������������������������������������ 662
Using foreign data wrappers and the postgres_fdw extension ���������������������������������������� 665
Disaster recovery with pgbackrest ���������������������������������������������������������������������������������� 667
Basic concepts • 668
Environment set up • 669
The exchange of public keys • 669
Installing pgbackrest • 671
Configuring pgbackrest • 672
The repository configuration • 672
Using pgbackrest with object store support • 675
The PostgreSQL server configuration • 675
The postgresql.conf file ��������������������������������������������������������������������������������������������������� 675
The pgbackrest.conf file �������������������������������������������������������������������������������������������������� 676
Creating and managing continuous backups • 677
Creating the stanza • 677
Checking the stanza • 677
Managing base backups • 678
Managing PITR • 681
Migrating from MySQL/MariaDB to PostgreSQL using pgloader ������������������������������������ 684
Summary ����������������������������������������������������������������������������������������������������������������������� 688
Verify your knowledge ��������������������������������������������������������������������������������������������������� 688
References ����������������������������������������������������������������������������������������������������������������������� 689

Other Books You May Enjoy  691

Index 697
Random documents with unrelated
content Scribd suggests to you:
CHAPTER XXX
ENDERBY CASTLE

There were two spacious open barouches and one large wagon.
“My lord ordered me, sir, if the weather should be fine, to bring the
barouches for the ladies, as they would be so much pleasanter,” the
man explained, touching his hat, as he held the door of the first
carriage open for Mrs. Force.
The travelers were soon seated—Mr. and Mrs. Force, Wynnette
and Elva in the first barouche, Le, Odalite and Rosemary in the
second, and the two servants, with the dog and the luggage, in the
wagon.
“Oh, how jolly!” exclaimed Wynnette, looking about her.
By this time it was light enough to see their surroundings—the
hoary cliffs and the picturesque fishing village on their right; the far-
spread rocky beach, with the fishing boats drawn up, on their left;
the expanse of ocean beyond, dotted at long distances with sails; and
right near them the only street of the hamlet that ran from the beach
up through a natural cleft in the rocks, and looked something like a
rude, broad staircase of flagstones, which were paved on edge to
afford a hold to horses’ feet in climbing up the steep ascent.
By this time, too, the denizens of the village were out before their
doors to stare at the unusual sight of three carriages and a large party
of visitors for Enderby Castle.
For, of course, as his lordship’s carriages and liveried servants
were there to meet the party of travelers, they must be visitors to the
castle.
The men took off their hats and the women courtesied as the open
carriages passed slowly up the steep street to the top of the cliff,
where it joined the road leading northward along the sea toward
Enderby Castle.
Now the travelers in the open carriages had a grand view of land
and water.
On the east, moorland rolling into hills in the mid distance and
rising into mountains on the far horizon. The newly risen sun shining
above them and tinting all their tops with the soft and varied hues of
the opal stone. Here and there at long distances could be seen the
ruined tower of some ancient stronghold, or the roof and chimneys
of some old farmstead. Everything looked old or ancient on this wild
coast of Cumberland.
On the west the ocean rolled out until lost to view in the mists of
the horizon.
Before them northward the road stretched for many a mile.
Far ahead they saw a mighty promontory stretching out to sea. At
its base the waves dashed, leaped, roared, tumbled like raging wild
beasts clawing at the rocks. On the extreme edge of its point arose a
mass of gray stone buildings scarcely to be distinguished from the
foundation on which they were built.
“How far is it to Enderby Castle?” inquired Mr. Force of the
coachman who drove his carriage.
“Ten miles from the station, sir,” replied the man, touching his hat.
“That is the castle,” said Mrs. Force, pointing to the pile of
buildings on the edge of the promontory, and handing the field glass
with which she had been taking a view of her birthplace and first
home.
“That! It is a fine, commanding situation, but it scarcely looks to be
more than five miles from here.”
“It is not, if we could take a bee line over land and sea, but the road
has to follow the bend of the estuary,” replied the lady.
All the occupants of both carriages, which had come to a standstill,
were now on their feet gazing at that hoary headland, capped with its
ancient stronghold.
The field glass was passed from one to another, while the carriages
paused long enough for all to take a view.
“So that was the home of my grandparents and of our forefathers
for—how long, dear mamma?” inquired Odalite.
“Eight centuries, my dear. The round tower that you see is the
oldest part of the edifice, and was built by Kedrik of Enderbee in the
year 950.”
“Lord, what a fine time the rats, mice, bats, owls, rooks and ghosts
must have in it!” remarked Wynnette.
“It is like a picture in a Christmas ghost story,” said Elva.
“It seems like Aunt Sukey was reading it all to me out of a novel by
the evening fire at Grove Hill,” mused Rosemary.
“Go on,” said Mr. Force.
And the carriages started again.
The road, still running along the top of the cliff, turned gradually
more and more to the left until its course verged from the north to
the northwest, and then to the west, as it entered upon the long, high
point of land upon which stood the castle. The road now began to
ascend another steep, paved with stones on edge to make a hold for
the horses’ feet in climbing, and at length entered a sort of alley
between huge stone walls that rose higher and higher on either side
as the road ascended, until it reached a heavy gateway flanked with
towers, between which, and over the gateway, hung the spiked and
rusting iron portcullis, looking as if it were ready, at the touch of a
spring, to fall and impale any audacious intruder who might pass
beneath it. But it was fast rusted into its place, where it had been
stationary for ages.
“I wonder who was the last warder that raised this portcullis?”
mused Wynnette.
“I cannot tell you, my dear. It has not been moved in the memory
of man,” replied Mrs. Force.
“I see ghosts again!” exclaimed Wynnette—“men-at-arms on
yonder battlements! Knights, squires and pursuivants in the
courtyard here! Oh, what a haunted hole is this!”
They entered a quadrangular courtyard paved with flagstones,
inclosed by stone buildings, and having at each of the four corners a
strong tower.
The front building, through which they had passed by the
ascending road, was the most ancient part of the castle and faced the
sea. But in the rear of that was the more recent structure, used as the
dwelling of the earl and his household. This modern building also
faced the sea, on the other side, but it could not be approached from
the cliff road except through the front. These buildings were not used
at all. They were given over to the denizens objected to by Wynnette
—to rats, mice, bats, owls and rooks, and—perhaps ghosts.
On either side the buildings were used as quarters for the servants
and offices for the household.
They drove through the courtyard, under an archway in the wall of
the modern building, and out to the front entrance, facing the open
sea.
Many steps led from the pavement up to the massive oaken doors,
flanked by huge pillars of stone, that gave admittance to the building.
The coachman left his box, went up these stairs and knocked.
The double doors swung open.
Mr. Force alighted and handed out his wife and two elder
daughters, while Le performed the same service for Elva and
Rosemary, and the party walked up the stairs to the open door.
A footman in the gray livery of Enderby bowed them in.
CHAPTER XXXI
MRS. FORCE’S BROTHER

A tall, fair, delicate-looking patrician of about forty years of age,


clothed in an India silk dressing gown, leaning on the arm of his
gray-haired valet, and further supporting himself by a gold-headed
cane, approached to welcome them.
“My sister—I am glad to see you, Elfrida,” he said, passing his cane
over to his valet and taking the lady by the hand to give her his
brotherly kiss. “Now present me to your husband and daughters, and
to these—young friends of yours. I am glad to see them all. Very
glad.”
Mrs. Force introduced Mr. Force, Leonidas and the girls in turn.
Lord Enderby shook hands with each in succession, and heartily
welcomed them all to Enderby.
“You must take your place at the head of my bachelor household,
Elfrida. In the meantime, my housekeeper, Mrs. Kelsy here, will
show you to your rooms.”
As he spoke, an elderly woman, in her Sunday dress of black silk,
with a white net shoulder shawl and a white net cap, came from the
rear of the hall, courtesied, and said:
“My lady, this way, if you please.”
“Breakfast will be served as soon as you are ready for it, Elfrida,”
said the host, as, still leaning on the arm of his valet and supporting
himself by his cane, he turned and passed through a door on the
right, into his own sanctum.
Widely yawned the foot of the broad staircase, up which Mrs. Kelsy
led the guests of the house, to a vast upper hall, flanked with oaken
doors leading into a suit of apartments on either side.
The housekeeper opened a door on the right, saying:
“Here is a suit of five rooms, my lady, fitted up for yourself and the
young ladies. And here, on the opposite side, is a large room, with
dressing room attached, for the young gentlemen—Good Lord!!”
This sudden exclamation from the housekeeper was called forth by
the unexpected apparition of Gipsy, the negro maid, than whom no
blacker human being ever saw the light. Gipsy was as black as ink, as
black as ebony. Wynnette declared that charcoal made a light-
colored mark on her. But aside from her complexion, Gipsy was a
good-looking girl, with laughing black eyes, and laughing lips that
disclosed fine white teeth.
“This is my maid, Zipporah, but we call her Gipsy for
convenience,” said Mrs. Force.
“Oh, my lady! Will it bite? Can’t it talk? Is it vicious?” inquired the
Cumberland woman, who had never seen and scarcely ever heard of
a negro, and had the vaguest idea of dark-colored savages in distant
parts of the world, who were pagans and cannibals.
“She is a very good girl, and can read and write as well as any of us;
and she is, besides, a member of the Episcopal church at home,
which is the same as your Church of England here,” Mrs. Force
explained.
“Yes, my lady. Certainly, my lady. I beg pardon, my lady, I am
sure,” said the housekeeper, in profuse apology; but still she did not
seem satisfied, but gave Gipsy a wide berth while she eyed her
suspiciously.
Now Gipsy resented this sort of treatment; besides, she was a bit of
a wag; so every time her mistress’ back was turned she rolled up the
whites of her big eyes, curled up her large red lips, and snapped her
teeth together, in a way that made Kelsy’s blood run cold.
As soon as it was possible to do so, she made an excuse and left the
room.
“Where is Dickon?” inquired Mr. Force.
“He’s round at the kennel with the dog. Joshua won’t make friends
’long o’ none of the grooms, nor likewise none o’ the doogs, so
Dickon have to stay ’long o’ him to keep him quiet,” said Gipsy.
Mr. Force groaned.
“Now everything is going to be laid on that poor dog! Gipsy, I
won’t give you my crimson silk dress when I have done with it, just
for that. Papa, I can help you to dress just as well as Dickon can—and
a great deal better, too. I can fix your shaving things and hair
brushes, and lay out your clothes myself!” exclaimed Wynnette.
“My dear, I think you had better prepare for breakfast,” said her
mother.
“Mother, we can’t do much preparing, as our trunks have not been
brought up.”
“Take off your duster, my dear, and wash your face and hands, and
brush your hair,” suggested Mrs. Force.
“I suppose these two rooms are yours and papa’s, but which are
ours?”
Mrs. Force walked through the whole suit, and finally assigned a
room next to her own to Wynnette and Odalite, and another to Elva
and Rosemary.
What struck all these visitors was the heavy and rather gloomy
character of their apartments. Thick Brussels carpets, thick moreen
window curtains, and bed curtains of dull colors and dingy
appearance, massive bedsteads, bureaus, presses and chairs.
“And they call this the modern part of the castle! Oh, I know I shall
see ghosts!” said Wynnette.
When they were all ready, they went downstairs to the hall, all
hung with suits of armor, and decorated with arms, shields, spears,
banners, battle-axes, and so on, and with stags’ heads and other
trophies of the battlefield and the chase.
Here a footman showed them into the breakfast room, where the
earl sat waiting for them. Breakfast was served in a very few minutes.
After breakfast the whole party adjourned to the drawing room, a
vast, gloomy apartment with walls lined with old oil paintings,
windows hung with heavy, dark curtains; floor covered with a thick,
dull carpet, and filled up with massive furniture.
After they had been seated for a while, the earl arose, taking his
cane in one hand and the arm of his brother-in-law with the other,
and said:
“I hope you will amuse yourselves as you please, my dears, and
excuse me: I wish to have a talk on family matters with your parents
in the library. If you would like to go over the house, call one of the
maids or the housekeeper to be your guide,” he concluded, as he left
the room, accompanied by Mr. and Mrs. Force.
Odalite acted on her uncle’s suggestion, rang the bell, and
requested to see the housekeeper.
Mrs. Kelsy came, and on being requested, expressed her
willingness to show the young ladies over the house.
“And to the picture gallery first, if you please,” she said, as she led
the way across the hall to a long room on the opposite side.
Here were the family portraits.
“Odalite, here are the originals of all the ghosts I saw with my eyes
shut, on last night’s journey, and of all the ghosts I saw here on the
battlements and in the courtyard—all, all, all—men-at-arms, squires,
knights, lords and ladies. If they would but talk, what interesting
shades they would be!”
“Which, Wynnette? The ghosts or the pictures?”
“Either. Both. This, you say, Mrs. Kelsy, was Elfrida, Lady
Enderby, my mother’s mother? Why, I should have known it. How
much she is like my mother, and like Elva. And this is the second and
last Lady Enderby? How lovely, yet how fragile. She was mamma’s
stepmother, and she died young, leaving one delicate little boy, our
uncle, the present earl. Sic transit, and so forth.”
They spent an hour in the picture gallery, and then the
housekeeper proposed that they go into the library.
“But we cannot go there. Papa, mamma and uncle are shut up
there, in close council,” said Odalite.
“Ah! Well, we will go upstairs, if you please, miss,” said Kelsy.
And upstairs they went. And all over the vast building they went,
finding only gloomy rooms, each one more depressing than the
others.
“And now show me the room Queen Elizabeth slept in when on a
visit to Baron Ealon, of Enderby,” said Wynnette.
“Queen Elizabeth, miss! I never heard that Queen Elizabeth was
ever in this part of the country!” the housekeeper exclaimed.
Wynnette laughed.
“Oh, well, then,” she said, “show me the room that Alexander the
Great, or Julius Cæsar, or Napoleon Bonaparte, or George
Washington slept in.”
“I—do not think I ever heard of any of these grandees stopping at
Enderby. But there is a room——”
“Yes, yes!” eagerly exclaimed Wynnette.
“Where the Young Pretender was hidden for days before he
escaped to France,” said the housekeeper.
“Oh, show us that room, Mrs. Kelsy,” said a chorus of voices.
The housekeeper took them down a long flight of stairs and along a
dark passage, and up another flight of stairs, and through a suit of
unfurnished apartments, to a large room in the rear of the main
building, whose black oak floor and whose paneled walls were bare,
and whose windows were curtainless.
In the middle of this room stood a huge bedstead, whose four posts
were the dragon supporters of the arms of Enderby and whose
canopy was surmounted by an earl’s coronet. The velvet hangings of
this bedstead, the brocade quilt and satin pillow cases had almost
gone the way of all perishable things.
“And the Young Pretender occupied this room?” inquired
Rosemary, reverently.
“Yes, miss, and it is kept just as he left it, except that the curtains
have been taken from the windows, because they had fallen into
rags.”
“And he slept in this bed?” said Elva, timidly laying her hand upon
the sacred relic.
“Yes, miss, but I wouldn’t touch the quilt, if I was you. Bless you, it
would go to pieces if you were to handle it!”
“I would make a bonfire of every unhealthy mess in this room, if it
were mine!” said Wynnette.
The housekeeper looked at her in silent horror.
They lingered some time in “the pretender’s room.”
As they were leaving it, Wynnette said, at random:
“And now show us the haunted chamber, please.”
The housekeeper stopped short, turned pale and stared at the
speaker.
“Who told you anything about the haunted room?” she inquired.
“Nobody did,” replied Wynnette, staring in her turn.
“How, then, did you know anything about it?”
“By inference. Given an old castle, inferred a haunted room. Come,
now, show it to us, dear Mrs. Kelsy.”
“No, you cannot see the haunted chamber, young miss. It has not
been opened for ten years or more.”
“Come! This is getting to be exciting, and I declare I will see it, if I
die for it,” said Wynnette.
“Not through my means, you will not, young lady. But there is the
luncheon bell, and we had better go down.”
They returned to the inhabited parts of the house, and were shown
by the housekeeper to the morning room, where the luncheon table
was spread.
There they found Mr. and Mrs. Force. Their host had not yet
joined them.
“My dear,” said Mr. Force, in a low voice, addressing Odalite, “we
have had a consultation in the library. It is almost certain that Lady
Mary Anglesea died one year before the time stated as that of her
death. It is best, however, that we go down to Angleton and search
for evidence in the church and mausoleum. Therefore, it is decided
that Leonidas and myself go to Lancashire to-morrow to investigate
the facts, leaving your mother, sisters, and self here. We shall only be
absent for a few days.”
“Oh, papa! then you will take poor John Kirby’s letter and parcel to
his old father there? You see, they live only a few miles from
Angleton,” said Wynnette.
“Yes, dear, I will take them,” assented the squire. “And, Odalite,
my love,” he added, turning to his eldest daughter, “if all goes well we
shall have a merry marriage here at Enderby.”
CHAPTER XXXII
AN ANXIOUS SEARCH

Early the next morning Mr. Force, Leonidas and Wynnette, who
begged to make one of the party, left Enderby Castle for Lancashire.
The gray-haired coachman drove them in an open carriage to the
Nethermost Railway Station.
On this drive they retraced the road on the top of the cliffs which
they had traversed on the previous day.
They reached Nethermost just in time to jump on board the
“parliamentary,” a slow train—none but slow trains ever did stop at
this obscure and unfrequented station.
Mr. Force secured a first-class compartment for himself and party,
and they were soon comfortably seated and being whirled onward
toward Lancaster.
For some miles the road followed the line of the coast in a
southerly direction, and then diverged a little to the eastward until it
reached the ancient and picturesque town of Lancaster, perched
upon its own hill and crowned with its old castle, which dates back to
the time of John of Gaunt.
Here they left their train, and on consulting the local time-table in
the ticket office found that the next train on the branch line going to
the station nearest Angleton did not start until 3 P.M.
This, as it was now but 11 A.M., gave the party an opportunity of
seeing the town, as well as of getting a luncheon.
A chorus of voices offered cabs; but Mr. Force, waving them all
away, walked up the street of antiquated houses and brought his
party to the ancient inn of “The Royal Oak.”
Here he ordered luncheon, to be ready at two, and then set out
with his young people to walk through the town.
They climbed the hill and viewed the castle, now fallen from its
ancient glory of a royal fortress—not into ruin, but into deeper
degradation as the county jail. But the donjon keep, King John’s
Tower, and John of Gaunt’s Gate remain as of old.
They next visited the old parish church of St. Mary’s, where they
saw some wonderful stained glass windows, brass statuary, and oak
carvings of a date to which the memory of man reached not back.
They could only gaze upon the outside of the cotton and silk
factories and the iron foundries before the clock in the church tower
struck two, and they returned to the hotel for lunch.
At three o’clock they took the train for Angleton.
Their course now lay eastward through many a mile of the
manufacturing districts, and then entered a moorland, waste and
sparsely inhabited, stretching eastward to the range of mountains
known in local phraseology as “England’s Backbone.”
It was six o’clock on a warm June afternoon when the slow train
stopped at a little, lonely station, in the midst of a moor, where there
was not another house anywhere in sight.
Here our travelers left their compartment and came out upon the
platform, carpetbags in hand; and the train went on its way.
Our party paused on the platform, looking about them.
On their right hand stood the station, a small, strong building of
stone with two rooms and a ticket office. Behind that the moor
stretched out in unbroken solitude to the horizon.
On their left hand was the track of the railroad, and beyond that
the moor rolling into low hills, toward the distant range of
mountains.
There was not a vehicle of any sort in sight; and there were but two
human beings besides themselves on the spot—one was the ticket
agent and the other the railway porter.
Mr. Force spoke to the latter.
“Where can I get a carriage to take my party on to Angleton?”
The man, a red, shock-haired rustic, stared at the questioner a
minute before answering.
“Noa whurr, maister, leaf it be at t’ Whoit Coo.”
“And where is the White Cow?” inquired the gentleman.
The rustic stretched his arm out and pointed due east.
Mr. Force strained his eyes in that direction, but at first could see
nothing but the moor stretching out in the distance and rolling into
hills as it reached the range of mountains.
“Papa,” said Wynnette, who was straining her eyes also, “I think I
see the place. I know I see a curl of smoke and the top of a chimney,
and the peak of a gable-end roof. I think the rise of the ground
prevents our seeing more.”
“Oie, oie, yon’s t’ Whoit Coo,” assented the porter.
“How far is it from here?” inquired Mr. Force.
“Taw mulls, maister.”
“Can you go there and bring us a carriage of some sort? I will pay
you well for your trouble,” said Mr. Force.
“Naw, maister. Oi’ mawn’t leave t’ stution.”
“Uncle!” exclaimed Le, “I can go and bring you a carriage in no
time. You take Wynnette into the house and wait for me.”
And without more ado Le ran across the track and strode off across
the moor.
Mr. Force took Wynnette into the waiting room of the little
wayside station, where they sat down.
There was no carpet on the floor, no paper on the walls, no shades
at the windows, but against the walls were rows of wooden benches,
and on them large posters of railway and steamboat routes, hotels,
watering places, and so forth, and one picture of the winner of the
last Derby.
They had scarcely time to get tired of waiting before Le came back
with the most wretched-looking turnout that ever tried to be a useful
conveyance.
It was a long cart covered with faded and torn black leather, and
furnished with wooden seats without cushions. Its harness was worn
and patched. But there was one comfort in the whole equipage—the
horse was in very good condition. It was a strong draught horse.
“I shall not have to cry for cruelty to animals, at any rate,” said
Wynnette, as her father helped her up into a seat.
“How far is it to Angleton?” inquired Mr. Force of the driver.
“Sux mulls, surr,” answered the man. “Sux mulls, if yur tek it cross
t’ moor, but tun, ’round b’ t’ rood.”
“Is it very rough across the moor?” inquired Mr. Force.
“Muddlin’, maister,” replied the man.
“Go across the moor,” said the gentleman, as he stepped up into
the carriage.
Le followed him. The horse started and trudged on, jolting them
over the irons on the railway track and striking into the very worst
country road they had ever known.
Yes. It was rough riding across that moor, sitting on hard benches,
in a cart without springs, and drawn by a strong, hard-trotting horse.
Our travelers were jolted until their bones were sore before they
reached the first stopping place.
This was “‘The White Cow,” an old-fashioned inn, in a dip of the
moor, where the ground began to roll in hills and hollows toward the
distant mountains.
The house fronted east, and, as it lay basking in the late afternoon
summer sun, was very picturesque. Its steep, gable roof was of red
tiles, with tall, twisted chimneys, and projecting dormer windows; its
walls were of some dark, gray stone, with broad windows and doors,
and a great archway leading into the stable yard. A staff, with a
swinging sign, stood before the door.
The declining sun threw the shadow of the house in front of it; and
in this shade a pair of country laborers sat on a bench, with a table
before them. They were smoking short pipes and drinking beer,
which stood in pewter pots on the board.
This was the only sign of life and business about the still place.
As the cart drew up Mr. Force got out of it and helped his daughter
to alight.
Le followed them.
“I think we will go in the house and rest a while, and see if we can
get a decent cup of tea, my dear. We have had nothing since we left
Lancaster, at three o’clock, and it is now half-past seven. You must be
both tired and hungry,” said the squire, leading her in.
“‘I’m killed, sire,’”
responded Wynnette, misapplying a line from Browning, as she
limped along on her father’s arm.
The man who had driven them from the railway station, and whom
after developments proved to be waiter, hostler, groom and
bootblack rolled into one for the guests of the White Cow, left his
horse and cart standing and ran before Mr. Force to show the
travelers into the house.
It was needless; but he did it.
They entered a broad hall paved with flagstones.
On the left of this an open door revealed the taproom, half full of
rustic workingmen, who were smoking, drinking, laughing and
talking, and whose forms loomed indistinctly through the thick
smoke, tinted in one corner like a golden mist by the horizontal rays
of the setting sun that streamed obliquely through the end window.
On the right another open door revealed a large low-ceiled parlor,
with whitewashed walls and sanded floor, a broad window in front
filled with flowering plants in pots, and a broad fireplace at the back
filled with evergreen boughs and cut paper flowers. On the walls
were cheap colored pictures, purporting to be portraits of the queen
and members of the royal family. Against the walls were ranged
Windsor chairs. On the mantelpiece stood an eight-day clock,
flanked by a pair of sperm candles, in brass candlesticks.
In the middle of the floor stood a square table, covered with a
damask cloth as white as new fallen snow, and so smooth and glossy,
with such sharp lines where it had been folded, that proved it to have
been just taken from the linen press and spread upon the table.
The house might be old-fashioned and somewhat dilapidated, not
to say tumble-down, as to its outward appearance; but this large,
low-ceiled room was clean, neat, fresh and fragrant as it was possible
for a room to be.
“This is pleasant, isn’t it, papa?” said Wynnette, as she stood by the
flowery window, threw off her brown straw hat, pulled off her gloves,
drew off her duster, put them all upon one chair and dropped herself
into another.
“Yes. If the tea proves as good as the room, we shall be content,”
replied Mr. Force.
The man-of-all-work, who had slipped out and put on a clean
apron, and taken up a clean towel, with magical expedition, now
reappeared to take orders.
“What would you please to have, sir?”
“Tea for the party, and anything else you have in the house that is
good to eat with it.”
“Yes, sir.”
And the waiter pulled the white tablecloth this way and that and
smoothed it with the palms of his hands, apparently for no other
reason than to prove his zeal, for he did not improve the cloth.
Mr. Force and Le walked out “to look around,” they said.
CHAPTER XXXIII
A CLEW

The one maid-of-all-work came in and asked the young lady if she
would not like to go to a room and wash her face and hands.
Wynnette decidedly would like it, and said so.
The girl was a fresh, wholesome-looking English lass, with rosy
cheeks and rippling red hair. She wore a dark blue dress of some
cheap woolen material, with a white apron and white collar.
She led the young lady out into the hall again, and up a flight of
broad stone steps to an upper hall, and thence into a front bed
chamber, immediately over the parlor.
Here again were the whitewashed walls, clean bare floor, the
broad, white-shaded window, the open fireplace filled with
evergreens, the polished wooden chairs, ranged along the walls, and
all the dainty neatness of the room below. There were, besides, a
white-curtained bed, with a strip of carpet on each side of it; a white-
draped dressing table with an oval glass, and a white-covered
washstand, with white china basin and ewer. In a word, it was a pure,
fresh, dainty, and fragrant white room.
“Oh, what a nice place! Oh, how I should like to stay here to-night,
instead of going further!” exclaimed Wynnette, appreciatively.
The girl made no reply, but began to lay out towels on the
washstand, and to pour water from the ewer into the basin.
“This is a very lonesome country, though, isn’t it?” inquired
Wynnette, who was bound to talk.
“There’s not a many gentry, ma’am. There be mill hands and
pitmen mostly about here,” said the girl.
“Mill hands and pitmen! I saw no mills nor mines, either, as we
drove along.”
“No, ma’am; but they beant far off. The hills do hide them just
about here; but you might seen the high chimneys—I mean the tops
of ’em and the smoke.”
“Are they pitmen down there in the barroom?”
“In the taproom? Yes, ma’am. Mill hands, and farm hands, too.
They do come in at this hour for their beer and ’bacco.”
“Do you have many more customers besides these men?”
“Not ivery day, ma’am; but we hev the farmers on their way to
Middlemoor market stop here; and—and the gentry coming and
going betwixt the station and Fell Hall, or Middlemoor Court, or
Anglewood Manor, ma’am.”
“How far is Anglewood Manor from this?”
“About five miles, ma’am.”
“‘Five!’ Why, I thought it wasn’t more than four. The coachman
told us it was only six from the station and we have come two.”
“That was Anglewood village, I reckon, ma’am. That is only four
miles from here; but Anglewood Manor is a short mile beyant that.”
“Ah! Who keeps this inn? There is no name on the sign.”
“No, ma’am. It’s ‘T’ Whoit Coo.’ It allers hev been ‘T’ Whoit Coo,’
ma’am.”
“But who keeps it?” persisted inquisitive Wynnette.
“Oo! Me mawther keeps it, iver sin’ feyther deed, ma’am. Mawther
tends bar hersen, and Jonah waits and waters horses, and cleans
boots, and does odd jobs, and I be chambermaid.”
“Ah! and who is Jonah?”
“Me brawther.”
“Ah! And so your mother, your brother, and yourself do all the
work and run the hotel?”
“Yes, ma’am. It would no pay us else,” replied the “Maid of the
Inn,” who seemed to be as much inclined to be communicative as
Wynnette was to be inquisitive.
“Oh, well, it is lucky that you are all able to do so. But you have not
told me your name yet.”
“Mine be Hetty Kirby, ma’am. Brawther Jonah’s be Jonah, and
mawther’s be the Widow Kirby,” definitely replied the girl.
“‘Kirby!’ Oh—why——Tell me, did you have a relation named John
Kirby go to America once upon a time?”
“Yes, ma’am, a long time ago, before I can remember, me Oncle
John Kirby, me feyther’s yo’ngest brawther, went there and never
come back.”
“Oh! And—is your grandfather living?”
The “Maid of the Inn” stared. What was all this to the young lady?
Wynnette interpreted her look and explained:
“Because, if he is living, I have got a letter and a bundle for him
from his son in New York.”
“Oh, Law! hev you, though, ma’am? Look at thet, noo! What
wonders in this world. The grandfeyther is living, ma’am, but not in
Moorton. He be lately coom to dwell wi’ ‘is son Job, me Oncle Job,
who be sexton at Anglewood church.”
“Sexton at Anglewood church! Is your uncle sexton at Anglewood
church? And does your grandfather, old Mr. Kirby, live with him?”
The maid of the inn stared again. Why should this strange young
lady take so much interest in the Kirbys?
Again Wynnette interpreted her look, and explained:
“Because if your grandfather does live there, it will save us a
journey to Moorton, as we are going to Anglewood, and can give him
the letter and parcel without turning out of our way,” she said; but
she was also thinking that if this old Kirby, to whom she was bringing
letters and presents from his son in America, was the father of the
sexton at Anglewood church, an inmate of his cottage, and probably
assistant in his work, these circumstances might greatly facilitate
their admission into vaults and mausoleums which the party had
come to see, but which might otherwise have been closed to them.
“Oh, ma’am,” said Hetty, “would you mind letting mawther see the
letter and parcel?”
“No, certainly not; but I have no right to let her open either of
them, you know.”
“She shawnt, ma’am; but it wull do the mawther good to see the
outside ’n ’em. And o’ Sunday, when she goes to church, she can see
the grandfeyther, and get to read t’ letter. And there be t’ bell, ma’am.
And we mun goo doon to tea.”
Wynnette was ready, and went downstairs, attended by the girl.
A dainty and delicious repast was spread upon the table. Tea,
whose rich aroma filled the room and proved its excellence, muffins,
sally-lunns, biscuits, buttered toast, rich milk, cream and butter,
fried chicken, poached eggs, sliced tongue and ham, radishes, pepper
grass, cheese, marmalade, jelly, pound cake and plum cake.
Wynnette’s eyes danced as she saw the feast.
“It is as good as a St. Mary’s county spread! And I couldn’t say
more for it if I were to talk all day!” she exclaimed, as she took her
place at the head of the table to pour out the tea.
Mr. Force asked a blessing, just as he would have done if he had
been at home, and then the three hungry travelers “fell to.”
“Father,” said Wynnette, when she had poured out the tea, which
Hetty began to hand around, “do you know the Widow Kirby who
keeps this hotel——”
“Inn, my dear—inn,” amended the squire. “I am so happy to find
myself in an old-fashioned inn that I protest against its being
insulted with the name of hotel.”
“All right, squire,” said Wynnette.
“‘A sweet by any other smell would name as rose,’

or words to that effect. The landlady of this hostelry—I should say


tavern—I mean inn—the landlady of this inn is the Widow Kirby,
sister-in-law to the baggage master who took care of Joshua, and
from whom we brought the letter and parcel, you know. And this
young person is his niece, and the man who drove us here is his
nephew. And his brother is sexton at Anglewood Church, and his
father lives there. Now! What do you think of that?”
“We knew from the baggage master that the Kirbys lived in
Lancashire, so we need not be surprised to find them here.”
“But, papa, Lancashire is a large place.”
“My love, it has been said that the habitable globe is but a small
place, and we are always sure to meet some of the same people
everywhere.”

You might also like