---
title: PostgreSQL Integration Guide
slug: manufacturing-connect-edge/postgresql-integration-guide
docTags: 
createdAt: 2022-11-24T18:29:38.000Z
---

Review the following guide for setting up an integration between Manufacturing Connect Edge and a PostgreSQL database.&#x20;

# User Scenario

In this guide you will deploy a PostgreSQL database container from Manufacturing Connect Edge and then integrate with the database using the DB-PostgreSQL Server connector. For your specific scenario you may use an external PostgreSQL Server database to set up the integration.&#x20;

For external PostgreSQL databases, refer to the following links to learn more:

- [PostgreSQL Docker Image](https://hub.docker.com/_/postgres)
- [PostgreSQL Documentation](https://www.postgresql.org/docs/)

# Step 1: Add Device

Follow the steps to [Connect a Device](docId\:RFVIJdxz7DBAd8mwbismA). The device will be used to store tags that will be eventually used to create outbound topics in the connector. Make sure to select the **Enable Data Store** checkbox.&#x20;

# Step 2: Add Tags

After connecting the device in Manufacturing Connect Edge, you can [Add Tags](docId\:iOaNZd2AwqnkuppgeE3Eh) to the device. Create tags that you want to use to create outbound topics for the connector.&#x20;

# Step 3: Add PostgreSQL Marketplace Application

:::hint{type="info"}
**Note**: The version used in this use case for PostgreSQL is 9.6.5.
:::

**To add the PostgreSQL Marketplace Application:**

1. In Manufacturing Connect Edge, navigate to **Applications&#x20;**> **Marketplace**.
2. Click **Marketplace List** and select **Default Marketplace Catalog**.
3. Click the **PostgreSQL&#x20;**&#x61;pplication tile.&#x20;
4. From the **Installation script version** drop-down list, select **9.6.5**.&#x20;
5. Enter a name and description for the application. &#x20;
6. Update the database name, username, and password as needed.&#x20;
7. Copy the database name, username, and password and store for reference later.&#x20;
8. Click **Launch**.&#x20;
9. Navigate to **Applications&#x20;**> **Catalog Apps**.&#x20;
   The Postgre application appears, pulls the image, and then starts the application. The  application shows as running.
10. Navigate to **Applications&#x20;**> **Containers**.&#x20;
    The postgre application Container is running.
11. Copy the IP address for the PostgreSQL application.

# Step 4: Add the DB - PostgreSQL Connector

Follow the steps to [Add a Connector](docId\:M2niFNAAdyPHcvZWMCOTo) and select the **DB - PostgreSQL&#x20;**&#x70;rovider.&#x20;

Configure the following parameters.&#x20;

- **Name**: Enter a name for the connector.&#x20;
- **Hostname**: Paste the IP address you copied in Step 3. &#x20;
- **Port**: The PostgreSQL Server port. The default value is **5432**.&#x20;
- **Username**: Paste the username configured in Step 3.&#x20;
- **Password**: Paste the password configured in Step 3.  &#x20;
- **Database**: Paste the database name configured configured in Step 3.&#x20;
- **Table**: Enter **devicehub**. If you are sending data to an existing table, use the corresponding name.
- **Show Mapping**: If you want to send data to a custom table, select this checkbox and unselect *Create table*. See [Work with Tables in SQL Connectors (Create Table and Show Mapping)](docId\:FI9mBipRrRIxufdIHwQl9) to learn more. To add key/value pairs for the custom table, see [Configure Key/Value Pairs](docId\:FI9mBipRrRIxufdIHwQl9).&#x20;
- **Create table**: If you want to send data to an existing table in the default format, or you want to create a new table in the default format, select this checkbox and unselect *Show Mapping*. See [Work with Tables in SQL Connectors (Create Table and Show Mapping)](docId\:FI9mBipRrRIxufdIHwQl9) to learn more.&#x20;
- **Commit timeout**: Enter the transaction commit timeout in (ms).
- **Max transaction size**: Enter the maximum number of messages before a transaction is committed, regardless of timeout parameter.&#x20;
- **Throttling limit**: The maximum number of messages per second to be processed. The default value is zero, which means that there is no limit.&#x20;
- **Persistent storage**: When enabled, this will cause messages to undergo a store-and-forward procedure. Messages will be stored within Manufacturing Connect Edge when cloud providers are online. &#x20;
- **Queue Mode**: Select the queue mode as **lifo&#x20;**(last in first out) or **fifo&#x20;**(first in first out). Selecting **lifo&#x20;**&#x6D;eans that the last data entry is processed first, and selecting **fifo&#x20;**&#x6D;eans the first data entry is processed first.&#x20;

# Step 5: Enable the Connector

After adding the connector, click the toggle in the connector tile to enable it.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/Lr9QL5pZSjFsmTfwNUYMy_postgresql.png" size="60" width="412" height="348" position="center" showCaption="false"}

If you see a *Failed&#x20;*&#x73;tatus, you can review the [Connector Logs](docId\:Zz28hZtQBK7oD_Xsj81O8) and relevant error messages.&#x20;

# Step 6: Create Topics for Connector

You will now need to import the tags created in Step 2 as topics for the PostgreSQL connector. The topics will be created as outbound topics.&#x20;

**To create outbound topics:**

1. Click the connector tile.
   The connector *Dashboard&#x20;*&#x61;ppears.&#x20;
2. Click the **Topics&#x20;**&#x74;ab.&#x20;
3. Click the **Import from DeviceHub tags** icon.&#x20;
   The *DeviceHub Import* dialog box appears.
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/QUo-NUFfBj7F2BbnlBBj3_importdevicehub.png" size="80" width="1218" height="567" caption="Import from DeviceHub icon" position="center" showCaption="true"}
4. Select all the tags to import and click **Import**.&#x20;

After adding all required topics, navigate to the Integration overview page and ensure the connector is not disabled and still shows a CONNECTED status.&#x20;

# Step 7: Enable Topics

To enable the topics, return to the *Topics&#x20;*&#x74;ab and click the **Enable all topics** icon.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/_r9Zt0i2zdoHv9dd9d5xx_image.png" size="80" width="1218" height="567" caption="Enable all topics icon" position="center" showCaption="true"}

# Step 8: Make PostgreSQL Queries

You can now verify that you can view data through the terminal command window.&#x20;

Update the credentials, database name, and table name to your specific configurations.&#x20;

**To make queries in the container terminal:**

1. In Manufacturing Connect Edge, navigate to **Applications&#x20;**>**&#x20;Containers**.
2. Click the **Terminal&#xA0;**&#x69;con next to the PostgreSQL container.
   The PostgreSQL shell opens.
3. From the PostgreSQL container terminal, enter `psql -h localhost -U postgres`**&#xA0;**&#x61;nd press **ENTER**.
   The *psql (13.2 (Debian 13.2-1.pgdg100+1))***&#xA0;**&#x76;ersion number appears.
4. Enter `\l`**&#xA0;**&#x61;nd press **ENTER**.
   The list of databases appears in the console.
5. Enter `\c postgres`**&#xA0;**&#x61;nd press **ENTER**.
   *You are now connected to database "db-example" as user "postgres"* appears.
6. Enter `\dt` and press **ENTER**.
   The list of relations appears showing the devicehub schema.
7. Enter `\d devicehub` and press **ENTER**.
   The *public.devicehub* table appears.
8. Enter **\du** and press **ENTER**.****
   The *List of roles* appears.
9. Enter `select * from devicehub;`**&#xA0;**&#x61;nd press **ENTER**.
   The data for the devicehub table appears.
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/HOsMXyQViXIcPsygcVFOq_applications-postgresql-table.png" size="80" width="1576" height="739" caption="PostgreSQL connector messages" position="center" showCaption="true"}

