- 508 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
PostgreSQL 10 High Performance
About This Book
Leverage the power of PostgreSQL 10 to design, administer and maintain a high-performance database solution
Key Features
- Obtain optimal PostgreSQL 10 database performance, ranging from initial design to routine maintenance
- Fine tune the performance of your queries and avoid the common pitfalls that can slow your system down
- Contains tips and tricks on scaling successful database installations, and ensuring a highly available PostgreSQL solution
Book Description
PostgreSQL database servers have a common set of problems that they encounter as their usage gets heavier and requirements get more demanding. Peek into the future of your PostgreSQL 10 database's problems today. Know the warning signs to look for and how to avoid the most common issues before they even happen.
Surprisingly, most PostgreSQL database applications evolve in the same way—choose the right hardware, tune the operating system and server memory use, optimize queries against the database and CPUs with the right indexes, and monitor every layer, from hardware to queries, using tools from inside and outside PostgreSQL. Also, using monitoring insight, PostgreSQL database applications continuously rework the design and
configuration. On reaching the limits of a single server, they break things up; connection pooling, caching, partitioning, replication, and parallel queries can all help handle increasing database workloads.
By the end of this book, you will have all the knowledge you need to design, run, and manage your PostgreSQL solution while ensuring high performance and high availability
What you will learn
- Learn best practices for scaling PostgreSQL 10 installations
- Discover the best hardware for developing high-performance PostgreSQL applications
- Benchmark your whole system – from hardware to application
- Learn by real examples how server parameters impact performance
- Discover PostgreSQL 10 features for partitioning and parallel query
- Monitor your server, both inside and outside the database
- Design and implement a good replication system on PostgreSQL 10
Who this book is for
This book is designed for database administrators and PostgreSQL architects who already use or plan to exploit the features of PostgreSQL 10 to design and maintain a high-performance PostgreSQL database. A working knowledge of SQL, and some experience with PostgreSQL will be helpful in getting the most out of this book.
Frequently asked questions
Information
Query Optimization
- Explanation of the EXPLAIN command
- Query plan node structure
- Cost computation
- Processing nodes
- Scans
- Subquery scan and subplan
- CTE scan
- Joins
- Statistics
Sample data sets
Pagila
dellstore2
$ wget http://pgfoundry.org/frs/download.php/543/dellstore2-normal-1.0.tar.gz $ tar xvfz dellstore2-normal-1.0.tar.gz $ cd dellstore2-normal-1.0/ $ createdb dellstore2 $ psql -f dellstore2-normal-1.0.sql -d dellstore2 $ psql -d dellstore2 -c "VACUUM VERBOSE ANALYZE"
$ psql -d dellstore2 -c "SELECT pg_size_pretty(pg_database_size('dellstore2'))" pg_size_pretty ---------------- 21 MB
table | size --------------------------------+--------- public.customers | 3808 kB public.orderlines | 2840 kB public.cust_hist | 2368 kB public.products | 808 kB public.orders | 800 kB public.inventory | 400 kB index | size --------------------------------+--------- public.ix_orderlines_orderid | 1336 kB public.ix_cust_hist_customerid | 1080 kB public.ix_cust_username | 544 kB public.customers_pkey | 368 kB public.ix_order_custid | 232 kB public.orders_pkey | 232 kB public.ix_prod_special | 192 kB public.ix_prod_category | 192 kB public.products_pkey | 192 kB public.inventory_pkey | 192 kB
- There are a number of products the store sells, each of which fits into a category
- The store has customers
- Customers place orders
- Each order has a number of lines to it, each of which references the product being purchased
- A customer history is saved listing all the products that customer has ever ordered
EXPLAIN basics
EXPLAIN ANALYZE DELETE * FROM t;
Timing overhead
dellstore2=# \timing Timing is on. dellstore2=# SELECT count(*) FROM customers; count ------- 20000 Time: 7.994 ms
dellstore2=# EXPLAIN ANALYZE SELECT count(*) FROM customers; QUERY PLAN ---------- Aggregate (cost=726.00..726.01 rows=1 width=0) (actual time=68.836..68.838 rows=1 loops=1) -> Seq Scan on customers (cost=0.00..676.00 rows=20000 width=0) (actual time=0.012..33.609 rows=20000 loops=1) Total runtime: 68.934 ms Time: 69.837 ms
Hot and cold cache behavior
SELECT pg_size_pretty(CAST(pg_relation_size('customers') / 7.994 * 1000 as int8)) AS bytes_per_second; bytes_per_second ------------------ 465 MB
Clearing the cache
$ pg_ctl stop $ sudo su - # sync # echo 3 > /proc/sys/vm/drop_caches # logout $ pg_ctl start -l $PGLOG
$ psql -d dellstore2 dellstore2=# \timing Timing is on. dellstore2=# SELECT count(*) FROM customers; count ------- 20000 Time: 204.738 ms dellstore2=# SELECT pg_size_pretty(CAST(pg_relation_size('customers') / 204.738 * 1000 as int8)) AS bytes_per_second; bytes_per_second ------------------ 18 MB
dellstore2=# SELECT count(*) FROM customers; Time: 8.067 ms
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- Packt Upsell
- Contributors
- Preface
- PostgreSQL Versions
- Database Hardware
- Database Hardware Benchmarking
- Disk Setup
- Memory for Database Caching
- Server Configuration Tuning
- Routine Maintenance
- Database Benchmarking
- Database Indexing
- Query Optimization
- Database Activity and Statistics
- Monitoring and Trending
- Pooling and Caching
- Scaling with Replication
- Partitioning Data
- Avoiding Common Problems
- Other Books You May Enjoy