--- title: "How to Connect a PostgreSQL Database to Preset" slug: "postgres-connection" description: "Article about how to connect your PostgreSQL database to Preset Cloud." updated: 2025-06-26T21:20:15Z published: 2025-06-26T21:20:15Z canonical: "docs.preset.io/postgres-connection" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.preset.io/llms.txt > Use this file to discover all available pages before exploring further. # PostgreSQL ## Overview In this article we will explain how to connect a PostgreSQL database to Preset. So let's get started! --- ## Allowlist Preset IPs Preset Cloud runs on four regions. For Preset to access your data, first thing you need to do is to add region based Preset IP addresses to your Inbound and Outbound firewall rules. | Protocol | Port | Source | | --- | --- | --- | | TCP | 5432 | [Preset IPs](/v1/docs/connecting-your-data#introduction) | --- ## Connect database to Preset Let's start by selecting **+ Database** — have a look at [Connecting your Data](/v1/docs/connecting-your-data) if you need help wth this step. Select **PostgreSQL**. ![image.png](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/image%28321%29.png) The *Connect a database* window appears. There are two ways to proceed with the connection: - [Using the dynamic form](/v1/docs/postgres-connection#connect-via-the-dynamic-form): Applicable to most use-cases. - [Using a SQLAlchemy string URI](/v1/docs/postgres-connection#connect-using-a-sqlalchemy-string-uri): Useful to setup advanced configurations, such as providing custom certificate files. --- ## Connect via the dynamic form Fill the form with information from your Postgres instance: - **Host** with the hostname/IP address of your Postgres instance. - **Port** with the port that should be used for the connection (typically `5432`). - **Database name** with the name of the database you want to connect to from the Postgres instance. - **Username** and **Password** with the credentials that should be used for the connection. - **Display Name** with the name to be used in Preset for this connection. - The **Additional Parameters** field can be used to specify additional parameters to be used in the SQLAlchemy connection string, if needed. - Toggle the **SSL** button to create the connection with SSL mode set to `verify-ca`, if desired. - Expand the **SSH** section to provide an [SSH Tunnel](/v1/docs/ssh-tunneling) configuration in case your database is not exposed to the Preset IPs. ![](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/image(323).png) Click on **Connect** to create the connection. At this stage, you can optionally configure **Advanced** options, if needed. To learn more, please see [Advanced Connection Settings](/v1/docs/advanced-connection-settings). To finalize the connection, select **Finish**. Great job! --- ## Connect using a SQLAlchemy string URI Scroll down the Postgres form and click on the **Connect this database with a SQLAlchemy URI string instead**: ![](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/image(324).png) Fill the form accordingly: - In the **Display Name field**, enter a meaningful name for the new connection to Postgres. - In the **SQLAlchemy URI field**, customize your URI connection string using the following syntax: ```plaintext postgresql+psycopg2://:@:/ ``` Replace: - `<Username>` and `<Password>` with the credentials that should be used for the connection. - `<Host>` and `<Port>` with the host/IP address and port that should be used for the connection. - `<Database>` with the name of the database you want to connect to from the Postgres instance. ![](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/image(325).png) ### Provide custom certificate files If your database requires providing custom certificate files, navigate to the **Advanced** tab, and then expand the **Security** section. The additional connection configuration should be added to the **SECURE EXTRA** field: ```json {    "certificates": {        "client-cert.pem": "",        "client-key.pem": "",        "server-ca.pem": ""    } } ``` Note that the content for each file should be a single string block. Line breaks can be replaced with `\n` (each). You can also use below Python script to automatically generate this content — note that the Python script must be created inside the same directory the certificate files are stored, and the files should also be named as `client-cert.pem`, `client-key.pem` and `server-ca.pem`: ```python import json filenames = {    "client-cert.pem",    "client-key.pem",    "server-ca.pem", } print(    json.dumps(        {            "certificates": {filename: open(filename).read() for filename in filenames},        }    ) ) ``` When done, return to the previous screen by navigating to the **Basic** tab. ### Test and Connect To test your connection, click on the **Test connection** button. If successful, a notification message appears: ![](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/image(326).png) After a successful test, go ahead and select **Connect** to finalize the connection. Congratulations, your database is now connected to Preset!