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


6 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
  4. How do I get money back from Scammers? Reach out Recovery Masters.

    I must give special thanks to Recovery Masters,Specialised hackers in Cryptocurrency Recovery  and lost Bitcoin wallet tracing,My wife and I happened to be scammed by an online scammer who claimed to be professional and knowledgeable in the field investments.I and my wife had agreed to invest our savings pounds worth $623,400 in form of Crypto. This scammer persuaded us to invest in an online platform called Cryptos-seed.com.''I was persuaded to deposit the funds to platform that would generate us much profits on a daily basis.The profits generated significantly,but on asking on how my withdrawal of the funds,the swindler provided multiple excuses and was asking me to invest more funds.On search on how to recover The lost funds I came through Recovery Masters who were able to recover a significant portion of the lost funds.Contact them through; Mail Recoverymasters@email.cz                         Whatspp; 1(204){ 819}-{5505}

    ReplyDelete
  5. Victim of a BTC Scam? Contact Ultimate Hacker Jerry to recover your Lost Bitcoin.

    Have you ever been a victim of a scam? or have you Suffered a loss from a Fraudulent Ponzi Scheme? I implore you to Contact Ultimate Hacker Jerry, A Certified hacker and Lost Crypto Recovery Expert. I once fell victim to an online imposter who convinced me to invest in a phoney Cryptocurrency scheme by claiming to have made large profits from the plan. My Trezor wallet contained $219,100 in Crypto that I lost, I had been reporting to the Authorities tirelessly for a longtime without getting assistance before I finally got in touch with Ultimate Hacker Jerry. Fortunately after a serious conversation with Ultimate Hacker Jerry all my funds were recovered back.
    I recommend this Expert to any victim who has lost Crypto to any fake online Ponzi Scheme..

    Get in touch with ULTIMATE HACKER JERRY
    Through ; Mail (Ultimatehackerjerry@seznam. cz)
    WhatsAp, (+1,5/20,2827,15,1)

    ReplyDelete