Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide on how to connect to PostgreSQL Server (not Docker Image) #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

darko-bacic
Copy link

Added guide on how to connect to PostgreSQL standalone server.

Files affected:
Update 01-connection.md

Solving Issue serverpod/serverpod#2015 (comment)

Added guide on how to connect to PostgreSQL standalone server
@SandPod SandPod self-requested a review April 9, 2024 06:07
Copy link
Contributor

@SandPod SandPod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking this on 🎉

Awesome start! I have a couple of questions and concerns.

We should also make sure that we better explain how to create the database and a user with the correct permissions to run the migration scripts.

@@ -4,9 +4,14 @@ In Serverpod the connection details and password for the database are stored ins

Serverpod automatically establishes a connection to the Postgresql instance by using these configuration details when you start the server.


## Connecting to a Postgresql Docker Image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove this header.

The details in this section are general for all connection types regardless of whether we are connecting to a Postgres instance in a docker container or if it is running somewhere else.

The information about how to connect to the Postgresql docker image is outlined in the Development database header.

This section should still be kept general.


## Connecting to a Postgresql Server Instance

Connecting to a Postgresql Server Instance is similar to connecting to a Docker Image, but there are some prerequisites to take into account:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT (Non blocking):

Suggested change
Connecting to a Postgresql Server Instance is similar to connecting to a Docker Image, but there are some prerequisites to take into account:
Connecting to a Postgresql Server Instance is similar to connecting to a Docker Image, but there are some prerequisites to take into consideration:

- Making sure that the machine/server allows incoming traffic
- Creating a Postgresql user and database

You can connect to Postgresql server that you have installed on your local machine, a self-hosted one, Google Cloud SQL, AWS RDS or SQL Server, or any other 3rd party service.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Improve the start of the sentence and clarify that any service is supported.

The start of this sentence seems a little strange. How about:

Serverpod supports connecting to any running Postgresql server, whether hosted on your local machine in Google Cloud SQL or any other 3rd party service.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this sentence should be directly under the Connecting to a Postgresql Server Instance header as well, and then we list the prerequisites below. "Sales pitch" before instructions?


### Connecting to a Local Postgresql

If you want to connect to a local Postgresql Server (with the default setup) then the `development.yaml` will work just fine. The only thing you need to do is change the password in the `passwords.yaml`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add instructions around the specifying port.

The default port for Postgres is 5432; whenever I have a local instance of Postgres, it usually occupies that port. I think that needs to be changed as the default development.yaml specifies port 8090.

Connecting to a Postgresql Server Instance is similar to connecting to a Docker Image, but there are some prerequisites to take into account:

- Making sure that the machine/server allows incoming traffic
- Creating a Postgresql user and database
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add instructions for how to create a user and a database.

This is the step that many people get stuck on, I think it would be good to have instructions on creating a database with a user with the right permissions.

That obsticle that Craig Labenz was fighting with in observable flutter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend watching that part of the video and ensuring we answer all those questions.

- Make sure to open any necessary ports on that machine
- Configure Postgresql Server to listen to all other connections (not only local once) in `postgresql.conf`:
```bash
listen_addresses = '*'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Are there any safety considerations to take into account here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a reference to instructions on best practices here?

You can connect to a Google Cloud SQL Postgresql Instance in 2 ways:

- Setting up the Public IP Authorized networks (with your Serverpod server IP) and changing the database host string to the `Cloud SQL public IP`
- Using the Connection String if you are hosting your Serverpod server on Google Cloud Run and changing the database host string to the Cloud SQL: `/cloudsql/my-project:server-location:database-name/.s.PGSQL.5432`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Most parts of the link that should be used are configured by the user. Does it make sense to clarify that these are user-provided as opposed to the constant parts such as .s.PGSQL.5432?

We could provide a small explanation on the user provided parts as well.

Suggested change
- Using the Connection String if you are hosting your Serverpod server on Google Cloud Run and changing the database host string to the Cloud SQL: `/cloudsql/my-project:server-location:database-name/.s.PGSQL.5432`
- Using the Connection String if you are hosting your Serverpod server on Google Cloud Run and changing the database host string to the Cloud SQL: `/cloudsql/<my-project>:<server-location>:<database-name>/.s.PGSQL.5432`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question for the AWS RDS link.


:::info

If you are using the `isUnixSocket` don't forget to add **"/.s.PGSQL.5432"** to the end of the `host` IP address *otherwise your Google Cloud Run instance will not be able to connect to the database*.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Should we leave /.s.PGSQL.5432 out of the string in the instructions, since it is not always required. Then provide a full link example in the info box here where it is?

- Update your Serverpod `database` config to use the public IP, database name, and user. Also the database password in `passwords.yaml`.


### Connecting to Google Cloud SQL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: More information around this seems to be explained in: https://github.com/serverpod/serverpod_docs/blob/main/docs/06-deployments/03-deploying-to-gcr-console.md#setup-the-database

Maybe we could refer to that section for more in-depth instructions?

We should also ensure that the information is matching in style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants