Cross database query between Google SQL instances PostgreSQL

Topic: Cross-database query between Google SQL instances PostgreSQL


Cross-database query between Google SQL instances PostgreSQL | GCP SQL Tutorial 2022, in this article we are going to learn Cross database query between Google SQL instances PostgreSQL.

Script used in demo:

create database sales_asia
create database sales_europe
create table public.AsiaSale(id int, name varchar(100), region varchar(100))
insert into public.AsiaSale values(1,'aamir','Asia')
Select * From public.AsiaSale create table public.EuropeSale(id int, name varchar(100), region varchar(100))
insert into public.EuropeSale values(2,'lisa','Europe')
Select * From public.europesale -- we want to execute union query in sales_asia database that should get data from sales_europe.public.EuropeSale table.
Select * From public.europesale
union all
select * from public.AsiaSale 1) Set up a Foreign User-- Do this on DB from which you would like to read the tables
CREATE USER fdwuser WITH PASSWORD 'test123$';
GRANT USAGE ON SCHEMA PUBLIC TO fdwuser;
GRANT SELECT ON europesale TO fdwuser; --Check the list of Tables
select * from information_schema.tables where table_name like '%sale%' 2) Create the Extension
CREATE EXTENSION postgres_fdw;
select * from pg_extension; 3) Create the Foreign Server
CREATE SERVER secondrydb_srv FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '34.67.244.181', port '5432', dbname 'sales_europe');
Select * From pg_foreign_server; 4) Create User Mapping
CREATE USER MAPPING FOR postgres SERVER secondrydb_srv OPTIONS(user 'fdwuser',password 'test123$');
Select * From pg_user_mappings 5) Grant the Local User Access to the Foreign Data Wrapper
GRANT USAGE ON FOREIGN SERVER secondrydb_srv TO postgres; 6) Import the Foreign Schema or Tables
IMPORT FOREIGN SCHEMA public LIMIT TO (europesale) FROM SERVER secondrydb_srv INTO public; Select * From public.europesale
union all
select * from public.AsiaSale


Video Demo: Cross database query between Google SQL instances PostgreSQL


3 comments:

  1. We will always be grateful to you and will share your hard-written article with our friends too. https://www.ayushibosus.com/ | Mumbai

    ReplyDelete
  2. πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–πŸ–
    I and my household have been blessed through an Expert Forex trader Mr Mark Toray who I came across while searching for top Bitcoin entrepreneurs. He traded for me and also gave me lessons on how to trade with his Forex/Binary trading company where I earned $10,500 in just 7 days, you also want to be bill free? Do well and reach out to him via his Email: Marktoray8@gmail.com, Telegram: @Mark4toray_fx

    ReplyDelete
  3. Fullz with CC Info (USA, UK, CAN)
    USA FULLZ (SSN DOB DL) & HIGH CREDIT SCORES FULLZ
    Track 101 & 202 Dumps With Pin Codes
    EIN Business Fullz
    PayPal/Office365 Logins
    USA/Canada Photo I.D's/Passports
    Bank Logins

    Here you can DM me Guy's
    IcQ - 752822040
    TG/icq - @killhacks
    Wickr/Skype - peeterhacks

    Contact with full potential
    Many More stuff will be provided on demand
    Will Serve you with Loyalty
    Here we are for you 24by7

    (Te.legram) (@leadsupplier)
    (I/C/Q) (752.822.040)

    ::GADGETS LIST::

    SMTP's/Web-Mailers/PHP-mailers/Alexus-Mailer
    C-panel/RDP's
    S-hells/Bru-tes/Dorks
    Spa-mming To-ols with Guides/Tutorials (package available also)
    PC/Mob/Web/Server Ha-cking Stuff on demand
    Credit/Debit Cards Tuts for Transfers, Cashouts, CC To BTC
    Car-ding (Amazon, PayPal, E-bay, BTC, etc) Updated Tuts
    Flasher/Cracker for Bit.Co*n
    2021 OR 2022 Fr**D B**le
    I.p's & Pro.xies
    Bulk (Netflix/Amazon/Spotify/Coinbase) Acount Logs
    W.eb L-inks D*R* DE*p Updated
    Web Complete Course for D**P & D**K with Video Tuts
    Scri-pting for Sca-m Pages
    Master Class Complete Kal-i Li-nux
    Vi-ruses for Attac-king & Sp-ying
    Senders (Email, SMS, Codes)

    ReplyDelete