@@ -34,23 +34,29 @@ Metadata:
34
34
Label :
35
35
default : " Source PostgreSQL parameters"
36
36
Parameters :
37
+ - SourceDatabaseSize
37
38
- SourcePostgresHost
38
39
- SourcePostgresPort
39
40
- SourcePostgresUsername
40
41
- SourcePostgresPassword
41
42
- SourcePostgresDBName
42
- - SourcePostgresVersion
43
43
- PostgresConfigSharedPreloadLibraries
44
44
- SourcePostgresDBList
45
+ -
46
+ Label :
47
+ default : " Advanced DLE configuration"
48
+ Parameters :
49
+ - PostgresDockerImage
50
+ - DLEZFSDataSetsNumber
45
51
ParameterLabels :
46
52
KeyName :
47
53
default : " Key pair"
48
54
InstanceType :
49
55
default : " Instance type"
50
56
SSHLocation :
51
57
default : " Connection source IP range"
52
- ZFSVolumeSize :
53
- default : " EBS volume size in GB for ZFS "
58
+ SourceDatabaseSize :
59
+ default : " Total source database size in GiB "
54
60
CertificateSubdomain :
55
61
default : " Certificate subdomain"
56
62
CertificateHostedZone :
@@ -63,6 +69,10 @@ Metadata:
63
69
default : " DLE verification token"
64
70
DLERetrievalRefreshTimetable :
65
71
default : " DLE retrieval refresh timetable"
72
+ PostgresDockerImage :
73
+ default : " Postgres docker image"
74
+ DLEZFSDataSetsNumber :
75
+ default : " Number of supported snapshots."
66
76
PostgresDumpParallelJobs :
67
77
default : " Number of pg_dump jobs"
68
78
SourcePostgresDBName :
@@ -71,8 +81,6 @@ Metadata:
71
81
default : " VPC security group"
72
82
Subnet :
73
83
default : " Subnet"
74
- SourcePostgresVersion :
75
- default : " Postgres version"
76
84
SourcePostgresHost :
77
85
default : " Host name or IP"
78
86
SourcePostgresPort :
@@ -85,7 +93,6 @@ Metadata:
85
93
default : " shared_preload_libraries parameter"
86
94
SourcePostgresDBList :
87
95
default : " Comma separated list of databases to copy"
88
-
89
96
Parameters :
90
97
Subnet :
91
98
Description : Subnet to attach EC2 machine.
@@ -134,8 +141,8 @@ Parameters:
134
141
MaxLength : ' 18'
135
142
AllowedPattern : ' (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
136
143
ConstraintDescription : Must be a valid IP CIDR range of the form x.x.x.x/x
137
- ZFSVolumeSize :
138
- Description : The size of the EBS volumes used for DLE ZFS pool
144
+ SourceDatabaseSize :
145
+ Description : The size of the source databases used to calculate the size of EBS volume, in GiB
139
146
Type : Number
140
147
Default : 40
141
148
CertificateSubdomain :
@@ -167,21 +174,20 @@ Parameters:
167
174
Description : DLE refresh schedule on cron format
168
175
Type : String
169
176
Default : ' 0 0 * * *'
177
+ DLEZFSDataSetsNumber :
178
+ Description : Number of database copies needed
179
+ Type : Number
180
+ Default : 2
181
+ MinValue : 2
182
+ MaxValue : 100
183
+ PostgresDockerImage :
184
+ Description : Docker image to run PostgreSQL
185
+ Type : String
186
+ Default : ' postgresai/extended-postgres:14'
170
187
SourcePostgresDBName :
171
188
Description : Source database name. This parameter is used to connect to the database
172
189
Type : String
173
190
Default : ' postgres'
174
- SourcePostgresVersion :
175
- Description : Source database Postgres version
176
- Type : String
177
- Default : 14
178
- AllowedValues :
179
- - 9.6
180
- - 10
181
- - 11
182
- - 12
183
- - 13
184
- - 14
185
191
SourcePostgresHost :
186
192
Description : Source Postgres cluster host name or IP
187
193
Type : String
@@ -301,13 +307,45 @@ Conditions:
301
307
!Not [!Equals [!Ref CertificateHostedZone, '']]
302
308
303
309
Resources :
310
+ LambdaExecutionRole :
311
+ Type : AWS::IAM::Role
312
+ Properties :
313
+ AssumeRolePolicyDocument :
314
+ Version : ' 2012-10-17'
315
+ Statement :
316
+ - Effect : Allow
317
+ Principal : {Service: [lambda.amazonaws.com]}
318
+ Action : ['sts:AssumeRole']
319
+ Path : " /"
320
+ ManagedPolicyArns :
321
+ - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
322
+ PowerFunction :
323
+ Type : AWS::Lambda::Function
324
+ Properties :
325
+ Handler : index.handler
326
+ Role : !GetAtt LambdaExecutionRole.Arn
327
+ Code :
328
+ ZipFile : !Sub |
329
+ var response = require('cfn-response');
330
+ exports.handler = function(event, context) {
331
+ var result = parseInt(event.ResourceProperties.Op1)*(parseInt(event.ResourceProperties.Op2)+2);
332
+ response.send(event, context, response.SUCCESS, {Value: result});
333
+ };
334
+ Runtime : nodejs14.x
335
+ SizeCalculate :
336
+ Type : Custom::Power
337
+ Properties :
338
+ ServiceToken : !GetAtt PowerFunction.Arn
339
+ Op1 : !Ref SourceDatabaseSize
340
+ Op2 : !Ref DLEZFSDataSetsNumber
341
+
304
342
ZFSVolume :
305
343
Type : AWS::EC2::Volume
306
344
DeletionPolicy : Snapshot
307
345
Properties :
308
346
Encrypted : True
309
347
AvailabilityZone : !GetAtt DLEInstance.AvailabilityZone
310
- Size : !Ref ZFSVolumeSize
348
+ Size : !GetAtt SizeCalculate.Value
311
349
Tags :
312
350
-
313
351
Key : Name
@@ -342,7 +380,6 @@ Resources:
342
380
set -ex
343
381
344
382
sleep 30
345
-
346
383
347
384
# This code tested and works on Ubuntu 20.04 (current base AMI)
348
385
disk=$(lsblk -e7 --output PATH,NAME,FSTYPE --json | jq -r '.blockdevices[] | select(.children == null and .fstype == null) | .path ')
@@ -356,6 +393,10 @@ Resources:
356
393
dblab_pool \
357
394
$disk
358
395
396
+ for i in {1..${DLEZFSDataSetsNumber}}; do
397
+ sudo zfs create dblab_pool/dataset_$i
398
+ done
399
+
359
400
dle_config_path="/home/ubuntu/.dblab/engine/configs"
360
401
dle_meta_path="/home/ubuntu/.dblab/engine/meta"
361
402
postgres_conf_path="/home/ubuntu/.dblab/postgres_conf"
@@ -366,9 +407,11 @@ Resources:
366
407
.server.verificationToken="${DLEVerificationToken}" |
367
408
.retrieval.refresh.timetable="${DLERetrievalRefreshTimetable}" |
368
409
.retrieval.spec.logicalRestore.options.forceInit=true |
369
- .databaseContainer.dockerImage="postgresai/extended-postgres:${SourcePostgresVersion}" |
370
- .databaseConfigs.configs.shared_preload_libraries="${PostgresConfigSharedPreloadLibraries}" |
371
- .databaseContainer.dockerImage="postgresai/extended-postgres:${SourcePostgresVersion}"
410
+ .poolManager.mountDir = "/var/lib/dblab/dblab_pool" |
411
+ .retrieval.spec.logicalDump.options.dumpLocation="/var/lib/dblab/dblab_pool/dataset_1/dump/" |
412
+ .retrieval.spec.logicalRestore.options.dumpLocation="/var/lib/dblab/dblab_pool/dataset_1/dump/" |
413
+ .databaseContainer.dockerImage="${PostgresDockerImage}" |
414
+ .databaseConfigs.configs.shared_preload_libraries="${PostgresConfigSharedPreloadLibraries}"
372
415
' $dle_config_path/server.yml
373
416
374
417
yq e -i '
@@ -397,13 +440,13 @@ Resources:
397
440
--publish 2345:2345 \
398
441
--volume /var/run/docker.sock:/var/run/docker.sock \
399
442
--volume /var/lib/dblab:/var/lib/dblab/:rshared \
400
- --volume /var/lib/dblab/dblab_pool/dump:/var/lib/dblab/dblab_pool/dump/:rshared \
443
+ --volume /var/lib/dblab/dblab_pool/dataset_1/ dump/ :/var/lib/dblab/dblab_pool/dataset_1 /dump/:rshared \
401
444
--volume $dle_config_path:/home/dblab/configs:ro \
402
445
--volume $dle_meta_path:/home/dblab/meta \
403
446
--volume $postgres_conf_path:/home/dblab/standard/postgres/control \
404
447
--env DOCKER_API_VERSION=1.39 \
405
448
--restart always \
406
- registry.gitlab.com/postgres-ai/database-lab/dblab-server:3.0.3
449
+ registry.gitlab.com/postgres-ai/database-lab/dblab-server:3.1.0
407
450
408
451
if [ ! -z "${CertificateHostedZone}" ]; then
409
452
export DOMAIN=${CertificateSubdomain}.${CertificateHostedZone}
@@ -495,7 +538,6 @@ Resources:
495
538
CidrIp : ' 0.0.0.0/0'
496
539
VpcId : !Ref VPC
497
540
498
-
499
541
Outputs :
500
542
VerificationToken :
501
543
Description : ' DLE verification token'
@@ -511,6 +553,10 @@ Outputs:
511
553
Value : !Sub 'https://${CertificateSubdomain}.${CertificateHostedZone}:446'
512
554
Condition : CreateSubDomain
513
555
556
+ EBSVolume :
557
+ Description : Size of provisioned EBS volume
558
+ Value : !GetAtt SizeCalculate.Value
559
+
514
560
DNSName :
515
561
Description : Public DNS name
516
562
Value : !GetAtt DLEInstance.PublicDnsName
@@ -538,3 +584,4 @@ Outputs:
538
584
Value : !Sub
539
585
- ' ssh -N -L CLONE_PORT:${DNSName}:CLONE_PORT -i YOUR_PRIVATE_KEY ubuntu@${DNSName}'
540
586
- DNSName : !GetAtt DLEInstance.PublicDnsName
587
+
0 commit comments