Skip to content

Latest commit

 

History

History
108 lines (78 loc) · 2.55 KB

File metadata and controls

108 lines (78 loc) · 2.55 KB

GSP1085 - Migrating to AlloyDB from PostgreSQL Using PostgreSQL Tools

Task 1. Verify Data in Source Instance for Migration

  1. Navigation menu > Compute Engine > VM instances

  2. Connect ke instance pg14-source using SSH

  3. Buka psql dengan command sudo -u postgres psql

  4. Cek table yang ada dengan command \dt

  5. Cek jumlah baris

    select count (*) as countries_row_count from countries;
    select count (*) as departments_row_count from departments;
    select count (*) as employees_row_count from employees;
    select count (*) as jobs_row_count from jobs;
    select count (*) as locations_row_count from locations;
    select count (*) as regions_row_count from regions;
  6. \q untuk keluar dari psql

Task 2. Create a database DMP file using pg_dump

  1. Dump database dengan command

    sudo -u postgres pg_dump -Fc postgres > pg14_source.DMP
  2. Cek file yang sudah dibuat dengan command

    ls -l -h pg14_source.DMP
  3. Migrate DMP file ke bucket dengan command

    gsutil cp pg14_source.DMP gs://qwiklabs-gcp-02-61e160a13a91/pg14_source.DMP

Task 3. Import DMP file using pg_restore

  1. Navigation menu > Databases > AlloyDB for PostgreSQL > Clusters, copy ip address dari lab-instance 10.91.0.2

  2. Navigation menu > Compute Engine > VM instances, connect ke instance alloydb-client menggunakan SSH

  3. Set environment variable

    export ALLOYDB=ALLOYDB_ADDRESS
  4. Simpan ke AlloyDB client VM

    echo $ALLOYDB  > alloydbip.txt
  5. Cek Table yang ada di AlloyDB dan quit

    \dt
    \q
  6. Download DMP file yang sudah diupload ke bucket

    gsutil cp  gs://qwiklabs-gcp-02-61e160a13a91/pg14_source.DMP pg14_source.DMP
  7. Buat TOC file

    pg_restore -l  pg14_source.DMP | sed -E 's/(.* EXTENSION )/; \1/g' >  pg14_source_toc.toc
  8. Restore database

    pg_restore -h $ALLOYDB -U postgres \
        -d postgres \
        -L pg14_source_toc.toc \
        pg14_source.DMP
  9. Masuk ke postgresql

    psql -h $ALLOYDB -U postgres
  10. Cek table yang ada

    \dt
  11. Cek jumlah baris

    select count (*) as countries_row_count from countries;
    select count (*) as departments_row_count from departments;
    select count (*) as employees_row_count from employees;
    select count (*) as jobs_row_count from jobs;
    select count (*) as locations_row_count from locations;
    select count (*) as regions_row_count from regions;