blob: 2d20b0474b1297e807396a81e73ff2ff8ccd4eee [file] [log] [blame]
Lusheng Jibd115742017-10-13 19:18:52 +00001PostgreSQL as a Service
2============
Tony Hansen30c453e2017-10-13 14:34:46 +00003
4PostgreSQL as a Service comes in two flavors: all-in-one blueprint, and
5separate disk/cluster/database blueprints to separate the management of
6the lifetime of those constituent parts. Both are provided for use.
7
Lusheng Jibd115742017-10-13 19:18:52 +00008Why Two Flavors?
9------------
Tony Hansen30c453e2017-10-13 14:34:46 +000010
11The reason there are two flavors of blueprints lays in the difference in
12lifetime management of the constituent parts.
13
14For example, a database usually needs to have persistent storage, which
15in these blueprints comes from Cinder storage volumes. The primitives
16used in these blueprints assume that the lifetime of the Cinder storage
17volumes matches the lifetime of the blueprint deployment. So when the
18blueprint goes away, any Cinder storage volume allocated in the
19blueprint also goes away.
20
Tony Hansen8c558972017-10-17 18:14:52 +000021Similarly, a database's lifetime may be the same time as an application's
22lifetime. When the application is undeployed, the associated database should
23be deployed too. OR, the database should have a lifetime beyond the scope
24of the applications that are writing to it or reading from it.
Tony Hansen30c453e2017-10-13 14:34:46 +000025
Tony Hansen1c0b82f2017-10-17 19:09:16 +000026Blueprint Files
Tony Hansen8c558972017-10-17 18:14:52 +000027------------
Tony Hansen30c453e2017-10-13 14:34:46 +000028
Tony Hansen1c0b82f2017-10-17 19:09:16 +000029The Blueprints for PG Services and Cinder
30^^^^^^^^^^^
31
Tony Hansen8c558972017-10-17 18:14:52 +000032The all-in-one blueprint PGaaS.yaml assumes that the PG servers and Cinder volumes can be allocated and
33deallocated together. This PGaaS.yaml blueprint creates a cluster named "pstg" by default.
34
35Alternatively, you can split them apart into separate steps, using PGaaS-disk.yaml to allocate the
36Cinder volume, and PGaaS-cluster.yaml to allocate a PG cluster. Create the Cinder volume first using
37PGaaS-disk.yaml, and then use PGaaS-cluster.yaml to create the cluster. The PG cluster can be
38redeployed without affecting the data on the Cinder volumes.
39
40The Blueprints for Databases
Tony Hansen1c0b82f2017-10-17 19:09:16 +000041^^^^^^^^^^^
Tony Hansen8c558972017-10-17 18:14:52 +000042
43The PGaaS-database.yaml blueprint shows how a database can be created separately from any application
44that uses it. That database will remain present until the PGaaS-database.yaml blueprint is
45undeployed. The PGaaS-getdbinfo.yaml file demonstrates how an application would access the credentials
46needed to access a given database on a given PostgreSQL cluster.
47
48If the lifetime of your database is tied to the lifetime of your application, use a block similar to what
49is in PGaaS-database.yaml to allocate the database, and use the attributes as shown in PGaaS-getdbinfo.yaml
50to access the credentials.
Tony Hansen1c0b82f2017-10-17 19:09:16 +000051
52
53What is Created by the Blueprints
54^^^^^^^^^^^^
55
56Each PostgreSQL cluster has a name, represented below as ``${CLUSTER}`` or ``CLNAME``. Each cluster is created
57with two VMs, one VM used for the writable master and the other as a cascaded read-only secondary.
58
59
60There are two DNS A records added, ``${LOCATIONPREFIX}${CLUSTER}00.${LOCATIONDOMAIN}`` and
61``${LOCATIONPREFIX}${CLUSTER}01.${LOCATIONDOMAIN}``. In addition,
62there are two CNAME entries added:
63``${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN} ``
64and
65``${LOCATIONPREFIX}-${CLUSTER}.${LOCATIONDOMAIN}``. The CNAME
66``${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN}`` will be used by further
67blueprints to create and attach to databases.
68
69
70Parameters
71------------
72
73The blueprints are designed to run using the standard inputs file used for all of the blueprints,
74plus several additional parameters that are given reasonable defaults.
75
76How to Run
77------------
78
79
80
81To install the PostgreSQL as a Service
82^^^^^^^^^^^^
83
84Installing the all-in-one blueprint is straightforward:
85
86::
87
88 cfy install -p pgaas.yaml -i inputs.yaml
89
90By default, the all-in-one blueprint creates a cluster by the name ``pstg``.
91
92You can override that name using another ``-i`` option.
93(When overriding the defaults, it is also best to explicitly
94set the -b and -d names.)
95
96::
Tony Hansen09c6a762017-10-30 18:52:57 +000097
Tony Hansen1c0b82f2017-10-17 19:09:16 +000098 cfy install -p pgaas.yaml -b pgaas-CLNAME -d pgaas-CLNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME
99
100
101Separating out the disk allocation from the service creation requires using two blueprints:
102
103::
Tony Hansen09c6a762017-10-30 18:52:57 +0000104
Tony Hansen1c0b82f2017-10-17 19:09:16 +0000105 cfy install -p pgaas-disk.yaml -i inputs.yaml
106 cfy install -p pgaas-cluster.yaml -i inputs.yaml
107
108By default, these blueprints create a cluster named ``pgcl``, which can be overridden the same
109way as shown above:
110
111::
Tony Hansen09c6a762017-10-30 18:52:57 +0000112
Tony Hansen1c0b82f2017-10-17 19:09:16 +0000113 cfy install -p pgaas-disk.yaml -b pgaas-disk-CLNAME -d pgaas-disk-CLNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME
114 cfy install -p pgaas-cluster.yaml -b pgaas-disk-CLNAME -d pgaas-disk-CLNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME
115
116
117You must use the same pgaas_cluster_name for the two blueprints to work together.
118
119For the disk, you can also specify a ``cinder_volume_size``, as in ``-i cinder_volume_size=1000``
120for 1TiB volume. (There is no need to override the ``-b`` and ``-d`` names when changing the
121volume size.)
122
123
124You can verify that the cluster is up and running by connecting to the PostgreSQL service
Tony Hansenb32a0b62017-10-25 11:53:09 +0000125on port 5432. To verify that all of the DNS names were created properly and that PostgreSQL is
126answering on port 5432, you can use something like this:
Tony Hansen1c0b82f2017-10-17 19:09:16 +0000127
128::
Tony Hansen09c6a762017-10-30 18:52:57 +0000129
Tony Hansenb32a0b62017-10-25 11:53:09 +0000130 sleep 1 | nc -v ${LOCATIONPREFIX}${CLUSTER}00.${LOCATIONDOMAIN} 5432
131 sleep 1 | nc -v ${LOCATIONPREFIX}${CLUSTER}01.${LOCATIONDOMAIN} 5432
132 sleep 1 | nc -v ${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN} 5432
133 sleep 1 | nc -v ${LOCATIONPREFIX}-${CLUSTER}.${LOCATIONDOMAIN} 5432
134
Tony Hansen1c0b82f2017-10-17 19:09:16 +0000135
136Once you have the cluster created, you can then allocate databases. An application that
137wants a persistent database not tied to the lifetime of the application blueprint can
138use the ``pgaas-database.yaml`` blueprint to create the database;
139
140::
Tony Hansen09c6a762017-10-30 18:52:57 +0000141
Tony Hansen1c0b82f2017-10-17 19:09:16 +0000142 cfy install -p pgaas-database.yaml -i inputs.yaml
143
144By default, the ``pgaas-database.yaml`` blueprint creates a database with the name ``sample``, which
145can be overridden using ``database_name``.
146
147
148::
Tony Hansen09c6a762017-10-30 18:52:57 +0000149
Tony Hansen1c0b82f2017-10-17 19:09:16 +0000150 cfy install -p pgaas-database.yaml -b pgaas-database-DBNAME -d pgaas-database-DBNAME -i inputs.yaml -i database_name=DBNAME
151 cfy install -p pgaas-database.yaml -b pgaas-database-CLNAME-DBNAME -d pgaas-database-CLNAME-DBNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME -i database_name=DBNAME
152
153
154The ``pgaas-getdbinfo.yaml`` blueprint shows how an application can attach to an existing
155database and access its attributes:
156
157::
Tony Hansen09c6a762017-10-30 18:52:57 +0000158
Tony Hansen1c0b82f2017-10-17 19:09:16 +0000159 cfy install -p pgaas-getdbinfo.yaml -d pgaas-getdbinfo -b pgaas-getdbinfo -i inputs.yaml
160 cfy deployments outputs -d pgaas-getdbinfo
161 cfy uninstall -d pgaas-getdbinfo