# Postgres

## Introduction

PostgreSQL (Postgres) is a powerful, open-source, object-relational database management system that uses and extends the SQL language. It is known for its stability, reliability, and advanced features such as concurrency control, transaction management, and support for various programming languages. Postgres is the backbone database of many backend production services.

You can now keep data in sync with all your other CRMs and database systems with Stacksync!

Check out our [Postgres guides](/two-way-sync/guides/modify-salesforce-data-in-postgres.md) to get started!

## Things to keep in mind

### During setup

* [x] **All Postgres tables must have a (single) primary key**\
  We use the primary key to keep your data in sync.\
  The primary key must be a single column, composite primary keys are not valid. Check our [Postgres snippets](/two-way-sync/connectors/postgres/snippets.md) collection for additional hints.
* [x] **Primary keys must be auto-generated**\
  Make sure your primary keys are generated by your database (i.e. have a default value set).
* [x] **Double-check that the Postgres user used by Stacksync to connect to your database is the owner** (or has the same role as the owner) **of&#x20;*****the tables*****&#x20;you want to map.**

If a table you see in your database does not appear in Stacksync, one of the previous conditions is not met. Check our [Postgres snippets](/two-way-sync/connectors/postgres/snippets.md) collection for additional hints.

{% hint style="info" %}
You must have replication rights to connect your Postgres instance. If you get the following error:

`The user does not have the right permissions for replication. Please check the documentation for more information.`

Please use the "**Postgres Heroku**" connector instead of the "Postgres" Connector. They are the same but the "Postgres Heroku" connector does not require replication rights in trade for some negligible database performance. So you can use the "Postgres Heroku" connector with your current database even if it is not provided by Heroku as long as you get the error message displayed above.
{% endhint %}

<details>

<summary>How to enable Logical Replication? (If not already enabled)</summary>

To use **logical replication** for change data capture the ***wal\_level*** value must be set to ***logical.*** To change the value of this parameter, modifications need to be made to the *postgresql.conf* file.

1. Open the *postgresql.conf* file. On Linux, this file can be found in the following directory:

   **/etc/postgresql/version/main**
2. Find the **wal\_level** variable under WRITE-AHEAD LOG settings.
3. Uncomment it if it's commented and set its value to **logical:**\
   wal\_level = logical
4. Restart the PostgreSQL service. On Linux it can be restarted with the following commands:\
   `sudo service postgresql stop`

   `sudo service postgresql start`
5. Use the following SQL query to ensure logical replication has been enabled:\
   `SHOW wal_level;`\
   The value displayed should be **logical.**
6. After enabling, in Stacksync, use the **Postgres** option instead of the **Postgres Heroku** option while creating the sync.

</details>

### After setup

{% hint style="warning" %}
Renaming schemas, tables, or columns will break Stacksync configuration. No worries, we get you covered! Please refer to our [Manual Sync Configuration Update](/two-way-sync/features/update-sync-configuration.md) guide.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stacksync.com/two-way-sync/connectors/postgres.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
