---
title: Integrate Postgres with Tiger Cloud | Tiger Data Docs
description: Query other Postgres data bases using foreign data wrappers
---

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

- Other Tiger Cloud services
- PostgreSQL databases outside of Tiger Cloud

If you are using VPC peering, you can create FDWs in your Customer VPC to query a service in your Tiger Cloud project. However, you can’t create FDWs in your Tiger Cloud services to query a data source in your Customer VPC. This is because Tiger Cloud VPC peering uses AWS PrivateLink for increased security. See [VPC peering documentation](/docs/deploy/tiger-cloud/tiger-cloud-aws/security/vpc/index.md) for additional details.

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

## Prerequisites

To follow the steps on this page:

- Create a target [Tiger Cloud service](/docs/get-started/quickstart/create-service/index.md) with the Real-time analytics capability.

  You need [your connection details](/docs/integrate/find-connection-details/index.md). This procedure also works for [self-hosted TimescaleDB](/docs/get-started/choose-your-path/install-timescaledb/index.md).

## Query another data source

To query another data source:

- [Tiger Cloud](#tab-panel-632)
- [Self-hosted TimescaleDB](#tab-panel-633)

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

1. **Connect to your service**

   See [how to connect](/docs/build/data-management/run-queries-from-tiger-console/index.md).

2. **Create a server**

   Run the following command using your [connection details](/docs/integrate/find-connection-details/index.md):

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

3. **Create user mapping**

   Run the following command using your [connection details](/docs/integrate/find-connection-details/index.md):

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

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

   - Import the whole schema:

     ```
     CREATE SCHEMA foreign_stuff;


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

   - Alternatively, import a limited number of tables:

     ```
     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:

     ```
     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;
     ```

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:

```
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;
```

You create PostgreSQL FDWs with the `postgres_fdw` extension. See [documentation](https://www.postgresql.org/docs/current/postgres-fdw.html) on how to enable it.

1. **Connect to your database**

   Use [`psql`](/docs/integrate/query-administration/psql/index.md) to connect to your database.

2. **Create a server**

   Run the following command using your [connection details](/docs/integrate/find-connection-details/index.md):

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

3. **Create user mapping**

   Run the following command using your [connection details](/docs/integrate/find-connection-details/index.md):

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

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

   - Import the whole schema:

     ```
     CREATE SCHEMA foreign_stuff;


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

   - Alternatively, import a limited number of tables:

     ```
     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:

     ```
     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;
     ```
