PostgreSQL Configuration: Best Practices for Performance and Security 9781484256626, 148425662X

Obtain all the skills you need to configure and manage a PostgreSQL database. In this book you will begin by installing

361 122 2MB

English Pages 244 [234]

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Table of Contents
About the Author
About the Technical Reviewer
Chapter 1: Best Ways to Install PostgreSQL
Information Needed for Installation
Types of Installations
Source Installation
Binary Installation
RPM Installation
One-Click Installers for Linux, Windows, and Mac
Plan for the Installation
General Recommendations for PostgreSQL Disk/Storage
Choose the Right Location and Ownership
One Cluster and Database per Server
FileSystem Layouts
Data Cluster Separation
WAL Files Separation
Log Files Separation
Temp Files Separation
Tablespaces
Tuning OS Parameters
Before Installation
After Installation
Troubleshooting Installation Issues
Summary
Chapter 2: Configure Your Database for Better Performance
Initial Steps After Installation
For PostgreSQL Developers
For Administrators
Configuration Files and Recommendations
postgresql.conf
pg_hba.conf
pg_ident.conf
Parameter Recommendations
The Types of Settings
When They Take Effect
Tuning Tools
Review Parameters
Connections Related
listen_addresses
max_connections
Memory Related
shared_buffers
effective_cache_size
work_mem
maintenance_work_mem
Planner/Cost Related
seq_page_cost
random_page_cost
cpu_tuple_cost
WAL Related
wal_buffers
wal_level
bgwriter_delay
bgwriter_lru_maxpages
bgwriter_lru_multiplier
synchronous_commit
fsync
effective_io_concurrency
checkpoint_segments
checkpoint_timeout
checkpoint_completion_target
checkpoint_warning
Autovacuum Related
autovacuum
autovacuum_max_workers
autovacuum_naptime
autovacuum_vacuum_threshold / autovacuum_analyze_threshold
autovacuum_vacuum_scale_factor / autovacuum_analyze_scale_factor
autovacuum_vacuum_cost_delay
Logging Related
Replication Related
max_wal_senders
max_replication_slots
max_worker_processes
max_logical_worker_processes
max_sync_workers_per_subscription
OS Recommendations
Why Allow Overcommits?
Overcommit Strategy 0
Overcommit Strategy 1
Overcommit Strategy 2
vm.dirty_ratio
vm.dirty_background_ratio
THP
Hugepages
Summary
Chapter 3: User Management and Securing Databases
Information That You Need to Know
Security Mechanisms
Authentication in HBA
PASSWORD
MD5
SCRAM
TRUST
REJECT
PEER and IDENT
LDAP
HOSTSSL
ACLs
Available Privileges
Transactional DDLs
Alter Default Privileges
Roles and Groups
Column Level ACLs
Avoid Public Schema
Read-Only Roles
RLS (Row Level Security)
SSL
Tunneling
Event Trigger
Auditing
Monitoring Roles
Encryption and PCI
Performance Impact
Backups
Volumes
Instance Level
Replication
PL Trusted vs. Untrusted
High Security and Encryption Guidelines
Summary
Chapter 4: Backup and Restore Best Practices
Purpose of Backing Up a Database
Gather Information to Set Up a Backup Strategy
Backup Types
Logical Backups
How to Take Logical Backups
Physical Backups
How to Take a Base Backup
Backup Formats
What Needs to Be Backed Up?
pg_receivexlog/pg_receivewal
Backup Retention
Other Backup Tools
Barman
pgBackRest
Restore Your Database
Logical Backups
Restoring a Plain Dump File
Restoring Custom/tar Format Dump Files
Restore Physical Backups
Point-In-Time-Recovery
Design a Backup Strategy
Daily Backups
Weekly Backups
Monthly Backups
Yearly Backup
Monitoring Backups
Summary
Chapter 5: Enable Logging of Your Database and Monitoring PostgreSQL Instances
Why/When/How to Log
Parameters to Set for Logging
log_min_duration_statement
log_line_prefix
log_checkpoints
log_connections and log_disconnections
log_lock_waits
log_temp_files
log_autovacuum_min_duration
Monitoring Databases
Levels of Monitoring
OS Level Monitoring
CPU
Memory
IO
Network
Filesystem
Database Level Monitoring
Frequent Monitoring
Daily or Weekly Basis
Monitoring/Reporting Tools
pgBadger
pgCluu
sar
pg_buffercache
Summary
Chapter 6: Execute Maintenance
What is MVCC
MVCC in PostgreSQL
If the Row Is Deleted
If the Row Is Updated
Why/How—Maintenance Activities
Table and Index Bloat
AUTOVACUUM/VACUUM
What Does Autovacuum Do?
How Does Autovacuum Work?
What Else of Importance Can the Autovacuum Daemon Do?
Autovacuum Parameters
autovacuum
autovacuum_max_workers
autovacuum_naptime
autovacuum_vacuum_threshold / autovacuum_analyze_threshold
autovacuum_vacuum_scale_factor / autovacuum_analyze_scale_factor
autovacuum_vacuum_cost_delay
VACUUM Strategies
Manual VACUUM
Throttle VACUUM
Schedule
autovacuum IO
Index Fragmentation
Other Database Maintenance
Unused Indexes
Duplicate Indexes
Summary
Chapter 7: High Availability Procedures and Implementing a Pooler
Why High Availability?
Gather Information to Set Up HA
RPO and RTO
RPO (Recovery Point Objective)
RTO (Recovery Time Objective)
High Availability Solutions in Core PostgreSQL
Warm Standby/Log Shipping
Hot Standby
Streaming Replication
Cascading Replication
Warm/Hot Standby vs. Streaming Replication
Warm/Hot Standby
Streaming Replication
Simple HA Solution
Better HA Solution
Auto Failover Tools Available
auto-failover through repmgr
Installation
Setup
Configuration
Node Registration
Test Auto Failover
Replication Lag
Common Replication Issues
Why Connection Pooling
pgBouncer
Issues
pgpool-II
Summary
Chapter 8: Basic Errors and Handy Queries
Basic Errors of PostgreSQL
Connection Errors
Error
Cause/Resolution
Error
Cause/Resolution
Error
Cause/Resolution
Configuration Errors
Error
Cause/Resolution
Error
Cause/Resolution
Error
Cause/Resolution
Query Errors
Error
Cause/Resolution
Error
Cause/Resolution
Other Errors
Error
Cause/Resolution
Error
Cause/Resolution
Error
Cause/Resolution
Error
Cause/Resolution
Error
Cause/Resolution
Error
Cause/Resolution
Error
Cause/Resolution
Error
Cause/Resolution
Handy Queries of PostgreSQL
Basic Queries
To Check Version
To Check Size of Database
To Get All Catalog Tables
Monitoring Queries
Top 10 WRITE Tables
Top 10 READ Tables
Largest Tables in DB
DB Size
Table Size
Index Size
Index Utilization
Tables That Are Being Updated the Most and Looking for VACUUM
Bloated Index to Run Reindexing (Locking Operation)\pgrepack (Online Rebuilding)
Bloated Tables to Do Vacuumfull (Locking Operation)\pgrepack (Online Rebuilding)
Real-Time Bloated Tables
Get name and value from pg_settings
Never-Used Indexes
Age of DB and Tables
Duplicate Indexes
Blocked Queries
Slow Running Queries on DB from Last 5 Min
Delete Duplicate Values in a Table Using CTID (Pseudo Column)
Total Number of Transactions Executed in All Databases
Object Privileges Queries
Grant Privileges on All Tables
Check Privileges on Tables
Find All Functions with Arguments
Find Privileges of a User on Objects
Granting Privileges on All Procedures
Object Level Queries
Get List of All Tables and Their Row Count
Check Tables in Each User Defined Schema
Find Parameters Changes for a Table
Generate a Script to Change or Rename All Table Names to lower case
Generate a Script to Change or Rename All Columns of a Table
For Tables
For All Tables in a Schema
Find Primary Keys on Tables of a Schema
Find Sequences in a Schema
Find the Constraints
Find ForeignKeys
Find Parent for ForeignKey
Query to Find Sequence OWNED BY
Summary
Index

PostgreSQL Configuration: Best Practices for Performance and Security
 9781484256626, 148425662X

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers