> 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/knowledge-bases/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 à lista de permissões `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 base de dados no AirOps

Para configurar uma nova ligação à base de dados, aceda a **⚙️ Definições > Configuração do armazém de dados > Adicionar origem**

Em seguida, introduza os seguintes dados:

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

   Exemplo: `example-postgres-instance.abcdefghijkl.us-west-2.rds.amazonaws.com`
2. **Porta** - A porta em que o servidor PostgreSQL está à escuta. A predefinição é `5432`.
3. **Utilizador** - O utilizador do PostgreSQL com o qual o AirOps se ligará à base de dados. Recomenda-se criar um novo utilizador para o AirOps (instruções abaixo), mas pode ser utilizado qualquer utilizador com privilégios SELECT.
4. **Palavra-passe** - Palavra-passe do utilizador acima.
5. **Base de dados** - A base de dados PostgreSQL à qual o AirOps se ligará.

<figure><img src="https://31915162-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX2n5yPRPynbnWuO4SH0M%2Fuploads%2Fgit-blob-ecd4ddd3fb641cf40dfdc4e9a2def26342c02531%2Fpostgres-01-form.png?alt=media" alt="Postgres connection form with host, port, user, password, and database fields and a Connect button"><figcaption><p>Introduza os dados de ligação do Postgres.</p></figcaption></figure>

## Configurar o utilizador e conceder acesso

Para adicionar uma base de dados PostgreSQL como origem de dados no AirOps, utilize um utilizador existente ou crie um utilizador com acesso de **leitura** às tabelas e aos esquemas que pretende aceder a partir do AirOps:

### 1. Criar o utilizador da 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 adequados 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 pretender conceder acesso a várias tabelas, pode executar a instrução `GRANT SELECT` para cada tabela ou executar `GRANT SELECT ON ALL TABLES`.

### 3. (Opcional) Conceder acesso a futuras tabelas no esquema

Se pretender conceder acesso a todas as futuras tabelas de um esquema, pode utilizar o seguinte comando, substituindo pelo nome do esquema adequado:

```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/knowledge-bases/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.
