Skip to content

Instantly share code, notes, and snippets.

View aamir814's full-sized avatar

Aamir Haroon aamir814

View GitHub Profile
@aamir814
aamir814 / upgrade-csql-dms.md
Last active June 11, 2025 21:18
Upgrade Cloud SQL PostgreSQL using DMS

Introduction

The following steps show how to upgrade Cloud SQL PostgreSQL to a newer version using Google Cloud DMS. A few interesting observations that were made are:

  • You can write to the destination database, but the cloudsqlexternalsync user owns all objects. You must create users/roles and manually run grant statements to match the source.
  • During the promotion, the target database restarts.
  • The drop/create/grant statements ran during promotion [1] are here.
  • This screenshot shows grants after promotion [2]. They don't match the source instance. Here is a good blog post that talks about this [3].
  • In optimal settings, DMS creates two subscriptions per database (max of 10 subscriptions). The more subscriptions you have, the longer it can take to clean up during the promotion.
  • This screenshot [4] shows that I was able to insert data into the destination database after applying appropriate grants while the migration job was in the CDC phase.

[1]

@aamir814
aamir814 / pg-test-replication-slot-failover.sh
Last active December 16, 2024 19:42
Test sync_replication_slot to keep the logical replication running during a failover
#!/usr/bin/env bash
#####################################################################
# Purpose:
# The following steps show how to use the new PostgreSQL parameter
# sync_replication_slot introduced in version 17 to keep logical
# replication running during a failover or major upgrade.
#
# The setup includes three RDS PostgreSQL instances: Primary (PRI),
# Read Replica (RR), and Logical Replica (LR). After successfully
@aamir814
aamir814 / csql-mysql-to-bigquery.sh
Created August 8, 2024 18:54
Transfer Data (CDC) from Cloud SQL (MySql) with Private IP to BigQuery using Datastream - Demo
#!/usr/bin/env bash
#####################################################################
# Purpose: Following steps show how to connect datastream to a Cloud
# SQL instance with private IP. These steps can be used to
# quickly demo data transfer from Cloud SQL to BigQuery.
#
# Assumption:
# * Google cloud project exists with network setup as desired.
# * all the necessary privileges have been granted to create
@aamir814
aamir814 / gcp-msc-api-test.py
Last active March 28, 2024 18:15
Example script on how to use Cloud Monitoring Metric Service Client in python.
#####################################################################
# Purpose: Following is an example on how to use Google Cloud Monitoring
# Metric Service Client using timeseries to get CPU metric
# for specified Cloud SQL instances in a project with aggregated
# mean value over the last five minuets.
#
# The Service account must have following permissions:
# * roles/monitoring.viewer
# * roles/cloudsql.viewer
# * Service Account Token Creator
@aamir814
aamir814 / alloyDB-cpbr.sh
Created February 9, 2024 18:27
AlloyDB corss-project backup/restore
#!/usr/bin/env bash
#####################################################################
# Purpose: Following is an example on how to restore AlloyDB Cluster
# cross project
# For CLOUD SQL backup/restore cross project, please see:
# https://gist.github.com/anorth848/724808332e4d3e699eb9a05411e59e5e
#
# Assumption:
# Source and target Google Projects exist
@aamir814
aamir814 / rds-mysql-export-csv.sh
Created November 7, 2023 22:46
Install Percona Toolkit and Export Mysql Table in CSV Format
#!/usr/bin/env bash
#####################################################################
# Purpose: Following are commands needed to install Percona tool kit on
# Amazon Linux 2023 AMI. It also shows how to export data from MySQL table
# into CSV format.
#
# Assumption: You have EC2 instance (Amazon Linux 2023 AMI) up and
# running and you can ssh into it.
# You have RDS MySQL (or Aurora MySQL) up and running
@aamir814
aamir814 / gcp-csql-psc.sh
Last active January 16, 2025 18:22
Connect to a Cloud SQL instance using Private Service Connect
#!/usr/bin/env bash
#####################################################################
# Purpose: Following is an example on how to connect to Cloud SQL instance
# from different VPC using Private Service Connect. I followed
# the instructions mentioned in Google document
# (1st URL in refrence section). Created two VPCs
#
# REFERENCES
# - https://cloud.google.com/sql/docs/postgres/configure-private-service-connect