VMware Postgres for Tanzu Application Service 1.1をインストールするメモ
cat <<EOF > additional-vm-extensions-postgres.yml
---
product-name: postgres
resource-config:
postgres-on-demand-broker:
additional_vm_extensions:
- spot-instance
---
EOF
om --env env.yml configure-product -c additional-vm-extensions-postgres.yml
om --env env.yml apply-changes
$ cf marketplace
Getting all service offerings from marketplace in org demo / space demo as admin...
offering plans description broker
postgres micro-2gb, micro-2gb-ha Postgres service to provide on-demand dedicated instances configured as database. postgres-odb
TIP: Use 'cf marketplace -e SERVICE_OFFERING' to view descriptions of individual plans of a given service offering.
git clone https://github.com/making/retrofacto
cd retrofacto
./mvnw clean package -DskipTests
cf create-service postgres micro-2gb retrofacto-db --wait
$ cf service retrofacto-db
Showing info of service retrofacto-db in org demo / space demo as admin...
name: retrofacto-db
guid: 8e535718-da66-434c-9604-77962b839b74
type: managed
broker: postgres-odb
offering: postgres
plan: micro-2gb
tags:
offering tags: postgres, pivotal, on-demand
description: Postgres service to provide on-demand dedicated instances configured as database.
documentation:
dashboard url:
Showing status of last operation:
status: create succeeded
message: Instance provisioning completed
started: 2024-07-03T04:57:59Z
updated: 2024-07-03T04:57:59Z
Showing bound apps:
There are no bound apps for this service instance.
Showing sharing info:
This service instance is not currently being shared.
The "service_instance_sharing" feature flag is disabled for this Cloud Foundry platform.
Service instance sharing is disabled for this service offering.
Showing upgrade status:
There is no upgrade available for this service.
cf push retrofacto -p target/retrofacto-0.1.0-SNAPSHOT.jar --no-start -m 768m -b java_buildpack_offline
cf set-env retrofacto JBP_CONFIG_OPEN_JDK_JRE '{jre: { version: 21.+}}'
cf bind-service retrofacto retrofacto-db
cf start retrofacto
$ cf app retrofacto
Showing health and status for app retrofacto in org demo / space demo as admin...
name: retrofacto
requested state: started
routes: retrofacto.apps.sandbox.aws.maki.lol
last uploaded: Wed 03 Jul 14:07:04 JST 2024
stack: cflinuxfs4
buildpacks:
name version detect output buildpack name
java_buildpack_offline v4.69.0-offline-https://github.com/cloudfoundry/java-buildpack#c294d50b java java
type: web
sidecars:
instances: 1/1
memory usage: 768M
state since cpu memory disk logging details
#0 running 2024-07-03T05:07:45Z 0.4% 279.8M of 768M 271.5M of 1G 0B/s of 16K/s
type: task
sidecars:
instances: 0/0
memory usage: 1024M
There are no running instances of this process.
$ cf logs retrofacto --recent | grep jdbc:
2024-07-03T14:07:34.19+0900 [APP/PROC/WEB/0] OUT {"@timestamp":"2024-07-03T05:07:34.196Z","log.level": "INFO","message":"Database: jdbc:postgresql://q-s0.postgres-instance.services.service-instance-8e535718-da66-434c-9604-77962b839b74.bosh:5432/postgres (PostgreSQL 15.6)","ecs.version": "1.2.0","service.name":"retrofacto","process.thread.name":"main","log.logger":"org.flywaydb.core.FlywayExecutor","traceId":"f9f18f8a3434df010a2ff1025fa1c44b","spanId":"e4fcd3be7759faca"}
$ cf env retrofacto
Getting env variables for app retrofacto in org demo / space demo as admin...
System-Provided:
VCAP_SERVICES: {
"postgres": [
{
"binding_guid": "2e504688-73d7-4e96-b5e7-7062c6c06fa3",
"binding_name": null,
"credentials": {
"credhub-ref": "/c/33D9B881-7A9A-4B92-8B5F-9636582250B0/8e535718-da66-434c-9604-77962b839b74/2e504688-73d7-4e96-b5e7-7062c6c06fa3/credentials"
},
"instance_guid": "8e535718-da66-434c-9604-77962b839b74",
"instance_name": "retrofacto-db",
"label": "postgres",
"name": "retrofacto-db",
"plan": "micro-2gb",
"provider": null,
"syslog_drain_url": null,
"tags": [
"postgres",
"pivotal",
"on-demand"
],
"volume_mounts": []
}
]
}
VCAP_APPLICATION: {
"application_id": "c061f2de-a231-4abf-b51d-e29f92642e35",
"application_name": "retrofacto",
"application_uris": [
"retrofacto.apps.sandbox.aws.maki.lol"
],
"cf_api": "https://api.sys.sandbox.aws.maki.lol",
"limits": {
"fds": 16384
},
"name": "retrofacto",
"organization_id": "4b84793c-f3ea-4a55-92b7-942726aac163",
"organization_name": "demo",
"space_id": "6755b19d-c543-4e0c-a4b3-cd6e7c9c68a3",
"space_name": "demo",
"uris": [
"retrofacto.apps.sandbox.aws.maki.lol"
],
"users": null
}
User-Provided:
JBP_CONFIG_OPEN_JDK_JRE: {jre: { version: 21.+}}
No running env variables have been set
No staging env variables have been set
cf ssh retrofacto cat /proc/<pid>/environ
cf delete-service retrofacto-db --force --wait
cf create-service postgres micro-2gb-ha retrofacto-db --wait
cf bind-service retrofacto retrofacto-db
cf restage retrofacto-db
2024-07-03T15:55:39.46+0900 [APP/PROC/WEB/0] OUT {"@timestamp":"2024-07-03T06:55:39.462Z","log.level": "INFO","message":"Database: jdbc:postgresql://q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh:5432/postgres (PostgreSQL 15.6)","ecs.version": "1.2.0","service.name":"retrofacto","process.thread.name":"main","log.logger":"org.flywaydb.core.FlywayExecutor","traceId":"c2c87b26754f34dbf48945e879d74db3","spanId":"f4dc9f00d324dfb6"}
$ cf ssh retrofacto -c 'dig q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh'
; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45432
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh. IN A
;; ANSWER SECTION:
q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh. 0 IN A 10.0.8.11
q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh. 0 IN A 10.0.10.11
q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh. 0 IN A 10.0.10.10
;; Query time: 0 msec
;; SERVER: 169.254.0.2#53(169.254.0.2) (UDP)
;; WHEN: Wed Jul 03 07:03:14 UTC 2024
;; MSG SIZE rcvd: 437
cf create-service-key retrofacto-db test
$ cf service-key retrofacto-db test
Getting key test for service instance retrofacto-db as admin...
{
"credentials": {
"db": "postgres",
"hosts": [
"q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh"
],
"jdbcUrl": "jdbc:postgresql://q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh:5432/postgres?targetServerType=primary&user=pgadmin&password=NVP092584x137RWj6hSl",
"password": "NVP092584x137RWj6hSl",
"port": 5432,
"uri": "postgresql://pgadmin:NVP092584x137RWj6hSl@q-s0.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh:5432/postgres",
"user": "pgadmin"
}
}
sudo su -
export PATH=/var/vcap/packages/postgres-15.1/bin:$PATH
source /var/vcap/jobs/postgres/bin/pgconfig.sh
# pg_autoctl show state
Name | Node | Host:Port | TLI: LSN | Connection | Reported State | Assigned State
-------+-------+---------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+---------------------+--------------------
node_1 | 1 | 300f38fa-1ea3-45f8-8df2-898ba5d720ff.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh:5432 | 1: 0/509F918 | read-write | primary | primary
node_2 | 2 | 8aa4378a-8a35-4356-aae3-1ca2197bcf64.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh:5432 | 1: 0/509F918 | read-only | secondary | secondary
node_3 | 3 | efbb6f2c-d522-460d-98f9-ef3b9fff0e1b.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh:5432 | 1: 0/509F918 | read-only | secondary | secondary
psql postgres://pgadmin@localhost/postgres -c "show transaction_read_only"
psql postgres://pgadmin:NVP092584x137RWj6hSl@10.0.8.11/postgres -c "show transaction_read_only"
psql postgres://pgadmin:NVP092584x137RWj6hSl@10.0.10.11/postgres -c "show transaction_read_only"
psql postgres://pgadmin:NVP092584x137RWj6hSl@10.0.10.10/postgres -c "show transaction_read_only"
+ psql postgres://pgadmin:NVP092584x137RWj6hSl@10.0.8.11/postgres -c 'show transaction_read_only'
transaction_read_only
-----------------------
off
(1 row)
+ psql postgres://pgadmin:NVP092584x137RWj6hSl@10.0.10.11/postgres -c 'show transaction_read_only'
transaction_read_only
-----------------------
on
(1 row)
+ psql postgres://pgadmin:NVP092584x137RWj6hSl@10.0.10.10/postgres -c 'show transaction_read_only'
transaction_read_only
-----------------------
on
(1 row)
# pg_autoctl show state
Name | Node | Host:Port | TLI: LSN | Connection | Reported State | Assigned State
-------+-------+---------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+---------------------+--------------------
node_1 | 1 | 300f38fa-1ea3-45f8-8df2-898ba5d720ff.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh:5432 | 2: 0/50A6E50 | read-only | secondary | secondary
node_2 | 2 | 8aa4378a-8a35-4356-aae3-1ca2197bcf64.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh:5432 | 2: 0/50A6E50 | read-write | primary | primary
node_3 | 3 | efbb6f2c-d522-460d-98f9-ef3b9fff0e1b.postgres-instance.services.service-instance-c8a15550-4a76-4515-9291-ebfb481cc0d3.bosh:5432 | 2: 0/50A6E50 | read-only | secondary | secondary
+ psql postgres://pgadmin:NVP092584x137RWj6hSl@10.0.8.11/postgres -c 'show transaction_read_only'
transaction_read_only
-----------------------
on
(1 row)
+ psql postgres://pgadmin:NVP092584x137RWj6hSl@10.0.10.11/postgres -c 'show transaction_read_only'
transaction_read_only
-----------------------
on
(1 row)
+ psql postgres://pgadmin:NVP092584x137RWj6hSl@10.0.10.10/postgres -c 'show transaction_read_only'
transaction_read_only
-----------------------
off
(1 row)
2024-07-03T17:25:06.07+0900 [APP/PROC/WEB/0] OUT {"@timestamp":"2024-07-03T08:25:06.075Z","log.level": "WARN","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@45d983c0 (This connection has been closed.). Possibly consider using a shorter maxLifetime value.","ecs.version": "1.2.0","service.name":"retrofacto","process.thread.name":"tomcat-handler-231","log.logger":"com.zaxxer.hikari.pool.PoolBase","traceId":"f8c73b7183c74e5c5e26910ca59941e1","spanId":"b984566ea76a5d88"}