Learning Heroku Postgres - Patrick Espake - E-Book

Learning Heroku Postgres E-Book

Patrick Espake

0,0
23,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Learning Heroku Postgres is targeted at developers and database admins. Even if you're new to Heroku Postgres, you'll be able to master both the basic as well as advanced features of Heroku Postgres. Since Heroku Postgres is incredibly user-friendly, no previous experience in computer coding or programming is required.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 158

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Learning Heroku Postgres
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Instant updates on new Packt books
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started with Heroku Postgres
How does Heroku work?
Heroku Dashboard and Heroku Toolbelt
Deploying your applications
Heroku architecture
HTTP routing
Dyno Manager
Config vars
Understanding the Dynos
Workers
Add-ons
Logplex
Heroku API
Postgres supported versions
Choosing the right Heroku Postgres plan
Shared features
Production-tier technical characterization
High availability
Self-test Questions
Summary
2. Heroku Toolbelt
Signing up
Installing the Heroku Toolbelt
Logging in to Heroku
Deploying an application
The sample application source code
The dependencies file
Deploying the sample application
Visiting the sample application
Self-test questions
Summary
3. Postgres Add-on
Local setup
Setting up PostgreSQL on Mac OS X
Setting up PostgreSQL on Windows
Setting up PostgreSQL on Linux
Creating a local database
Creating a new app
Via the Heroku dashboard
Via the Heroku client
Adding the add-on and creating the first database
Adding the Heroku Postgres add-on
Via the Heroku add-ons gallery
Via the Heroku client
Creating the first database
Heroku Postgres web interface
Using the Heroku client with Postgres
The pg:info command
The pg:psql command
The pg:push command
The pg:pull command
The pg:ps command
The pg:kill command
The pg:killall command
The pg:promote command
The pg:credentials command
The pg:reset command
Connecting with Java
JDBC
Spring/XML
Connecting with Ruby
Connecting with Python
Connecting with Django
Connecting with Node.js
Connection permissions
Multiple schemas
External connections
Connecting to databases from outside Heroku
Monitoring and logging
Removing the add-on
Self-test Questions
Summary
4. PG Backups
Plans
Installing the add-on
Via the Heroku client
Via the web interface
Changing the plan
Creating a backup
Listing backups
Via the Heroku client
Via the web interface
Downloading a backup
Deleting backups
Restoring from a backup
Importing databases
Importing in Heroku Postgres
Exporting databases
Downloading the backup
Restoring to local database
Removing the add-on
Via the Heroku client
Via the web interface
Self-test Questions
Summary
5. Dataclips
Creating dataclips
Sharing dataclips
Interacting with dataclips
Data refresh
Dataclips security
Limitations and additional settings
Self-test questions
Summary
6. Rollback, Followers, and Forks
Heroku Postgres rollback
Checking the rollback feature
Available period
Creating a rollback database
Promote a rollback database
Deprovisioning a rollback database
Heroku Postgres follower databases
Creating and managing follower databases
Unfollow the main database
Upgrade the database plan with follower
High availability with followers
Heroku Postgres forking databases
Forking your database
Forking databases with the fast option
View your fork databases
Deprovisioning a fork database
Self-test questions
Summary
7. Understanding Log Statements and Common Errors
Log statements
Common errors
LOG: long duration
LOG: unexpected EOF on client connection
PGError: permission denied for relation
PGError: operator does not exist
PGError: relation "table-name" does not exist
PGError: column "column-name" cannot...
PGError: SSL SYSCALL error: EOF detected
PGError: prepared statement "a30" already exists
FATAL: too many connections for role
FATAL: could not receive data...
FATAL: role "role-name"...
FATAL: terminating connection due to administrator command
FATAL: remaining connection slots are reserved for non-replication superuser connections
Temporary file: path "file path", size "file size"
Metrics logs
Self-test questions
Summary
8. Extensions, PostGIS, Full Text Search Dictionaries, Data Caching, and Tuning
Heroku Postgres extensions
Data types
Case-insensitive text – citext
Cube
HStore
Label tree – ltree
Product numbering – isn
Functions
Earth distance
Intarray
Fuzzy match – fuzzystrmatch
PGCrypto
Table functions and pivot tables – tablefunc
Trigram – pg_trgm
UUID generation
Statistics
Row locking – pgrowlocks
Tuple statistics – pgstattuple
Index types
Btree GiST – btree_gist
Languages
PLV8 – V8 Engine JavaScript Procedural Language
Full text search dictionaries
Dict int
Unaccent
Data caching
Setting up PostGIS
Provisioning
Database tuning
Database VACUUM
Determining the bloat factor
Manual vacuuming
Automatic vacuuming
Performance analysis
Self-test Questions
Summary
A. Keyword List
B. Self-test Answers
Chapter 1: Getting Started with Heroku Postgres
Chapter 2: Heroku Toolbelt
Chapter 3: Postgres Add-on
Chapter 4: PG Backups
Chapter 5: Dataclips
Chapter 6: Rollback, Followers, and Forks
Chapter 7: Understanding Log Statements and Common Errors
Chapter 8: Extensions, PostGIS, Full Text Search Dictionaries, Data Caching, and Tuning
Index

Learning Heroku Postgres

Learning Heroku Postgres

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: February 2015

Production reference: 1190215

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78217-345-8

www.packtpub.com

Credits

Author

Patrick Espake

Reviewers

Razvan Draghici

Andrea Mostosi

Peter Robinett

Karanraj Sankaranarayanan

Ariejan de Vroom

Commissioning Editor

Amarabha Bannerjee

Acquisition Editor

Nikhil Karkal

Content Development Editor

Pooja Nair

Technical Editor

Bharat Patil

Copy Editors

Karuna Narayanan

Laxmi Subramanian

Project Coordinator

Leena Purkait

Proofreaders

Stephen Copestake

Martin Diver

Paul Hindle

Indexer

Mariammal Chettiyar

Graphics

Disha Haria

Sheetal Aute

Production Coordinator

Alwin Roy

Cover Work

Alwin Roy

About the Author

Patrick Espake is passionate about technology, innovation, software development, and entrepreneurship. He has been professionally building and deploying web applications for over 10 years; with Heroku, it has been over 5 years, and he has worked on amazing projects for companies across the world. Currently, he is a cofounder of http://coursify.me. When Patrick isn't coding or writing, you will usually find him traveling to some wonderful place with his family.

I would like to thank my parents for their dedication and advice during my life, especially my mother, Elza, for not sparing effort and for her sacrifices to educate me and turn me into the person I am today. I would say that all your efforts were worthwhile and finishing this book together was a great achievement.

I also could never have finished this book without the support and encouraging words from my wife, Priscila. Through her infinite and pure love, she encouraged me and showed enormous patience during the several months that I've dedicated to this book. I would like to say that I am very grateful to be your husband.

I would also like to send a huge thank you to the Bard Kunenn family, who invited me numerous times for lunch during the weekends that I spent writing this book and provided me countless encouraging words for the creation of this book.

Finally, I would like to say thank you very much to my friend, Ana Carolina, for helping me in reviewing this book and for being so helpful with her suggestions for improvement.

About the Reviewers

Razvan Draghici is a full-stack software developer and scalability expert with over 7 years of experience in the field. In the past, he helped scale and develop high traffic applications for web properties, such as Sportsnet.ca, Bing Shopping Canada, and Canada Post Comparison Shopper. He is passionate about machine learning and data science, and while at Sportsnet he developed an NBA Playoffs winner prediction algorithm as part of a hackathon.

Razvan writes about software and technology at http://sleekd.com.

Andrea Mostosi is a technology enthusiast. An innovation lover since he was a child, he started his professional career in 2003 and worked on several projects, playing almost every role in the computer science environment. He is currently the CTO at The Fool, a company that tries to make sense of web and social data. During his free time, he likes to travel, run, cook, bike, and code.

I would like to thank my geek friends: Simone M, Daniele V, Luca T, Luigi P, Michele N, Luca O, Luca B, Diego C, and Fabio B. They are the smartest people I know and comparing myself with them has always pushed me to be better.

Peter Robinett is a backend and mobile developer, focusing on Scala and iOS development. He is a frequent user of the Heroku platform and is a fan of its power and extensibility.

He is currently a developer at Lua Technologies. He also works under the name Bubble Foundry and blogs occasionally at www.bubblefoundry.com.

Ariejan de Vroom is a software engineer from Son en Breugel, The Netherlands. He's been working professionally with Ruby on Rails at Kabisa since 2007. When not writing code, Ariejan likes to read, play the piano and experiment with electronics.

Karanraj Sankaranarayanan is a certified Salesforce.com developer and works as a Salesforce consultant at HCL Technologies. He holds a bachelor's degree in engineering from Anna University with specialization in computer science. He has more than 4 years of experience in the Salesforce platform and IT industry. He is passionate about the Salesforce platform and is an active member of and contributor to the Salesforce developer community. He writes technical blogs at http://clicksandcode.blogspot.in/.

He won second place in the Salesforce Summer of Hacks event in Bangalore. He is also the organizer of the Chennai Salesforce Platform Developer Group based in Chennai, India. His Twitter handle is @karanrajs

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Instant updates on new Packt books

Get notified! Find out when new books are published by following @PacktEnterprise on Twitter or the Packt Enterprise Facebook page.

Preface

This book is a definitive guide on how to use PostgreSQL on Heroku. Learn how to work with backups, dataclips, rollback, followers, forks, extensions, PostGIS, data caching, tuning, log statements, and common errors.

Heroku Postgres allows you to manage your PostgreSQL databases in a simple, worry-free way and from anywhere. Through the offered features, you can easily scale your database and extend functionalities.

This book is suitable for all Heroku Postgres user levels and offers knowledge that will help you manage your database with tranquility. The book covers simple topics until we reach more complex issues such as data caching and tuning. Through this book, you will be able to work with all the functionalities provided by Heroku Postgres.

What this book covers

Chapter 1, Getting Started with Heroku Postgres, introduces the Heroku architecture and how to build applications using Heroku Postgres. It also describes the key concepts about Heroku.

Chapter 2, Heroku Toolbelt, describes the Heroku Toolbelt and all the necessary tools to get started using Heroku at the command-line.

Chapter 3, Postgres Add-on, covers how to configure your local development environment, how to use the add-on, how to create your database, and how to connect using different programming languages. It also introduces the concepts of monitoring and information logs.

Chapter 4, PG Backups, introduces how to generate backups, import/export databases, data security, continuous protection, and how to upgrade your database plan.

Chapter 5, Dataclips, describes how dataclips work and how to share them with your colleagues. It also provides knowledge about security and limitations.

Chapter 6, Rollback, Followers, and Forks, covers important concepts related to security, stability, and experiments in using PostgreSQL database on the Heroku platform. It discusses topics related to rollback, followers, and forks.

Chapter 7, Understanding Log Statements and Common Errors, introduces how to view logs, how to collect metrics, and how to understand the most common errors.

Chapter 8, Extensions, PostGIS, Full Text Search Dictionaries, Data Caching, and Tuning, describes a collection of advanced features: how to install the main extensions of the Postgres database, how to enable PostGIS for work with spatial data, how to make optimizations, the text search tools, and the data cache.

Appendix A, Keyword List, contains a set of keywords used in this book, along with their definitions to facilitate better understanding of the concepts.

Appendix B, Self-test Answers, contains the answers to questions in each chapter that help test the knowledge you acquired.

What you need for this book

The software needed for this book includes the Heroku Toolbelt (client) (https://toolbelt.heroku.com), your preferred IDE such as Sublime Text (http://www.sublimetext.com), PostgreSQL (http://www.postgresql.org), pgAdmin (http://www.pgadmin.org), the Google Chrome web browser, and a Terminal.

Who this book is for

Learning Heroku Postgres is suitable for developers and database administrators. Even if you are new to Heroku Postgres, you will be able to master both the basic functions and the advanced features of Heroku Postgres. Since Heroku Postgres maintains an incredibly user-friendly interface, no previous experience in computer coding or programming is required.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows:

In the case of Ruby on Rails, these dependencies are found in Gemfile in Python requirements.txt, in Node.js package.json, and in Java pom.xml.

Any command-line input or output is written as follows:

$ heroku pg:info --app learning-heroku-postgres-app

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an email to <[email protected]>, and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the erratasubmissionform link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. Getting Started with Heroku Postgres

Heroku simplifies the infrastructure of web applications. With its architecture, it is possible to create robust, manageable, and scalable applications according to the needs of your business.

This book is focused on how Heroku works with PostgreSQL. It will cover pieces of architecture and how to build applications that benefit from Heroku Postgres. In this first chapter, you will learn about the key concepts of Heroku, how it works, what are the supported versions of PostgreSQL, how to choose the best plan according to your need, and how high availability works. The concepts covered in this chapter are fundamental to understanding the other chapters.

In this chapter, will cover the following topics:

How does Heroku work?Postgres supported versionsChoosing the right Heroku Postgres planProduction-tier technical characterizationHigh availability

How does Heroku work?

Heroku is a multi-language cloud platform that enables you to deploy applications written in several programming languages such as Ruby, Java, Python, Clojure, Scala, and Node.js. The list of supported programming languages is always growing.