> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/integrations/resource-integrations/postgresql-new/requesting-postgresql-access.md).

# Requesting PostgreSQL Access

## Requesting PostgreSQL access

How to request just-in-time access to PostgreSQL databases through P0 using the CLI.

P0 recommends using the P0 CLI to request access to a PostgreSQL database.

#### Via the P0 CLI <a href="#via-the-p0-cli" id="via-the-p0-cli"></a>

**Prerequisites:**

* An installed [PostgreSQL](https://docs.p0.dev/integrations/resource-integrations/postgresql-new) P0 integration on the database
* P0 access policies that allow you to request access to the PostgreSQL database
* P0 CLI version 0.25.0 or higher
* An open CloudShell terminal in the database's VPC
  * Open a CloudShell instance by navigating to the database's page within the "RDS" service in the AWS cloud console, then choosing "CloudShell" under "Connectivity & security", then clicking "Launch CloudShell"

**Listing requestable fields**

You can list requestable instances, roles, and databases by executing:

```bash
p0 ls postgres role instance                          # lists instances and clusters
p0 ls postgres role name --instance "${INSTANCE}"     # lists roles
p0 ls postgres role database --instance "${INSTANCE}" # lists databases within an instance 
```

**Making a request**

From the CLI, execute:

```bash
p0 aws rds generate-db-auth-token --arch postgres --role "${ROLE}" --instance "${INSTANCE}"
```

where `<role>` is the name of the role you want to access, and `<instance>` is the identifier configured in P0 when the instance was installed in P0.

After executing `p0 aws rds generate-db-auth-token`, P0 will create an access request. Have the request approved. Once it is approved, the command will emit instructions to connect to the instance.

*Example:*

<a class="button secondary">Copy</a>

```bash
export RDS_SSL_CA='/certs/global-bundle.pem'
export RDS_HOST=<hostname>
export PGPASSWORD=<password>

psql "host=${RDS_HOST} port=5432 sslmode=verify-full sslrootcert=${RDS_SSL_CA} dbname=postgres user=p0_john_doe"
```

Copy these instructions.

Now, navigate to the open CloudShell terminal, and execute these instructions. You will receive access to the database.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.p0.dev/integrations/resource-integrations/postgresql-new/requesting-postgresql-access.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
