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

Clarify steps needed for Cloud SQL #1928

Merged
merged 7 commits into from
Nov 12, 2020
Merged

Conversation

daxmc99
Copy link
Contributor

@daxmc99 daxmc99 commented Nov 2, 2020

This adds additional clarification for how to access our production databases

Followup to https://sourcegraph.slack.com/archives/D012ZE3Q5J7/p1604332857000100

@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Nov 2, 2020

Notifying subscribers in CODENOTIFY files for diff b807166...6a24673.

Notify File(s)
@nicksnyder handbook/engineering/deployments/postgresql.md


- Default db {[Password](https://my.1password.com/vaults/dnrhbauihkhjs5ag6vszsme45a/allitems/svfiw4vcbxhhbobpl442olyebu/)}
```
gcloud beta sql connect --project sourcegraph-dev sg-cloud-732a936743 --user=sg -d=sg
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't work for me

% gcloud beta sql connect --project sourcegraph-dev sg-cloud-732a936743 --user=sg -d=sg
ERROR: (gcloud.beta.sql.connect) Cloud SQL Proxy could not be found in PATH. See https://cloud.google.com/sql/docs/mysql/sql-proxy#install for information on installing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, I thought it prompted to install the beta utils if you did not have them

You do not currently have this command group installed.  Using it
requires the installation of components: [beta]


Your current Cloud SDK version is: 310.0.0
Installing components from version: 310.0.0

┌─────────────────────────────────────────────┐
│     These components will be installed.     │
├──────────────────────┬────────────┬─────────┤
│         Name         │  Version   │   Size  │
├──────────────────────┼────────────┼─────────┤
│ gcloud Beta Commands │ 2019.05.17 │ < 1 MiB │
└──────────────────────┴────────────┴─────────┘

For the latest full release notes, please visit:
  https://cloud.google.com/sdk/release_notes

Do you want to continue (Y/n)?

Copy link
Contributor

Choose a reason for hiding this comment

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

What makes you think I don't have beta tools installed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like the cloud-sql-proxy is not installed as part of the beta tools. I thought it was.


You may use these gcloud commands to connect directly to the databases:

- Default db {[Password](https://my.1password.com/vaults/dnrhbauihkhjs5ag6vszsme45a/allitems/svfiw4vcbxhhbobpl442olyebu/)}
Copy link
Contributor

Choose a reason for hiding this comment

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

how/where is the password provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The login should prompt for it

https://console.cloud.google.com/bigquery?sq=527047051561:67f2616f4acb4b7cb3639e4a97e2f4aa
) and their `EXTERNAL_QUERY` syntax.

There are two ways of connecting: either using the `gcloud beta sql connect` command or running the proxy on a port locally.
Copy link
Contributor

Choose a reason for hiding this comment

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

As a developer, how do I know which way to choose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gcloud is mainly for quick pgsql commands, the proxy is used when you want to connect an external database viewer or GUI program.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
There are two ways of connecting: either using the `gcloud beta sql connect` command or running the proxy on a port locally.
There are two ways of connecting: either using the `gcloud beta sql connect` command which will use the `pgsql` client or running the proxy on a port locally to utilize whatever tools you typically use.

```
_Note:_ You may need to set or unset your PGPASSWORD environment variable to the value of the password of the user you are using to connect (`-U sg`).

If you are frequently using this to access the database for read-only operations, please let the #dev-ops channel know so we can add a read-only replica.
Copy link
Contributor

Choose a reason for hiding this comment

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

At the very least, it seems like we should create a readonly user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@daxmc99 daxmc99 marked this pull request as draft November 6, 2020 18:58
@daxmc99 daxmc99 marked this pull request as ready for review November 7, 2020 01:58
Comment on lines +13 to +15
For read-only access, there is also an option of using [BigQuery](
https://console.cloud.google.com/bigquery?sq=527047051561:67f2616f4acb4b7cb3639e4a97e2f4aa
) and their `EXTERNAL_QUERY` syntax.
Copy link
Member

Choose a reason for hiding this comment

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

I think using BigQuery might deserve a section of its own, with the full EXTERNAL_QUERY here (did not realize that it was just a stand-in for a table), e.g. seeing:

SELECT * FROM EXTERNAL_QUERY("...", "SELECT name::text,created_at::text FROM repo LIMIT 5;");

would be a lot more self-explanatory. Seems a lot less setup than the alternative, so for UI-and-mouse noobs like me I would probably go for this more often than not 😛

Co-authored-by: Robert Lin <robert@bobheadxi.dev>
@nicksnyder
Copy link
Contributor

don't wait on my review, ultimately this documentation should make it clear to a new teammate how to connect to the database. The best review here is to have a new teammate walk through these steps and give you feedback on whether they were successful or not (feel free to merge first)


- Default db {[Password](https://start.1password.com/open/i?a=HEDEDSLHPBFGRBTKAKJWE23XX4&v=dnrhbauihkhjs5ag6vszsme45a&i=pjxf64qxwsin4d56xij6vm3gva&h=my.1password.com)}
```
gcloud beta sql connect --project sourcegraph-dev sg-cloud-732a936743 --user=dev-readonly -d=sg
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to export CLOUDSDK_PYTHON=python2. I have both 2 and 3 installed, 2 appears first in my path, but it looks like 3 gets chosen anyway:

Python 3 is preferred over Python 2. Note that gcloud requires Python version 2.7.x or 3.5-3.8.

I have 2.7 and 3.9, so without the environment variable I get AttributeError: module 'importlib' has no attribute 'util'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you find this command useful or do you just use the proxy by itself?

Copy link
Contributor

Choose a reason for hiding this comment

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

For me personally, the command is useful. I don't generally use a GUI or similar tool for PG access.

Copy link
Contributor

@flying-robot flying-robot left a comment

Choose a reason for hiding this comment

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

Worked for me, just left a couple of notes/questions

@daxmc99 daxmc99 merged commit b505b7b into main Nov 12, 2020
@daxmc99 daxmc99 deleted the dax/clarify_postgres_connection branch November 12, 2020 06:24
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

6 participants