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

SHS - adding doc on db access #158

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/safe-haven-services/accessing-databases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Accessing Databases

Some data in Safe Havens may be accessible via a database rather than files.

If you have a project with database access, your Research Coordinator will arrange for your accounts to be created on the database. Once your account is created, you will receive the `database name`, `host` and `port`, which you can use to connect programmatically (i.e., via R, Python, or any other language).

## R

To connect to a Safe Haven database via R, follow the [official documentation](https://solutions.posit.co/connections/db/getting-started/connect-to-database/) on database connections. The required connection packages will depend on the [type of database](https://solutions.posit.co/connections/db/databases/).

Example connection to a PostgreSQL database via [RPostgres](https://solutions.posit.co/connections/db/databases/postgresql/#using-the-rpostgres-package):

```r
library(DBI)
library(RPostgres)
con <- dbConnect(
RPostgres::Postgres(),
dbname = "<database-name>",
host="<host-name>",
port="<port-number>",
user = .rs.askForPassword("Enter Username:"),
password = .rs.askForPassword("Enter Password:")
)
```

## Python

Python has many database connection packages depending on the type of database. We recommend you choose a highly supported package and follow the package's official documentation.

Example connection to a PostgreSQL database via [psycopg](https://www.psycopg.org/docs/index.html):

1. Install psycopg2

```console
$ pip install psycopg2
```

1. Connect

```python
import psycopg2

con = psycopg2.connect(
database = "<database-name>",
host="<host-name>",
port="<port-number>",
user=input("Enter Username:"),
password=input("Enter Password:")
)
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ nav:
- "Network Access Controls": safe-haven-services/network-access-controls.md
- "Safe Haven Access": safe-haven-services/safe-haven-access.md
- "Virtual Desktop Connections": safe-haven-services/virtual-desktop-connections.md
- "Accessing Databases": safe-haven-services/accessing-databases.md
- "Using the HPC Cluster": safe-haven-services/using-the-hpc-cluster.md
- "Superdome Flex Tutorial":
- "Accessing the SDF Inside the EPCC TRE": safe-haven-services/superdome-flex-tutorial/L1_Accessing_the_SDF_Inside_the_EPCC_TRE.md
Expand Down