Skip to content

Commit

Permalink
Duplicated PostgreSQL FDW to Integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
atovpeko authored Feb 14, 2025
1 parent 0179a0c commit 05bc300
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 136 deletions.
196 changes: 196 additions & 0 deletions _partials/_foreign-data-wrappers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import IntegrationPrereqs from "versionContent/_partials/_integration-prereqs.mdx";

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

- Other $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.

PostgreSQL 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.

## Prerequisites

<IntegrationPrereqs />

## Query another data source

To query another data source:

<Tabs label="Query another data source">

<Tab title="Timescale Cloud">

You create PostgreSQL FDWs with the `postgres_fdw` extension, which is enabled by default in $CLOUD_LONG.

<Procedure>

1. **Connect to your service**

See [how to connect][connect].

1. **Create a server**

Run the following command using your [connection details][connection-info]:

```sql
CREATE SERVER myserver
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host '<host>', dbname 'tsdb', port '<port>');
```

1. **Create user mapping**

Run the following command using your [connection details][connection-info]:

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

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 PostgreSQL FDWs. You can enable another user, without the `tsdbadmin` role assigned, to query foreign data. To do so, explicitly grant the permission. For example, for a new `grafana` user:

```sql
CREATE USER grafana;
GRANT grafana TO tsdbadmin;
CREATE SCHEMA fdw AUTHORIZATION grafana;
CREATE SERVER db1 FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host '<host>', dbname 'tsdb', port '<port>');
CREATE USER MAPPING FOR grafana SERVER db1
OPTIONS (user 'tsdbadmin', password '<password>');
GRANT USAGE ON FOREIGN SERVER db1 TO grafana;
SET ROLE grafana;
IMPORT FOREIGN SCHEMA public
FROM SERVER db1
INTO fdw;
```

</Tab>

<Tab title="Self-hosted TimescaleDB">

You create PostgreSQL FDWs with the `postgres_fdw` extension. See [documenation][enable-fdw-docs] on how to enable it.

<Procedure>

1. **Connect to your database**

Use [`psql`][psql] to connect to your database.

1. **Create a server**

Run the following command using your [connection details][connection-info]:

```sql
CREATE SERVER myserver
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host '<host>', dbname '<database_name>', port '<port>');
```

1. **Create user mapping**

Run the following command using your [connection details][connection-info]:

```sql
CREATE USER MAPPING FOR postgres
SERVER myserver
OPTIONS (user 'postgres', password '<password>');
```

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>

</Tab>

</Tabs>

[vpc-peering]: /use-timescale/:currentVersion:/security/vpc/
[sql-editor]: /getting-started/:currentVersion:/run-queries-from-console/#ops-mode-sql-editor/
[connect]: /getting-started/:currentVersion:/run-queries-from-console/
[connection-info]: /use-timescale/:currentVersion:/integrations/find-connection-details/
[enable-fdw-docs]: https://www.postgresql.org/docs/current/postgres-fdw.html
[psql]: /use-timescale/:currentVersion:/integrations/psql/
2 changes: 1 addition & 1 deletion use-timescale/integrations/amazon-sagemaker.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This page shows you how to integrate Amazon Sagemaker with a $SERVICE_LONG.

<IntegrationPrereqs />

* Setup an [AWS Account][aws-sign-up]
* Set up an [AWS Account][aws-sign-up]

## Prepare your $SERVICE_LONG to ingest data from SageMaker

Expand Down
4 changes: 2 additions & 2 deletions use-timescale/integrations/aws-lambda.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Integrate AWS Lambda with $CLOUD_LONG
excerpt: ADD
title: Integrate AWS Lambda with Timescale Cloud
excerpt: With AWS Lambda, you can run code without provisioning or managing servers, and scale automatically. Integrate AWS Lambda with Timescale Cloud and inject data into your service
products: [cloud, mst, self_hosted]
keywords: [connect, integrate, aws, lambda]
---
Expand Down
2 changes: 1 addition & 1 deletion use-timescale/integrations/find-connection-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Retrieve the connection details for your $SERVICE_LONG:

<Tab title="Self-hosted TimescaleDB">

Find the connection details in the [PostgreSQL configuration file][postgres-config] or by asking your database administrator.
Find the connection details in the [PostgreSQL configuration file][postgres-config] or by asking your database administrator. The `postgres` superuser, created during PostgreSQL installation, has all the permissions required to run procedures in this documentation. However, it is recommended to create other users and assign permissions on the need-only basis.

</Tab>

Expand Down
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. |
| [PostgreSQL][postgresql] | 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
[postgresql]: /use-timescale/:currentVersion:/integrations/postgresql
13 changes: 13 additions & 0 deletions use-timescale/integrations/postgresql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Integrate with PostgreSQL
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";

# Integrate PostgreSQL with $CLOUD_LONG

<FDW />
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,11 +813,21 @@ module.exports = [
href: "dbeaver",
excerpt: "Integrate DBeaver with Timescale products",
},
{
title: "Grafana",
href: "grafana",
excerpt: "Integrate Grafana with Timescale products",
},
{
title: "pgAdmin",
href: "pgadmin",
excerpt: "Integrate pgAdmin with Timescale products",
},
{
title: "PostgreSQL",
href: "postgresql",
excerpt: "Integrate PostgreSQL with Timescale Cloud",
},
{
title: "Prometheus",
href: "prometheus",
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
Loading

0 comments on commit 05bc300

Please sign in to comment.