Lusheng Ji | bd11574 | 2017-10-13 19:18:52 +0000 | [diff] [blame] | 1 | PostgreSQL as a Service |
| 2 | ============ |
Tony Hansen | 30c453e | 2017-10-13 14:34:46 +0000 | [diff] [blame] | 3 | |
| 4 | PostgreSQL as a Service comes in two flavors: all-in-one blueprint, and |
| 5 | separate disk/cluster/database blueprints to separate the management of |
| 6 | the lifetime of those constituent parts. Both are provided for use. |
| 7 | |
Lusheng Ji | bd11574 | 2017-10-13 19:18:52 +0000 | [diff] [blame] | 8 | Why Two Flavors? |
| 9 | ------------ |
Tony Hansen | 30c453e | 2017-10-13 14:34:46 +0000 | [diff] [blame] | 10 | |
| 11 | The reason there are two flavors of blueprints lays in the difference in |
| 12 | lifetime management of the constituent parts. |
| 13 | |
| 14 | For example, a database usually needs to have persistent storage, which |
| 15 | in these blueprints comes from Cinder storage volumes. The primitives |
| 16 | used in these blueprints assume that the lifetime of the Cinder storage |
| 17 | volumes matches the lifetime of the blueprint deployment. So when the |
| 18 | blueprint goes away, any Cinder storage volume allocated in the |
| 19 | blueprint also goes away. |
| 20 | |
Tony Hansen | 8c55897 | 2017-10-17 18:14:52 +0000 | [diff] [blame] | 21 | Similarly, a database's lifetime may be the same time as an application's |
| 22 | lifetime. When the application is undeployed, the associated database should |
| 23 | be deployed too. OR, the database should have a lifetime beyond the scope |
| 24 | of the applications that are writing to it or reading from it. |
Tony Hansen | 30c453e | 2017-10-13 14:34:46 +0000 | [diff] [blame] | 25 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 26 | Blueprint Files |
Tony Hansen | 8c55897 | 2017-10-17 18:14:52 +0000 | [diff] [blame] | 27 | ------------ |
Tony Hansen | 30c453e | 2017-10-13 14:34:46 +0000 | [diff] [blame] | 28 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 29 | The Blueprints for PG Services and Cinder |
| 30 | ^^^^^^^^^^^ |
| 31 | |
Tony Hansen | 8c55897 | 2017-10-17 18:14:52 +0000 | [diff] [blame] | 32 | The all-in-one blueprint PGaaS.yaml assumes that the PG servers and Cinder volumes can be allocated and |
| 33 | deallocated together. This PGaaS.yaml blueprint creates a cluster named "pstg" by default. |
| 34 | |
| 35 | Alternatively, you can split them apart into separate steps, using PGaaS-disk.yaml to allocate the |
| 36 | Cinder volume, and PGaaS-cluster.yaml to allocate a PG cluster. Create the Cinder volume first using |
| 37 | PGaaS-disk.yaml, and then use PGaaS-cluster.yaml to create the cluster. The PG cluster can be |
| 38 | redeployed without affecting the data on the Cinder volumes. |
| 39 | |
| 40 | The Blueprints for Databases |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 41 | ^^^^^^^^^^^ |
Tony Hansen | 8c55897 | 2017-10-17 18:14:52 +0000 | [diff] [blame] | 42 | |
| 43 | The PGaaS-database.yaml blueprint shows how a database can be created separately from any application |
| 44 | that uses it. That database will remain present until the PGaaS-database.yaml blueprint is |
| 45 | undeployed. The PGaaS-getdbinfo.yaml file demonstrates how an application would access the credentials |
| 46 | needed to access a given database on a given PostgreSQL cluster. |
| 47 | |
| 48 | If the lifetime of your database is tied to the lifetime of your application, use a block similar to what |
| 49 | is in PGaaS-database.yaml to allocate the database, and use the attributes as shown in PGaaS-getdbinfo.yaml |
| 50 | to access the credentials. |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | What is Created by the Blueprints |
| 54 | ^^^^^^^^^^^^ |
| 55 | |
| 56 | Each PostgreSQL cluster has a name, represented below as ``${CLUSTER}`` or ``CLNAME``. Each cluster is created |
| 57 | with two VMs, one VM used for the writable master and the other as a cascaded read-only secondary. |
| 58 | |
| 59 | |
| 60 | There are two DNS A records added, ``${LOCATIONPREFIX}${CLUSTER}00.${LOCATIONDOMAIN}`` and |
| 61 | ``${LOCATIONPREFIX}${CLUSTER}01.${LOCATIONDOMAIN}``. In addition, |
| 62 | there are two CNAME entries added: |
| 63 | ``${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN} `` |
| 64 | and |
| 65 | ``${LOCATIONPREFIX}-${CLUSTER}.${LOCATIONDOMAIN}``. The CNAME |
| 66 | ``${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN}`` will be used by further |
| 67 | blueprints to create and attach to databases. |
| 68 | |
| 69 | |
| 70 | Parameters |
| 71 | ------------ |
| 72 | |
| 73 | The blueprints are designed to run using the standard inputs file used for all of the blueprints, |
| 74 | plus several additional parameters that are given reasonable defaults. |
| 75 | |
| 76 | How to Run |
| 77 | ------------ |
| 78 | |
| 79 | |
| 80 | |
| 81 | To install the PostgreSQL as a Service |
| 82 | ^^^^^^^^^^^^ |
| 83 | |
| 84 | Installing the all-in-one blueprint is straightforward: |
| 85 | |
| 86 | :: |
| 87 | |
| 88 | cfy install -p pgaas.yaml -i inputs.yaml |
| 89 | |
| 90 | By default, the all-in-one blueprint creates a cluster by the name ``pstg``. |
| 91 | |
| 92 | You can override that name using another ``-i`` option. |
| 93 | (When overriding the defaults, it is also best to explicitly |
| 94 | set 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 | |
| 100 | Separating 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 | |
| 106 | By default, these blueprints create a cluster named ``pgcl``, which can be overridden the same |
| 107 | way 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 | |
| 114 | You must use the same pgaas_cluster_name for the two blueprints to work together. |
| 115 | |
| 116 | For the disk, you can also specify a ``cinder_volume_size``, as in ``-i cinder_volume_size=1000`` |
| 117 | for 1TiB volume. (There is no need to override the ``-b`` and ``-d`` names when changing the |
| 118 | volume size.) |
| 119 | |
| 120 | |
| 121 | You can verify that the cluster is up and running by connecting to the PostgreSQL service |
| 122 | on port 5432: |
| 123 | |
| 124 | :: |
| 125 | telnet ${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN} 5432 |
| 126 | |
| 127 | Once you have the cluster created, you can then allocate databases. An application that |
| 128 | wants a persistent database not tied to the lifetime of the application blueprint can |
| 129 | use the ``pgaas-database.yaml`` blueprint to create the database; |
| 130 | |
| 131 | :: |
| 132 | cfy install -p pgaas-database.yaml -i inputs.yaml |
| 133 | |
| 134 | By default, the ``pgaas-database.yaml`` blueprint creates a database with the name ``sample``, which |
| 135 | can 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 | |
| 143 | The ``pgaas-getdbinfo.yaml`` blueprint shows how an application can attach to an existing |
| 144 | database 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 |