> For the complete documentation index, see [llms.txt](https://docs.airops.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.airops.com/docs/pt/contexto/memory-stores/add-data/import-from-sql-database/data-sources/postgres.md).

# Postgres

Conecte a uma base de dados Postgres no AirOps

{% hint style="info" %}
**Lembre-se de adicionar o nosso endereço IP à allowlist `52.71.87.39`**

Se a sua base de dados estiver protegida por uma firewall, lembre-se de permitir o acesso de entrada ao endereço IP da AirOps através da porta da sua base de dados.
{% endhint %}

## Adicionar o Postgres como uma Base de Dados no AirOps

Para configurar uma nova ligação à base de dados, vá para **⚙️ Definições > Configuração do Warehouse > Adicionar Fonte**

Depois, inclua o seguinte:

1. **Host** - O nome de anfitrião ou endereço IP do seu servidor PostgreSQL.

   Exemplo: `example-postgres-instance.abcdefghijkl.us-west-2.rds.amazonaws.com`
2. **Porta** - A porta na qual o seu servidor PostgreSQL está a ouvir. O valor predefinido é `5432`.
3. **Utilizador** - O utilizador PostgreSQL com o qual o AirOps se ligará à base de dados. É uma boa prática criar um novo utilizador para o AirOps (instruções abaixo), mas pode ser usado qualquer utilizador com privilégios SELECT.
4. **Palavra-passe** - Palavra-passe para o utilizador acima.
5. **Base de Dados** - A base de dados PostgreSQL à qual o AirOps se ligará.

<figure><img src="https://files.readme.io/595ac85-image.png" alt="" width="375"><figcaption></figcaption></figure>

## Configurar Utilizador e Conceder Acesso

Para adicionar uma base de dados PostgreSQL como Fonte de Dados no AirOps, use um utilizador existente ou crie um utilizador com **acesso de leitura** acesso às tabelas e esquemas aos quais gostaria de aceder a partir do AirOps:

### 1. Criar utilizador AirOps

```sql
CREATE USER airops_user
WITH PASSWORD '<secure-password>';
```

### 2. Conceder Privilégios USAGE e SELECT

Substitua pelos nomes de esquema e de tabela apropriados com os quais pretende que o AirOps interaja.

```sql
GRANT USAGE ON SCHEMA "<schema>" TO airops_user;

GRANT SELECT ON TABLE "<schema>"."<table>" TO airops_user;
```

Se quiser conceder acesso a várias tabelas, pode executar a `GRANT SELECT` instrução para cada tabela ou execute `GRANT SELECT ON ALL TABLES`.

### 3. (Opcional) Conceder Acesso a Futuras Tabelas no Esquema

Se quiser conceder acesso a todas as futuras tabelas num esquema, pode usar o seguinte comando, substituindo pelo nome de esquema apropriado:

```sql
ALTER DEFAULT PRIVILEGES IN SCHEMA "<schema>"
GRANT SELECT ON TABLES TO airops_user;
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.airops.com/docs/pt/contexto/memory-stores/add-data/import-from-sql-database/data-sources/postgres.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
