Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Troubleshooting PostgreSQL

You're reading from   Troubleshooting PostgreSQL Intercept problems and challenges typically faced by PostgreSQL database administrators with the best troubleshooting techniques

Arrow left icon
Product type Paperback
Published in Mar 2015
Publisher Packt
ISBN-13 9781783555314
Length 164 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Installing PostgreSQL FREE CHAPTER 2. Creating Data Structures 3. Handling Indexes 4. Reading Data Efficiently and Correctly 5. Getting Transactions and Locking Right 6. Writing Proper Procedures 7. PostgreSQL Monitoring 8. Fixing Backups and Replication 9. Handling Hardware and Software Disasters 10. A Standard Approach to Troubleshooting Index

Avoiding trouble with indexes


Indexes are not always a solution to the problem; they can also be the problem by themselves. The following example outlines a common pitfall. It should be avoided at all costs:

test=# CREATE TABLE t_test (id int, x text);
CREATE TABLE
test=# INSERT INTO t_test SELECT x, 'house' 
  FROM generate_series(1, 10000000) AS x;
INSERT 0 10000000
test=# CREATE INDEX idx_x ON t_test (x);
CREATE INDEX

Before taking a look at the way the index is used, it makes sense to inspect the size of the table as well as the size of the indexes:

test=# SELECT
   pg_size_pretty(pg_relation_size('t_test')), 
  pg_size_pretty(pg_relation_size('idx_x'));
 pg_size_pretty | pg_size_pretty 
----------------+----------------
 422 MB         | 214 MB
(1 row)

The table created in this example is 422 MB large (only the table). On top of that, there is 214 MB taken up by the index. So, overall the size of the table with the index is larger than 600 MB.

The problem is that the index is of no use in...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime