Practical CockroachDB: Building Fault-Tolerant Distributed SQL Databases 1st Edition Rob Reid - Quickly download the ebook to start your content journey
Practical CockroachDB: Building Fault-Tolerant Distributed SQL Databases 1st Edition Rob Reid - Quickly download the ebook to start your content journey
com
https://ebookmeta.com/product/practical-cockroachdb-
building-fault-tolerant-distributed-sql-databases-1st-
edition-rob-reid/
OR CLICK HERE
DOWLOAD EBOOK
https://ebookmeta.com/product/cockroachdb-the-definitive-guide-
distributed-data-at-scale-guy-harrison/
ebookmeta.com
https://ebookmeta.com/product/cockroachdb-the-definitive-guide-
distributed-data-at-scale-1st-edition-jesse-seldess/
ebookmeta.com
https://ebookmeta.com/product/fault-tolerant-attitude-estimation-for-
small-satellites-1st-edition-chingiz-hajiyev-halil-ersin-soken/
ebookmeta.com
https://ebookmeta.com/product/lippincott-illustrated-reviews-
pharmacology-7th-edition-karen-whalen/
ebookmeta.com
What s So Controversial about Genetically Modified Food
1st Edition John T Lang
https://ebookmeta.com/product/what-s-so-controversial-about-
genetically-modified-food-1st-edition-john-t-lang/
ebookmeta.com
https://ebookmeta.com/product/her-daddy-s-jewel-mc-daddies-book-5-1st-
edition-laylah-roberts-2/
ebookmeta.com
https://ebookmeta.com/product/the-impact-of-individual-expertise-and-
public-information-on-group-decision-making-1st-edition-ulrich-g-
strunz/
ebookmeta.com
https://ebookmeta.com/product/cosplay-the-builders-fans-and-makers-
who-bring-your-favorite-stories-to-life-1st-edition-andrew-liptak/
ebookmeta.com
https://ebookmeta.com/product/metaheuristic-algorithms-in-
industry-4-0-advances-in-metaheuristics-1st-edition-pritesh-shah-
editor/
ebookmeta.com
C Language Specification ECMA 334 6th edition June 2022
Ecma
https://ebookmeta.com/product/c-language-specification-ecma-334-6th-
edition-june-2022-ecma/
ebookmeta.com
Practical CockroachDB
SQL Databases
Rob Reid
Rob Reid
Liss, Hampshire, UK
https://doi.org/10.1007/978-1-4842-8224-3
While the advice and information in this book are believed to be true
and accurate at the date of publication, neither the authors nor the
editors nor the publisher can accept any legal responsibility for any
errors or omissions that may be made. The publisher makes no
warranty, express or implied, with respect to the material contained
herein.
Table of Contents
CockroachDB’s Architecture
�������������������������������
�������������������������������
�������������������������������
������������� 2
Licensing
�������������������������������
�������������������������������
�������������������������������
�������������������������������
����������� 5
Free
�������������������������������
�������������������������������
�������������������������������
�������������������������������
������������� 5
Paid For
�������������������������������
�������������������������������
�������������������������������
�������������������������������
������� 6
CockroachDB Core
�������������������������������
�������������������������������
�������������������������������
���������������������� 6
Local Installation
�������������������������������
�������������������������������
�������������������������������
������������������������������ 6
Binary Install
�������������������������������
�������������������������������
�������������������������������
�������������������������������
7
Docker Install
�������������������������������
�������������������������������
�������������������������������
������������������������������ 8
Kubernetes Install
�������������������������������
�������������������������������
�������������������������������
����������������������� 9
Multinode
Clusters����������������������������
�������������������������������
�������������������������������
����������������������� 20
Multiregion Clusters
�������������������������������
�������������������������������
�������������������������������
����������������� 21
Table of ConTenTs
CockroachDB Serverless/Dedicated
�������������������������������
�������������������������������
����������������������������� 29
Creating a Cluster
�������������������������������
�������������������������������
�������������������������������
��������������������� 29
Summary���������������������������
�������������������������������
�������������������������������
�������������������������������
������������� 30
Chapter 3: Concepts
�������������������������������
�������������������������������
�������������������������������
�� 31
Database Objects
�������������������������������
�������������������������������
�������������������������������
��������������������������� 31
Data Types
�������������������������������
�������������������������������
�������������������������������
�������������������������������
������� 33
UUID
�������������������������������
�������������������������������
�������������������������������
�������������������������������
����������� 33
ARRAY
�������������������������������
�������������������������������
�������������������������������
�������������������������������
�������� 34
BIT
�������������������������������
�������������������������������
�������������������������������
�������������������������������
������������� 37
BOOL
�������������������������������
�������������������������������
�������������������������������
�������������������������������
���������� 38
BYTES
�������������������������������
�������������������������������
�������������������������������
�������������������������������
�������� 39
DATE
�������������������������������
�������������������������������
�������������������������������
�������������������������������
���������� 39
ENUM
�������������������������������
�������������������������������
�������������������������������
�������������������������������
��������� 40
DECIMAL
�������������������������������
�������������������������������
�������������������������������
�������������������������������
���� 41
FLOAT
�������������������������������
�������������������������������
�������������������������������
�������������������������������
��������� 43
INET
�������������������������������
�������������������������������
�������������������������������
�������������������������������
����������� 44
INTERVAL
�������������������������������
�������������������������������
�������������������������������
�������������������������������
��� 45
JSONB
�������������������������������
�������������������������������
�������������������������������
�������������������������������
������� 46
SERIAL
�������������������������������
�������������������������������
�������������������������������
�������������������������������
������� 48
STRING
�������������������������������
�������������������������������
�������������������������������
�������������������������������
������� 49
TIME/TIMETZ
�������������������������������
�������������������������������
�������������������������������
����������������������������� 50
TIMESTAMP/TIMESTAMPTZ
�������������������������������
�������������������������������
�������������������������������
������ 51
GEOMETRY
�������������������������������
�������������������������������
�������������������������������
�������������������������������
� 53
Functions
�������������������������������
�������������������������������
�������������������������������
�������������������������������
�������� 55
Geo-partitioned Data
�������������������������������
�������������������������������
�������������������������������
���������������������� 58
REGION BY ROW
�������������������������������
�������������������������������
�������������������������������
����������������������� 59
REGION BY TABLE
�������������������������������
�������������������������������
�������������������������������
��������������������� 63
vi
Table of ConTenTs
Chapter 4: Managing CockroachDB from the Command Line
�������������������������������
�� 67
Connecting to CockroachDB
�������������������������������
�������������������������������
�������������������������������
���������� 83
Connecting with
Tools�����������������������������
�������������������������������
�������������������������������
����������������� 83
Connecting Programmatically
�������������������������������
�������������������������������
�������������������������������
�� 88
Designing Databases
�������������������������������
�������������������������������
�������������������������������
��������������������� 96
Database
Design����������������������������
�������������������������������
�������������������������������
�������������������������� 96
Schema Design
�������������������������������
�������������������������������
�������������������������������
������������������������� 98
Table Design
�������������������������������
�������������������������������
�������������������������������
��������������������������� 101
View Design
�������������������������������
�������������������������������
�������������������������������
���������������������������� 109
Moving Data
�������������������������������
�������������������������������
�������������������������������
�������������������������������
�� 114
Global Regulations
�������������������������������
�������������������������������
�������������������������������
����������������������� 123
Location-Specific Considerations
�������������������������������
�������������������������������
�������������������������������
125
vii
Table of ConTenTs
Encryption
�������������������������������
�������������������������������
�������������������������������
�������������������������������
����� 129
In Transit
�������������������������������
�������������������������������
�������������������������������
�������������������������������
�� 130
At Rest
�������������������������������
�������������������������������
�������������������������������
�������������������������������
����� 133
Single-Region Topologies
�������������������������������
�������������������������������
�������������������������������
������������� 140
Development
�������������������������������
�������������������������������
�������������������������������
�������������������������� 140
Basic
Production��������������������������
�������������������������������
�������������������������������
�������������������������� 140
Multiregion Topologies
�������������������������������
�������������������������������
�������������������������������
����������������� 143
Regional
Tables����������������������������
�������������������������������
�������������������������������
�������������������������� 143
Global Tables
�������������������������������
�������������������������������
�������������������������������
�������������������������� 149
Follower Reads
�������������������������������
�������������������������������
�������������������������������
����������������������� 151
Follow-the-Workload
�������������������������������
�������������������������������
�������������������������������
�������������� 152
Antipatterns
�������������������������������
�������������������������������
�������������������������������
�������������������������������
�� 152
Summary
�������������������������������
�������������������������������
�������������������������������
�������������������������������
� 157
Chapter 8: Testing
�������������������������������
�������������������������������
�������������������������������
���� 159
Structural Testing
�������������������������������
�������������������������������
�������������������������������
������������������������� 161
Functional Testing
�������������������������������
�������������������������������
�������������������������������
������������������������ 165
Performance Testing
�������������������������������
�������������������������������
�������������������������������
��������������� 194
Resilience Testing
�������������������������������
�������������������������������
�������������������������������
������������������� 203
Chapter 9: Production
�������������������������������
�������������������������������
����������������������������� 207
Best Practices
�������������������������������
�������������������������������
�������������������������������
������������������������������
208
SELECT Performance
�������������������������������
�������������������������������
�������������������������������
�������������� 208
INSERT Performance
�������������������������������
�������������������������������
�������������������������������
�������������� 209
UPDATE Performance
�������������������������������
�������������������������������
�������������������������������
������������� 214
Cluster Maintenance
�������������������������������
�������������������������������
�������������������������������
�������������������� 220
Moving a Cluster
�������������������������������
�������������������������������
�������������������������������
�������������������������� 227
viii
Table of ConTenTs
Full Backups
�������������������������������
�������������������������������
�������������������������������
��������������������������� 233
Incremental Backups
�������������������������������
�������������������������������
�������������������������������
�������������� 236
Encrypted Backups
�������������������������������
�������������������������������
�������������������������������
����������������� 237
Locality-Aware Backups
�������������������������������
�������������������������������
�������������������������������
��������� 240
Scheduled Backups
�������������������������������
�������������������������������
�������������������������������
���������������� 241
Cluster Design
�������������������������������
�������������������������������
�������������������������������
������������������������������
243
Cluster Sizing
�������������������������������
�������������������������������
�������������������������������
������������������������� 243
Node Sizing
�������������������������������
�������������������������������
�������������������������������
���������������������������� 243
Monitoring
�������������������������������
�������������������������������
�������������������������������
�������������������������������
����� 244
Index
�������������������������������
�������������������������������
�������������������������������
������������������������ 249
ix
xi
xiii
Acknowledgments
The Cockroach Labs team – The Cockroach Labs team is among the
smartest people I’ve ever met. They’re incredibly dedicated to their
database and its customers and are a big reason for my affection
toward CockroachDB. I’d like to thank the following people from
Cockroach Labs (past and present) for their help, inspiration,
hospitality, and friendship: Jim Walker, Jeff Miller, Carolyn Parrish,
Jordan Lewis, Bram Gruneir, Kai Niemi, Daniel Holt, Glenn Fawcett,
Tim Veil, Jessica Edwards, Dan Kelly, Lakshmi Kannan, Spencer
Kimball, Peter Mattis, Ben Darnell, Nate Stewart, Jesse Seldess, Andy
Woods, Meagan Goldman, Megan Mueller, Andrew Deally, Isaac
Wong, Vincent Giacomazza, Maria Toft, Tom Hannon, Mikael Austin,
Eric Goldstein, Amruta Ranade, Armen Kopoyan, Robert Lee, Charles
Sutton, Kevin Maro, James Weitzman, and anyone I’ve failed to
mention.
xv
Introduction
In this book, I’ll share my excitement for this database and the
experience I’ve gained from using it for many different use cases.
xvii
InTroduCTIon
https://github.com/codingconcepts/practical- cockroachdb
Contacts
CockroachDB
53 W 23rd Street
8th Floor
New York, NY
10010
www.cockroachlabs.com
https://forum.cockroachlabs.com
Rob Reid
[email protected]
https://robreid.io
https://twitter.com/robreid_io
https://github.com/codingconcepts
www.linkedin.com/in/rob- reid
xviii
CHAPTER 1
The Reason
for CockroachDB
What Is CockroachDB?
CockroachDB’s Architecture
CockroachDB uses the Raft Consensus algorithm to give users a
multiactive system, which means every node is the same. There are
no special “active,” “leader,” or “write”
nodes. Every node can receive a portion of read and write requests
for different shards (or “ranges”) of data, helping CockroachDB to
scale horizontally.
2
Chapter 1 the reason for CoCkroaChDB
In Figure 1-2, you’ll see that when we add a node, data in the cluster
will be rebalanced across all four nodes, resulting in shares of 30GB
per node of the 120GB total.
3
Chapter 1 the reason for CoCkroaChDB
CHAPTER 2
Installing CockroachDB
One of CockroachDB’s many strengths is the ease with which you can
install it. In this chapter, we’ll explore CockroachDB’s licensing model
and the various ways you can install it.
Licensing
Free
features. You would need to install this option onto either cloud-
Paid For
CockroachDB Core
In this section, I’ll show you how to install CockroachDB on your local
machine. For each installation method, we’ll run CockroachDB with
insecure configuration for brevity for each installation method, which
means no authentication or encryption. This is acceptable for a
local development database but not for anything else. Once we’ve
installed and tested local insecure deployments, we’ll move on to
some real-world secure implementations.
Binary Install
operating system.
$ curl https://binaries.cockroachdb.com/cockroach-v21.1.7.linux-
amd64.tgz
| tar -xz
$ curl -o cockroach-v21.1.7.windows-6.2-amd64.zip
https://binaries.cockroachdb.com/cockroach-v21.1.7.windows-6.2-
amd64.zip
v21.1.7.windows-6.2-amd64.zip' '.'"
directory and invoke the cockroach executable when you need it, or
add its containing directory to your PATH and invoke the cockroach
executable from any directory.
The cockroach executable is now available, and you can start a local
instance of CockroachDB using the following command:
7
Another Random Scribd Document
with Unrelated Content
IN A GARDEN
Gushing from the mouths of stone men
To spread at ease under the sky
In granite-lipped basins,
Where iris dabble their feet
And rustle to a passing wind,
The water fills the garden with its rushing,
In the midst of the quiet of close-clipped lawns.
Amy Lowell
POSTLUDE
Now that I have cooled to you
Let there be gold of tarnished masonry,
Temples soothed by the sun to ruin
That sleep utterly.
Give me hand for the dances,
Ripples at Philæ, in and out,
And lips, my Lesbian,
Wall flowers that once were flame.
James Joyce
ΔΏΡΙΑ
Ezra Pound
THE RETURN
Ezra Pound
AFTER CH’U YUAN
Ezra Pound
LIU CH’E
Ezra Pound.
FAN-PIECE FOR HER IMPERIAL LORD
Ezra Pound
TS’AI CHI’H
Hear it rain!
And from eight leaden pipes in the ball he stands on
That has eight leaden and copper bands on,
There gurgle and drain
Eight driblets of water down into the basin.
Th i t!
The poor saint!
It rains and it rains,
In the market there isn’t an ox,
And in all the emplacement
For waggons there isn’t a waggon,
Not a stall for a grape or a raisin,
Not a soul in the market
Save the saint on his dragon
With the rain dribbling down in the basin,
And the maiden that sews in the casement.