Mastering PostgreSQL 10
Hans-Jurgen Schonig
- 428 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Mastering PostgreSQL 10
Hans-Jurgen Schonig
About This Book
Master the capabilities of PostgreSQL 10 to efficiently manage and maintain your databaseAbout This Book• Your one-stop guide to mastering advanced concepts in PostgreSQL 10 with ease• Master query optimization, replication, and high availability with PostgreSQL • Extend the functionalities of your PostgreSQL instance to suit your organizational needs with minimal effortWho This Book Is ForIf you are a PostgreSQL data architect or an administrator and want to understand how to implement advanced functionalities and master complex administrative tasks with PostgreSQL 10, then this book is perfect for you. Prior experience of administrating a PostgreSQL database and a working knowledge of SQL are required to make the best use of this book.What You Will Learn• Get to grips with the advanced features of PostgreSQL 10 and handle advanced SQL• Make use of the indexing features in PostgreSQL and fine-tune the performance of your queries• Work with stored procedures and manage backup and recovery• Master replication and failover techniques• Troubleshoot your PostgreSQL instance for solutions to 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. This book highlights the newly introduced features in PostgreSQL 10, and shows you how you can build better PostgreSQL applications, and administer your PostgreSQL database more efficiently. We begin by explaining advanced database design concepts in PostgreSQL 10, 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, high availability, and much more. You will understand 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 advanced database functionalities and will be able to implement advanced administrative tasks with PostgreSQL 10.Style and approachThis mastering-level guide delves into the advanced functionalities of PostgreSQL 10
Frequently asked questions
Information
Making Use of Indexes
- When does PostgreSQL use indexes?
- How does an 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: 176.949 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 obvious problems
- The rewrite system takes 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 = 432332;
QUERY PLAN
----------------------------------------------------------
Seq Scan o...