Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
atovpeko committed Feb 11, 2025
1 parent 252992d commit dd28d93
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 133 deletions.
99 changes: 99 additions & 0 deletions _partials/_foreign-data-wrappers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
You use foreign data wrappers (FDWs) to query external data sources from a $SERVICE_LONG. These external data sources can be one of the following:

- $SERVICE_LONGs
- PostgreSQL databases outside of $CLOUD_LONG

If you are using $VPC peering, you can create FDWs in your Customer VPC to query a $SERVICE_SHORT in your $CLOUD_LONG project. However, you can't create FDWs in your $SERVICE_LONGs to query a data source in your Customer VPC. This is because $CLOUD_LONG $VPC peering uses AWS PrivateLink for increased security. See [VPC peering documentation][vpc-peering] for additional details.

FDWs are particularly useful if you manage multiple $SERVICE_LONGs with different capabilities, and need to seamlessly access and merge regular and time-series data.

## Query another data source

You create FDWs with the `postgres_fdw` extension, which is enabled by default.

<Procedure>

To query another data source, run the following queries in the [SQL editor][sql-editor]:

1. **Create a server:**

```sql
CREATE SERVER myserver
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'serviceID.projectID.tsdb.cloud.timescale.com', dbname 'tsdb', port '30702');
```

1. **Create user mapping:**

```sql
CREATE USER MAPPING FOR tsdbadmin
SERVER myserver
OPTIONS (user 'tsdbadmin', password 'mysupersecurepassword');
```

1. **Import a foreign schema (recommended) or create a foreign table:**

- Import the whole schema:

```sql
CREATE SCHEMA foreign_stuff;

IMPORT FOREIGN SCHEMA public
FROM SERVER myserver
INTO foreign_stuff ;
```

- Alternatively, import a limited number of tables:

```sql
CREATE SCHEMA foreign_stuff;
IMPORT FOREIGN SCHEMA public
LIMIT TO (table1, table2)
FROM SERVER myserver
INTO foreign_stuff;
```

- Create a foreign table. Skip if you are importing a schema:

```sql
CREATE FOREIGN TABLE films (
code char(5) NOT NULL,
title varchar(40) NOT NULL,
did integer NOT NULL,
date_prod date,
kind varchar(10),
len interval hour to minute
)
SERVER film_server;
```

</Procedure>


A user with the `tsdbadmin` role assigned already has the required `USAGE` permission to create FDWs. You can enable another user, without the `tsdbadmin` role assigned, to query foreign data. To do so, explicitly grant the permission:

```sql
CREATE USER grafana;
GRANT grafana TO tsdbadmin;
CREATE SCHEMA fdw AUTHORIZATION grafana;
CREATE SERVER db1 FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'serviceID.projectID.tsdb.cloud.timescale.com', dbname 'tsdb', port '30702');
CREATE USER MAPPING FOR grafana SERVER db1
OPTIONS (user 'tsdbadmin', password 'mysupersecurepassword');
GRANT USAGE ON FOREIGN SERVER db1 TO grafana;
SET ROLE grafana;
IMPORT FOREIGN SCHEMA public
FROM SERVER db1
INTO fdw;
```

[vpc-peering]: /use-timescale/:currentVersion:/security/vpc/
[sql-editor]: /getting-started/:currentVersion:/run-queries-from-console/#ops-mode-sql-editor/
13 changes: 13 additions & 0 deletions use-timescale/integrations/foreign-data-wrappers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Query external sources with foreign data wrappers
excerpt: Query any other PostgreSQL database or another Timescale Cloud service from your service by using foreign data wrappers
products: [cloud]
keywords: [integrate, foreign data wrappers, fdw]
tags: [change]
---

import FDW from "versionContent/_partials/_foreign-data-wrappers.mdx";

# Query external sources with foreign data wrappers

<FDW />
45 changes: 23 additions & 22 deletions use-timescale/integrations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@ Some of the most in-demand integrations for $CLOUD_LONG are listed below, with l

## Query and administration

| Name | Description |
|:------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------|
| [Azure Data Studio][ads] | An open-source, cross-platform hybrid data analytics tool designed to simplify the data landscape. |
| [DBeaver][dbeaver] | A free cross-platform database tool for developers, database administrators, analysts, and everyone working with data. |
| [pgAdmin][pgadmin] | A feature-rich open-source administration and development platform for PostgreSQL. |
| [psql][psql] | A terminal-based frontend to PostgreSQL that enables you to type in queries interactively, issue them to PostgreSQL, and see the query results. |
| [qStudio][qstudio] | A modern free SQL editor that provides syntax highlighting, code completion, excel export, charting, and more. |

| Name | Description |
|:----------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------|
| [Azure Data Studio][ads] | Query, manage, visualize, and develop databases across SQL Server, Azure SQL, and PostgreSQL. |
| [DBeaver][dbeaver] | Connect to, manage, query, and analyze multiple database in a single interface with SQL editing, visualization, and administration tools. |
| [pgAdmin][pgadmin] | Manage, query, and administer PostgreSQL databases through a graphical interface. |
| [psql][psql] | Run SQL queries, manage databases, automate tasks, and interact directly with PostgreSQL. |
| [qStudio][qstudio] | Write and execute SQL queries, manage database objects, and analyze data in a user-friendly interface. |
| [Foreign data wrappers][fdw] | Access and query data from external sources as if they were regular PostgreSQL tables. |

## Observability and alerting

| Name | Description |
|:-------------------------------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Amazon Cloudwatch][cloudwatch] | A monitoring and observability service designed to help collect, analyze, and act on data from applications, infrastructure, and services running in AWS and on-premises environments. |
| [Datadog][datadog] | A cloud-based monitoring and analytics platform that provides comprehensive visibility into applications, infrastructure, and systems through real-time monitoring, logging, and analytics. |
| [Grafana][grafana] | An open-source analytics and monitoring solution that enables you to query, visualize, alert on, and explore your metrics, logs. |
| [Prometheus][prometheus] | An open-source monitoring system with a dimensional data model, flexible query language, and a modern alerting approach. |
| [Tableau][tableau] | A popular analytics platform that helps you gain greater intelligence about your business. |
| Name | Description |
|:-------------------------------:|------------------------------------------------------------------------------------------------------------------------------------|
| [Amazon Cloudwatch][cloudwatch] | Collect, analyze, and act on data from applications, infrastructure, and services running in AWS and on-premises environments. |
| [Datadog][datadog] | Gain comprehensive visibility into applications, infrastructure, and systems through real-time monitoring, logging, and analytics. |
| [Grafana][grafana] | Query, visualize, alert on, and explore your metrics and logs. |
| [Prometheus][prometheus] | Track the performance and health of systems, applications, and infrastructure. |
| [Tableau][tableau] | Connect to data sources, analyze data, and create interactive visualizations and dashboards. |


## Configuration and deployment

| Name | Description |
|:---------------------------:|-----------------------------------------------------------------------------------------------------------------------------|
| [Terraform][terraform] | An infrastructure-as-code tool that enables you to safely and predictably provision and manage infrastructure in any cloud. |
| Name | Description |
|:---------------------------:|--------------------------------------------------------------------------|
| [Terraform][terraform] | Safely and predictably provision and manage infrastructure in any cloud. |


## Data engineering and extract, transform, load

| Name | Description |
|:--------------------------------:|-------------------------------------------------------------------------------|
| [Amazon SageMaker][amazon-sagemaker]| Build, train, and deploy ML models into a production-ready hosted environment |
| [Apache Airflow][apache-airflow] | Programmatically author, schedule, and monitor workflows. |
| Name | Description |
|:--------------------------------:|-------------------------------------------------------------------------------------|
| [Amazon SageMaker][amazon-sagemaker]| Build, train, and deploy ML models into a production-ready hosted environment. |
| [Apache Airflow][apache-airflow] | Programmatically author, schedule, and monitor workflows. |
| [AWS Lambda][aws-lambda]| Run code without provisioning or managing servers, scaling automatically as needed. |


Expand All @@ -69,3 +69,4 @@ Some of the most in-demand integrations for $CLOUD_LONG are listed below, with l
[postgresql-integrations]: https://slashdot.org/software/p/PostgreSQL/integrations/
[prometheus]: /use-timescale/:currentVersion:/integrations/prometheus
[amazon-sagemaker]: /use-timescale/:currentVersion:/integrations/amazon-sagemaker
[fdw]: /use-timescale/:currentVersion:/integrations/foreign-data-wrappers
25 changes: 15 additions & 10 deletions use-timescale/page-index/page-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,11 @@ module.exports = [
href: "find-connection-details",
excerpt: "Learn about connecting to your Timescale database",
},
{
title: "Amazon CloudWatch",
href: "cloudwatch",
excerpt: "Integrate Amazon Cloudwatch with Timescale Cloud",
},
{
title: "Amazon SageMaker",
href: "amazon-sagemaker",
Expand All @@ -788,11 +793,6 @@ module.exports = [
href: "apache-airflow",
excerpt: "Integrate Apache Airflow with Timescale products",
},
{
title: "Amazon CloudWatch",
href: "cloudwatch",
excerpt: "Integrate Amazon Cloudwatch with Timescale Cloud",
},
{
title: "AWS Lambda",
href: "aws-lambda",
Expand All @@ -813,6 +813,16 @@ module.exports = [
href: "dbeaver",
excerpt: "Integrate DBeaver with Timescale products",
},
{
title: "Foreign data wrappers",
href: "foreign-data-wrappers",
excerpt: "Query external data sources as regular tables",
},
{
title: "Grafana",
href: "grafana",
excerpt: "Integrate Grafana with Timescale products",
},
{
title: "pgAdmin",
href: "pgadmin",
Expand All @@ -833,11 +843,6 @@ module.exports = [
href: "qstudio",
excerpt: "Integrate qstudio with Timescale products",
},
{
title: "Grafana",
href: "grafana",
excerpt: "Integrate Grafana with Timescale products",
},
{
title: "Tableau",
href: "tableau",
Expand Down
106 changes: 5 additions & 101 deletions use-timescale/schema-management/foreign-data-wrappers.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,16 @@
---
title: Foreign data wrappers
excerpt: Query PostgreSQL databases within or outside Timescale
products: [cloud, mst, self_hosted]
keywords: [hypertables, schemas, alter]
products: [cloud]
keywords: [foreign data wrappers, fdw]
tags: [change]
---

# Foreign data wrappers

You use foreign data wrappers (FDWs) to query external data sources from a $SERVICE_LONG. These external data sources can be one of the following:

- $SERVICE_LONGs
- PostgreSQL databases outside of $CLOUD_LONG

If you are using $VPC peering, you can create FDWs in your Customer VPC to query a $SERVICE_SHORT in your $CLOUD_LONG project. However, you can't create FDWs in your $SERVICE_LONGs to query a data source in your Customer VPC. This is because $CLOUD_LONG $VPC peering uses AWS PrivateLink for increased security. See [VPC peering documentation][vpc-peering] for additional details.

FDWs are particularly useful if you manage multiple $SERVICE_LONGs with different capabilities, and need to seamlessly access and merge regular and time-series data.

## Query another data source

You create FDWs with the `postgres_fdw` extension, which is enabled by default.

<Procedure>

To query another data source, run the following queries in the [SQL editor][sql-editor]:

1. **Create a server:**

```sql
CREATE SERVER myserver
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'serviceID.projectID.tsdb.cloud.timescale.com', dbname 'tsdb', port '30702');
```

1. **Create user mapping:**

```sql
CREATE USER MAPPING FOR tsdbadmin
SERVER myserver
OPTIONS (user 'tsdbadmin', password 'mysupersecurepassword');
```

1. **Import a foreign schema (recommended) or create a foreign table:**

- Import the whole schema:
import FDW from "versionContent/_partials/_foreign-data-wrappers.mdx";

```sql
CREATE SCHEMA foreign_stuff;

IMPORT FOREIGN SCHEMA public
FROM SERVER myserver
INTO foreign_stuff ;
```

- Alternatively, import a limited number of tables:

```sql
CREATE SCHEMA foreign_stuff;
IMPORT FOREIGN SCHEMA public
LIMIT TO (table1, table2)
FROM SERVER myserver
INTO foreign_stuff;
```

- Create a foreign table. Skip if you are importing a schema:

```sql
CREATE FOREIGN TABLE films (
code char(5) NOT NULL,
title varchar(40) NOT NULL,
did integer NOT NULL,
date_prod date,
kind varchar(10),
len interval hour to minute
)
SERVER film_server;
```

</Procedure>


A user with the `tsdbadmin` role assigned already has the required `USAGE` permission to create FDWs. You can enable another user, without the `tsdbadmin` role assigned, to query foreign data. To do so, explicitly grant the permission:

```sql
CREATE USER grafana;
GRANT grafana TO tsdbadmin;
CREATE SCHEMA fdw AUTHORIZATION grafana;
CREATE SERVER db1 FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'serviceID.projectID.tsdb.cloud.timescale.com', dbname 'tsdb', port '30702');
CREATE USER MAPPING FOR grafana SERVER db1
OPTIONS (user 'tsdbadmin', password 'mysupersecurepassword');
GRANT USAGE ON FOREIGN SERVER db1 TO grafana;
SET ROLE grafana;
IMPORT FOREIGN SCHEMA public
FROM SERVER db1
INTO fdw;
```
# Foreign data wrappers

[vpc-peering]: /use-timescale/:currentVersion:/security/vpc/
[sql-editor]: /getting-started/:currentVersion:/run-queries-from-console/#ops-mode-sql-editor/
<FDW />



Expand Down

0 comments on commit dd28d93

Please sign in to comment.