- Enable service networking API
-
Connect instance with SSH
-
Install extension
sudo apt install postgresql-13-pglogical
-
Download tambahan
sudo su - postgres -c "gsutil cp gs://cloud-training/gsp918/pg_hba_append.conf ." sudo su - postgres -c "gsutil cp gs://cloud-training/gsp918/postgresql_append.conf ." sudo su - postgres -c "cat pg_hba_append.conf >> /etc/postgresql/13/main/pg_hba.conf" sudo su - postgres -c "cat postgresql_append.conf >> /etc/postgresql/13/main/postgresql.conf" sudo systemctl restart postgresql@13-main
-
Masuk ke psql
sudo su - postgres psql
-
Buat extension
\c postgres; CREATE EXTENSION pglogical; \c orders; CREATE EXTENSION pglogical; \c gmemegen_db; CREATE EXTENSION pglogical;
-
buat user
CREATE USER migration_admin PASSWORD 'DMS_1s_cool!'; ALTER DATABASE orders OWNER TO migration_admin; ALTER ROLE migration_admin WITH REPLICATION;
-
Kasih permission
\c postgres; GRANT USAGE ON SCHEMA pglogical TO migration_admin; GRANT ALL ON SCHEMA pglogical TO migration_admin; GRANT SELECT ON pglogical.tables TO migration_admin; GRANT SELECT ON pglogical.depend TO migration_admin; GRANT SELECT ON pglogical.local_node TO migration_admin; GRANT SELECT ON pglogical.local_sync_status TO migration_admin; GRANT SELECT ON pglogical.node TO migration_admin; GRANT SELECT ON pglogical.node_interface TO migration_admin; GRANT SELECT ON pglogical.queue TO migration_admin; GRANT SELECT ON pglogical.replication_set TO migration_admin; GRANT SELECT ON pglogical.replication_set_seq TO migration_admin; GRANT SELECT ON pglogical.replication_set_table TO migration_admin; GRANT SELECT ON pglogical.sequence_state TO migration_admin; GRANT SELECT ON pglogical.subscription TO migration_admin;
\c orders; GRANT USAGE ON SCHEMA pglogical TO migration_admin; GRANT ALL ON SCHEMA pglogical TO migration_admin; GRANT SELECT ON pglogical.tables TO migration_admin; GRANT SELECT ON pglogical.depend TO migration_admin; GRANT SELECT ON pglogical.local_node TO migration_admin; GRANT SELECT ON pglogical.local_sync_status TO migration_admin; GRANT SELECT ON pglogical.node TO migration_admin; GRANT SELECT ON pglogical.node_interface TO migration_admin; GRANT SELECT ON pglogical.queue TO migration_admin; GRANT SELECT ON pglogical.replication_set TO migration_admin; GRANT SELECT ON pglogical.replication_set_seq TO migration_admin; GRANT SELECT ON pglogical.replication_set_table TO migration_admin; GRANT SELECT ON pglogical.sequence_state TO migration_admin; GRANT SELECT ON pglogical.subscription TO migration_admin;
GRANT USAGE ON SCHEMA public TO migration_admin; GRANT ALL ON SCHEMA public TO migration_admin; GRANT SELECT ON public.distribution_centers TO migration_admin; GRANT SELECT ON public.inventory_items TO migration_admin; GRANT SELECT ON public.order_items TO migration_admin; GRANT SELECT ON public.products TO migration_admin; GRANT SELECT ON public.users TO migration_admin;
\c gmemegen_db; GRANT USAGE ON SCHEMA pglogical TO migration_admin; GRANT ALL ON SCHEMA pglogical TO migration_admin; GRANT SELECT ON pglogical.tables TO migration_admin; GRANT SELECT ON pglogical.depend TO migration_admin; GRANT SELECT ON pglogical.local_node TO migration_admin; GRANT SELECT ON pglogical.local_sync_status TO migration_admin; GRANT SELECT ON pglogical.node TO migration_admin; GRANT SELECT ON pglogical.node_interface TO migration_admin; GRANT SELECT ON pglogical.queue TO migration_admin; GRANT SELECT ON pglogical.replication_set TO migration_admin; GRANT SELECT ON pglogical.replication_set_seq TO migration_admin; GRANT SELECT ON pglogical.replication_set_table TO migration_admin; GRANT SELECT ON pglogical.sequence_state TO migration_admin; GRANT SELECT ON pglogical.subscription TO migration_admin;
GRANT USAGE ON SCHEMA public TO migration_admin; GRANT ALL ON SCHEMA public TO migration_admin; GRANT SELECT ON public.meme TO migration_admin;
\c orders; \dt ALTER TABLE public.distribution_centers OWNER TO migration_admin; ALTER TABLE public.inventory_items OWNER TO migration_admin; ALTER TABLE public.order_items OWNER TO migration_admin; ALTER TABLE public.products OWNER TO migration_admin; ALTER TABLE public.users OWNER TO migration_admin; \dt
-
Exit psql
\q exit
Task 2. Create a Database Migration Service connection profile for a stand-alone PostgreSQL database
Navigation menu > Compute Engine > VM instances > postgresql-vm
, copy ip internal = 10.138.0.2
Navigation menu > Database Migration > Connection profiles
+ Create Profile
- Database Engine:
PostgreSQL
- Connection Profile Name:
postgres-vm
- Hostname or IP address:
<internal-ip>
- Port:
5432
- Username:
migration_admin
- Password:
DMS_1s_cool!
i - Region:
us-west1
- Database Engine:
Navigation menu > Database Migration > Migration jobs
+ Create Migration Job
- Migration job name:
vm-to-cloudsql
- Source database engine:
PostgreSQL
- Destination region:
us-west1
- Destination database engine:
Cloud SQL for PostgreSQL
- Migration job type:
Continuous
- Migration job name:
postgres-vm
- Destination instance
- Destination instance ID:
postgresql-cloudsql
- Root password:
supersecret!
- Database version:
Cloud SQL for PostgreSQL 13
- Zone:
us-west1-c
- Instance connectivity:
Private IP
andPublic IP
Use an automatically allocated IP range
- klik
Allocate and connect
- Machine type:
Standard
,1 vCPU, 3.75 GB
- Storage type:
SSD
- Storage capacity:
10 GB
- klik
Create & Continue
- Destination instance ID:
- Tentukan connectivity method
- Connectivity method:
VPC peering
- VPC network:
default
Configure and continue
- Connectivity method:
-
Navigation menu > VPC network > VPC network peering
-
klik
servicenetworking-googleapis-com
-
copy ip range =
10.76.144.0/24
-
Edit
pg_hba.conf
sudo nano /etc/postgresql/13/main/pg_hba.conf
#GSP918 - allow access to all hosts host all all 10.107.176.0/24 md5
-
Restart postgresql
sudo systemctl restart postgresql@13-main
Database Migration Service
Test Job
Create and start job > Create and start