InfluxDB Foreign Data Wrapper for PostgreSQL
This PostgreSQL extension is a Foreign Data Wrapper (FDW) for InfluxDB.
The current version can work with PostgreSQL 9.6, 10, 11, 12 and 13. Currently this FDW supports InfluxDB 1.x series only.
Go version should be 1.10.4 or later.
Install InfluxDB Go client library
go get github.com/influxdata/influxdb1-client/v2
Add a directory of pg_config to PATH and build and install influxdb_fdw.
make USE_PGXS=1 with_llvm=no make install USE_PGXS=1 with_llvm=no
with_llvm=no is necessary to disable llvm bit code generation when PostgreSQL is configured with --with-llvm because influxdb_fdw use go code and cannot be compiled to llvm bit code.
If you want to build influxdb_fdw in a source tree of PostgreSQL instead, use
make with_llvm=no make install with_llvm=no
CREATE EXTENSION influxdb_fdw;
CREATE SERVER influxdb_server FOREIGN DATA WRAPPER influxdb_fdw OPTIONS (dbname 'mydb', host 'http://localhost', port '8086') ;
Create user mapping
CREATE USER MAPPING FOR CURRENT_USER SERVER influxdb_server OPTIONS(user 'user', password 'pass');
Create foreign table
You need to declare a column named "time" to access InfluxDB time column.
CREATE FOREIGN TABLE t1(time timestamp with time zone , tag1 text, field1 integer) SERVER influxdb_server OPTIONS (table 'measurement1');
You can use "tags" option to specify tag keys of a foreign table.
CREATE FOREIGN TABLE t2(tag1 text, field1 integer, tag2 text, field2 integer) SERVER influxdb_server OPTIONS (tags 'tag1, tag2');
Import foreign schema
IMPORT FOREIGN SCHEMA public FROM SERVER influxdb_server INTO public;
Access foreign table
SELECT * FROM t1;
- InfluxDB FDW supports pushed down some aggregate functions: count, stddev, sum, max, min.
- InfluxDB FDW supports INSERT, DELETE statements.
time_textcolumn can used for INSERT, DELETE statements.
timecolumn can express timestamp with precision down to microseconds.
time_textcolumn can express timestamp with precision down to nanoseconds.
- WHERE clauses including timestamp, interval and
now()functions are pushed down.
- LIMIT...OFFSET clauses are pushed down when there is LIMIT clause only or both LIMIT and OFFSET.
- UPDATE is not supported.
- WITH CHECK OPTION constraints is not supported. Following limitations originate from data model and query language of InfluxDB.
- Result sets have different number of rows depending on specified target list.
SELECT field1 FROM t1and
SELECT field2 FROM t1returns different number of rows if the number of points with field1 and field2 are different in InfluxDB database.
- Timestamp precision may be lost because timestamp resolution of PostgreSQL is microseconds while that of InfluxDB is nanoseconds.
- Conditions like
WHERE time + interval '1 day' < now()do not work. Please use
WHERE time < now() - interval '1 day'.
When a query to foreign tables fails, you can find why it fails by seeing a query executed in InfluxDB with
Opening issues and pull requests on GitHub are welcome.
Copyright (c) 2018 - 2021, TOSHIBA Corporation
Copyright (c) 2011 - 2016, EnterpriseDB Corporation
Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.
LICENSE file for full details.