- 416 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Mastering PostgreSQL 9.6
About This Book
Master the capabilities of PostgreSQL 9.6 to efficiently manage and maintain your databaseAbout This Book⢠Your one-stop guide to mastering the advanced concepts in PostgreSQL with ease⢠Master query optimization, replication, and high availability with PostgreSQL⢠Extend the functionalities of PostgreSQL to suit your organizational needs with minimum effortWho This Book Is ForIf you are a PostgreSQL data architect or an administrator who wants to understand how to implement advanced functionalities and master complex administrative tasks with PostgreSQL, then this book is perfect for you. Prior experience of administrating a PostgreSQL database and a working knowledge of SQL is required to make the best use of this book.What You Will Learn⢠Get to grips with the advanced features of PostgreSQL 9.6 and handle advanced SQL⢠Make use of the indexing features in PostgreSQL and fine-tune the performance of your queries⢠Work with the stored procedures and manage backup and recovery⢠Master the replication and failover techniques⢠Troubleshoot your PostgreSQL instance for solutions to the common and not-so-common problems⢠Learn how to migrate your database from MySQL and Oracle to PostgreSQL without any hassleIn DetailPostgreSQL is an open source database used for handling large datasets (Big Data) and as a JSON document database. It also has applications in the software and web domains. This book will enable you to build better PostgreSQL applications and administer databases more efficiently.We begin by explaining the advanced database design concepts in PostgreSQL 9.6, along with indexing and query optimization. You will also see how to work with event triggers and perform concurrent transactions and table partitioning, along with exploring SQL and server tuning. We will walk you through implementing advanced administrative tasks such as server maintenance and monitoring, replication, recovery and high availability, and much more. You will understand the common and not-so-common troubleshooting problems and how you can overcome them.By the end of this book, you will have an expert-level command of the advanced database functionalities and will be able to implement advanced administrative tasks with PostgreSQL.Style and ApproachThis book is a comprehensive guide covering all the concepts you need to master PostgreSQL. Packed with hands-on examples, tips and tricks, even the most advanced concepts are explained in a very easy-to-follow manner. Every chapter in the book does not only focus on how each task is performed, but also why.
Frequently asked questions
Information
Making Use of Indexes
- When does PostgreSQL use indexes?
- How does the optimizer handle things?
- What types of indexes are there and how do they work?
- Using your own indexing strategies
Understanding simple queries and the cost model
test=# CREATE TABLE t_test (id serial, name text);
CREATE TABLE
test=# INSERT INTO t_test (name) SELECT 'hans'
FROM generate_series(1, 2000000);
INSERT 0 2000000
test=# INSERT INTO t_test (name) SELECT 'paul'
FROM generate_series(1, 2000000);
INSERT 0 2000000
test=# SELECT name, count(*) FROM t_test GROUP BY 1;
name | count
------+---------
hans | 2000000
paul | 2000000
(2 rows)
test=# \timing
Timing is on.
test=# SELECT * FROM t_test WHERE id = 432332;
id | name
--------+------
432332 | hans
(1 row)
Time: 119.318 ms
Making use of EXPLAIN
test=# \h EXPLAIN
Command: EXPLAIN
Description: show the execution plan of a statement
Syntax:
EXPLAIN [ ( option [, ...] ) ] statement
EXPLAIN [ ANALYZE ] [ VERBOSE ] statement
where option can be one of:
ANALYZE [ boolean ]
VERBOSE [ boolean ]
COSTS [ boolean ]
BUFFERS [ boolean ]
TIMING [ boolean ]
FORMAT { TEXT | XML | JSON | YAML }
test=# EXPLAIN SELECT * FROM t_test WHERE id = 432332;
QUERY PLAN
---------------------------------------------------------------
Gather (cost=1000.00..43463.92 rows=1 width=9)
Workers Planned: 2
-> Parallel Seq Scan on t_test
(cost=0.00..42463.82 rows=1 width=9)
Filter: (id = 432332)
(4 rows)
- The parser will check for syntax errors and for obvious problems
- The rewrite system take care of rules (views and other things)
- The optimizer will figure out how to execute a query in the most efficient way and work out a plan
- The plan provided by the optimizer will be used by the executor to finally create the result
test=# SET max_parallel_workers_per_gather TO 0;
SET
Digging into the PostgreSQL cost model
test=# EXPLAIN SELECT * FROM t_test WHERE id = 43...
Table of contents
- Title Page
- Copyright
- Credits
- About the Author
- About the Reviewer
- www.PacktPub.com
- Customer Feedback
- Preface
- PostgreSQL Overview
- Understanding Transactions and Locking
- Making Use of Indexes
- Handling Advanced SQL
- Log Files and System Statistics
- Optimizing Queries for Good Performance
- Writing Stored Procedures
- Managing PostgreSQL Security
- Handling Backup and Recovery
- Making Sense of Backups and Replication
- Deciding on Useful Extensions
- Troubleshooting PostgreSQL
- Migrating to PostgreSQL