blob: 47e234e017e2e5395bd545d040e399afb71a2b15 [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::
97 cfy install -p pgaas.yaml -b pgaas-CLNAME -d pgaas-CLNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME
98
99
100Separating out the disk allocation from the service creation requires using two blueprints:
101
102::
103 cfy install -p pgaas-disk.yaml -i inputs.yaml
104 cfy install -p pgaas-cluster.yaml -i inputs.yaml
105
106By default, these blueprints create a cluster named ``pgcl``, which can be overridden the same
107way as shown above:
108
109::
110 cfy install -p pgaas-disk.yaml -b pgaas-disk-CLNAME -d pgaas-disk-CLNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME
111 cfy install -p pgaas-cluster.yaml -b pgaas-disk-CLNAME -d pgaas-disk-CLNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME
112
113
114You must use the same pgaas_cluster_name for the two blueprints to work together.
115
116For the disk, you can also specify a ``cinder_volume_size``, as in ``-i cinder_volume_size=1000``
117for 1TiB volume. (There is no need to override the ``-b`` and ``-d`` names when changing the
118volume size.)
119
120
121You can verify that the cluster is up and running by connecting to the PostgreSQL service
122on port 5432:
123
124::
125 telnet ${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN} 5432
126
127Once you have the cluster created, you can then allocate databases. An application that
128wants a persistent database not tied to the lifetime of the application blueprint can
129use the ``pgaas-database.yaml`` blueprint to create the database;
130
131::
132 cfy install -p pgaas-database.yaml -i inputs.yaml
133
134By default, the ``pgaas-database.yaml`` blueprint creates a database with the name ``sample``, which
135can be overridden using ``database_name``.
136
137
138::
139 cfy install -p pgaas-database.yaml -b pgaas-database-DBNAME -d pgaas-database-DBNAME -i inputs.yaml -i database_name=DBNAME
140 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
141
142
143The ``pgaas-getdbinfo.yaml`` blueprint shows how an application can attach to an existing
144database and access its attributes:
145
146::
147 cfy install -p pgaas-getdbinfo.yaml -d pgaas-getdbinfo -b pgaas-getdbinfo -i inputs.yaml
148 cfy deployments outputs -d pgaas-getdbinfo
149 cfy uninstall -d pgaas-getdbinfo