# Open port for space to connect to PostgreSQL

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%3E%5C
**Category:** Spaces\
**Created:** [January 18, 2023, 9:09am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938 "2023-01-18T09:09:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon86412018](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@anon86412018](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fanon86412018)%5C
**Post date:** [January 18, 2023, 9:09am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F1 "2023-01-18T09:09:42Z")

</div>

Hi @chris-rannou,

Could you open the port `5432` for this space: [Defi Ai 2022 - a Hugging Face Space by vnghia](https://huggingface.co/spaces/vnghia/defi-ai-2022) as I need to connect to a PostgreSQL database ?

Thank you very much !

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fradames)%5C
**Post date:** [January 18, 2023, 3:56pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F2 "2023-01-18T15:56:29Z")

</div>

hi @anon86412018 are you sure your DB service is running at `34.155.175.170:5432`? if you’re trying to access the DB from space, you don’t need that port to be open, however on your Space log it states timeout trying to reach your db server

---

<div class="post-metadata">

**Author:** ![anon86412018](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@anon86412018](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fanon86412018)%5C
**Post date:** [January 18, 2023, 4:13pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F3 "2023-01-18T16:13:59Z")

</div>

Hi @radames, I am quite sure my DB service is running at `34.155.175.170:5432` because the same code works on my machine. It is a Google Cloud SQL instance (I already opened the DB to every IP and port by `0.0.0.0/0` on GCP side), maybe that is the reason why I have this error ?

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fradames)%5C
**Post date:** [January 18, 2023, 7:29pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F4 "2023-01-18T19:29:57Z")

</div>

ok you’re right, you might need outgoing port access, currently only 80 and 443, we’ll get back to you soon.

---

<div class="post-metadata">

**Author:** ![chris-rannou](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@chris-rannou](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fchris-rannou)%5C
**Post date:** [January 19, 2023, 3:42pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F5 "2023-01-19T15:42:29Z")

</div>

Hi @anon86412018,

Port 5432 is now open.

---

<div class="post-metadata">

**Author:** ![anon86412018](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@anon86412018](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fanon86412018)%5C
**Post date:** [January 19, 2023, 7:13pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F6 "2023-01-19T19:13:27Z")

</div>

hmmm, unfortuntately, I still can not access to my DB instance. I also add a command to check if the DB is ready by `pg_isready`. And I found that when building the image, the connection is fine, but it failed while the space is running.

You can see the log here: [Defi Ai 2022 - a Hugging Face Space by vnghia](https://huggingface.co/spaces/vnghia/defi-ai-2022?logs=build)

Do the port need to be opened twice for building and running or there is something else ?

---

<div class="post-metadata">

**Author:** ![deepkyu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/deepkyu/32/19615_2.png) [@deepkyu](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdeepkyu)%5C
**Post date:** [January 20, 2023, 4:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F7 "2023-01-20T04:56:13Z")

</div>

Hi @anon86412018 ,

I had a similar issue when integrating my Hugging Face Space with my AWS instance.  
I later found that Hugging Face Space only approves for the privileged port, which is below 1024.  
I think this is for security reason, and I suggest that you change your SQL server port open with privileged port.

For now, I switched the service port to 80, but I remembered that it is fine if the port number is below 1024.

Ref for my previous issue:

> [@Is there a way to call external gRPC service?](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fis-there-a-way-to-call-external-grpc-service%2F14468)%3A
>
> I was planning to deploy a demo on Huggingface Space, but ran into a bit of an issue. So, my demo partially depends on a gRPC service that I have deployed on an AWS instance. When I tried test running it, it just timed out with “Failed to pick subchannel” so I am guessing that there is an issue when trying to call a remote gRPC service from Huggingface Space. When I tested my demo by having the same setup in my local computer as I did in Huggingface Space, I had no issues. I also checked to see…

---

<div class="post-metadata">

**Author:** ![anon86412018](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@anon86412018](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fanon86412018)%5C
**Post date:** [January 20, 2023, 10:49am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F8 "2023-01-20T10:49:14Z")

</div>

Hi @deepkyu I dont think so because @chris-rannou has already opened the port and my code can connect to the database while building the Docker image but not while running. I am suspecting there are some bugs with the Docker space 😕

---

<div class="post-metadata">

**Author:** ![deepkyu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/deepkyu/32/19615_2.png) [@deepkyu](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdeepkyu)%5C
**Post date:** [January 20, 2023, 1:49pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F9 "2023-01-20T13:49:37Z")

</div>

@anon86412018  
Oh I see. that’s also one of weird situations…

From my experience, I concluded that there were some outbound policies in Hugging Face Space server which blocks unprivileged ports. At that time, my docker container at my AWS instance communicates well from other servers’ request except the HF Space.

I’m sorry for not being helpful tho.  
Hope it works out 👍

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fradames)%5C
**Post date:** [January 20, 2023, 2:24pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F10 "2023-01-20T14:24:12Z")

</div>

hi @anon86412018 and @deepkyu , we’ve changed the rules and we’ll enable 5432, 27017 in addition to 80, 443. Sorry @anon86412018 I don’t think it’s in prod yet. I’ll ping you here. Thanks

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fradames)%5C
**Post date:** [January 20, 2023, 6:10pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F11 "2023-01-20T18:10:02Z")

</div>

hi @anon86412018 it should be fixed now, thanks for the patience

---

<div class="post-metadata">

**Author:** ![anon86412018](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@anon86412018](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fanon86412018)%5C
**Post date:** [January 20, 2023, 6:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F12 "2023-01-20T18:25:31Z")

</div>

Thank you very much !

---

<div class="post-metadata">

**Author:** ![kmfoda](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/kmfoda/32/42122_2.png) [@kmfoda](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkmfoda)%5C
**Post date:** [May 3, 2023, 10:21am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F13 "2023-05-03T10:21:11Z")

</div>

Hey @radames thanks for opening up 5432. I’m hoping to use ElasticSearch (`9243`) and Papertrail logging (`45454`) for my app. Would it be possible to open up those 2 ports as well in addition to `5432`?

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fradames)%5C
**Post date:** [May 4, 2023, 4:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F14 "2023-05-04T16:54:20Z")

</div>

the ports 5432, 9200 and 45454 are now open

---

<div class="post-metadata">

**Author:** ![kmfoda](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/kmfoda/32/42122_2.png) [@kmfoda](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkmfoda)%5C
**Post date:** [May 4, 2023, 4:55pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F15 "2023-05-04T16:55:38Z")

</div>

Sorry my apologies I mean 9243 not 9200. I believe that’s the port Elastic uses. Thanks so much!

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fradames)%5C
**Post date:** [May 4, 2023, 4:57pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F16 "2023-05-04T16:57:24Z")

</div>

I see, I guess the default ES port is 9200 and it’s been open already, could you change it on your app?

---

<div class="post-metadata">

**Author:** ![kmfoda](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/kmfoda/32/42122_2.png) [@kmfoda](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkmfoda)%5C
**Post date:** [May 4, 2023, 5:34pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F17 "2023-05-04T17:34:34Z")

</div>

Ah we’re running our app on [elastic.co](http://elastic.co/) and that’s the port they gave us unfortunately. I think it might be quite tricky for us to change the port, it’ll also have a bit of downstream impact on all our other services which we’d have to factor in.

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fradames)%5C
**Post date:** [May 5, 2023, 4:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F18 "2023-05-05T16:54:03Z")

</div>

hi @kmfoda , the requested ports are open now, please try it again. Thanks

---

<div class="post-metadata">

**Author:** ![kmfoda](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/kmfoda/32/42122_2.png) [@kmfoda](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkmfoda)%5C
**Post date:** [May 5, 2023, 6:01pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F19 "2023-05-05T18:01:45Z")

</div>

Hi @radames, amazing that worked now! Thank you very much for your help!

---

<div class="post-metadata">

**Author:** ![notionhive-ai](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/notionhive-ai/32/51497_2.png) [@notionhive-ai](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnotionhive-ai)%5C
**Post date:** [July 22, 2025, 6:51am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fopen-port-for-space-to-connect-to-postgresql%2F29938%2F20 "2025-07-22T06:51:20Z")

</div>

Hi @radames, is there any way to open the port 587 for mail SMTP and 443 port to communicate through telegram?
