-
Notifications
You must be signed in to change notification settings - Fork 15
How to stage bigquery_fdw on a test instance
Gabriel Bordeaux edited this page Jan 16, 2018
·
4 revisions
If you would like to stage bigquery_fdw
on a test instance before installing it on your dev/production servers, here is a quick how-to:
Stage a new Debian/Ubuntu instance on your preferred cloud provider.
apt-get update
apt-get -y install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
apt-get update
apt-get -y install postgresql-10
apt-get update
apt-get -y install git make gcc python3-dev python3-setuptools postgresql-server-dev-10
easy_install3 pip
pip3 install --upgrade setuptools
cd
git clone git://github.com/Kozea/Multicorn.git && cd Multicorn
export PYTHON_OVERRIDE=python3
make && make install
pip3 install bigquery-fdw
cd
git clone git://github.com/gabfl/bigquery_fdw.git && cd bigquery_fdw
python3 setup.py install
Create a BigQuery "Service Account" (see https://github.com/gabfl/bigquery_fdw/blob/master/docs/service_account.md) and save it to /opt/bigquery_fdw/user.json
:
mkdir /opt/bigquery_fdw
nano /opt/bigquery_fdw/user.json # <-- fill with BigQuery Json
su postgres
psql
-- Create a database called `fdw`
CREATE DATABASE fdw;
-- Connect to the database
\c fdw
-- Create extention
CREATE EXTENSION multicorn;
-- Create connector to bigquery_fdw
CREATE SERVER bigquery_srv FOREIGN DATA WRAPPER multicorn
OPTIONS (
wrapper 'bigquery_fdw.fdw.ConstantForeignDataWrapper'
);
-- Create a table to match your bigquery table
CREATE FOREIGN TABLE my_bigquery_table (
column1 text,
column2 bigint
) SERVER bigquery_srv
OPTIONS (
fdw_dataset 'my_dataset',
fdw_table 'my_table',
fdw_key '/opt/bigquery_fdw/user.json'
);
-- Query your table
SELECT *
FROM my_bigquery_table
WHERE [...]
LIMIT 10;