> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Setting up a remote PostgreSQL connection

> Learn to connect your local Mac, Windows, or Linux computer to remote PostgreSQL databases on Hosting.com.

This article describes how to use a local computer to connect to your PostgreSQL databases stored remotely on hosting.com servers.

<Warning>
  **Important**

  Before you can establish remote connections to your PostgreSQL databases, you must open a support ticket at [https://my.hosting.com](https://my.hosting.com). Please provide the following information in the ticket:

  * The name of the PostgreSQL database that you want to access remotely.

  * The database username that you want to use to access the PostgreSQL database.

  * The IP address from which you will access the PostgreSQL database.

  We can then enable remote access for the PostgreSQL database.
</Warning>

## Choose a remote PostgreSQL connection method

You can use either of the following methods to access your PostgreSQL databases remotely:

* **SSH tunnel:** This is the more secure method. You set up an SSH tunnel that forwards a port on your local computer to the remote PostgreSQL server. The PostgreSQL traffic is encrypted by the SSH tunnel.

* **Direct connection:** You can set up a direct connection between your local computer and the remote PostgreSQL server on port 5432.

After you have set up a remote PostgreSQL connection, you can use a client application such as *psql* to work with your databases.

## Method #1: Set up an SSH tunnel

The procedure you follow to set up an SSH tunnel between your local computer and the hosting.com server depends on the local computer's operating system.

### Microsoft Windows

In order to use an SSH tunnel on a computer running Microsoft Windows, you need an SSH client program. We recommend using PuTTY, which you can [download here](http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe). After you have downloaded the PuTTY executable to your local computer, you can set up an SSH tunnel.

To set up an SSH tunnel on a computer running Microsoft Windows:

1. Start PuTTY.

2. In the **Category** pane, expand **Connection**, expand **SSH**, and then click **Tunnels**.

3. In the **Source port** text box of the **Port Forwarding** section, type `5432`.  This is the local port to forward.
   > 📘 Note
   >
   > If you are running a PostgreSQL server on your local computer, you might have to change the port number (for example, to **5433** ) to avoid port conflicts.

4. In the **Destination** text box, type `localhost:5432`.

5. Confirm that the **Local** and **Auto** radio buttons are selected.

6. Click **Add**.

7. In the **Category** pane, click **Session**.

8. In the **Host Name (or IP address)** text box, type your web site's domain name or IP address.

9. In the **Port** text box, type `22`.

   > 🚧 Important
   >
   > Make sure you use the correct SSH port number for your account. For example, some hosting accounts use a different port for SSH, such as 7822.

10. Confirm that the **Connection type** radio button is set to **SSH**.

11. Click **Open**.

12. If a PuTTY security alert about the server's host key appears, click **Yes**.

13. When the **login as** prompt appears, type your hosting.com username, and then type your password.

14. When the remote server's command line prompt appears, the SSH tunnel is established and you can use your PostgreSQL client applications on the local computer.
    > 👍 Tip
    >
    > To verify that PuTTY is forwarding ports correctly, you can click the icon in the top-left corner of the PuTTY session window, and then click **Event Log** . If port forwarding is working correctly, you see a line similar to: **Local port 5432 forwarding to localhost:5432**

### macOS and Linux

To set up an SSH tunnel on a computer running macOS or Linux:

1. Open a terminal window and type the following command at the command line. Replace ***username*** with your hosting.com username, and replace ***example.com*** with your site's domain name:

   ```bash theme={null}
   ssh username@example.com -L 5432:localhost:5432
   ```

   > 🚧 Important
   >
   > To use a different port number, use the **-p** option. For example:
   >
   > ```bash theme={null}
   > ssh -p 7822 username@example.com -L 5432:localhost:5432
   > ```

   > 📘 Note
   >
   > The number before **localhost** is the port number at the local end of the tunnel. The number after **localhost** is the port number at the remote (server) end of the tunnel. If you are running a PostgreSQL server on your local computer, you might have to change the first **5432** to another port number (for example, to **5433**) to avoid port conflicts.

2. Type your password, and then press Enter. When the remote server's command line prompt appears, the SSH tunnel is established and you can use your PostgreSQL client applications on the local computer.For example, if the *psql* client application is installed on your local computer, you can type the following command to access a database on the hosting.com server. Replace ***username*** with the database user, and ***dbname*** with the name of the database:

   ```bash theme={null}
   psql -U username -h localhost -p 5432 dbname
   ```

## Method #2: Set up a direct connection

To set up a direct connection between your local site and the PostgreSQL server, you must configure a client application. There are several PostgreSQL client applications available, but for all of them, you must provide the following information to establish a remote connection:

* The name of the remote server (for example, *mi3-ss42.a2hosting.com*).

* The port of the remote server (this is always 5432).

* The PostgreSQL database name.

* The PostgreSQL database username.

* The PostgreSQL database password.

<Tip>
  pgAdmin III is a popular PostgreSQL client application. For information about how to set up this application to work with your account, please see [this article](/docs/postgresql-client-applications).
</Tip>

## More information

To view the online documentation for PuTTY, please visit [http://the.earth.li/\~sgtatham/putty/0.60/htmldoc/index.html](http://the.earth.li/~sgtatham/putty/0.60/htmldoc/index.html).

## Related articles

* [PostgreSQL client applications](/docs/postgresql-client-applications)
