> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/p/postgre-sql-adapter.md).

# Postgre SQL Adapter

PostgreSQL can hold an asset list in a table or view. OctoXLabs queries a view that you prepare and turns each row into a device.

## Use cases

* List devices that come from the PostgreSQL view.

```
Adapters = postgresql-adapter
```

* Find devices not seen for 30 days, when the view has a `LastSeen` column.

```
Adapters = postgresql-adapter AND NOT LastSeen last now-30d/d
```

## Before you begin

### Network

| Source              | Destination       | Port                | Protocol   |
| ------------------- | ----------------- | ------------------- | ---------- |
| OctoXLabs connector | PostgreSQL server | 5432 (configurable) | PostgreSQL |

### Required permissions

| Scope or role | Permission            | Needed for          |
| ------------- | --------------------- | ------------------- |
| Database user | Read, Select and List | The configured view |

## Create credentials in Postgre SQL Adapter

{% stepper %}
{% step %}

### Create a database user

Create a PostgreSQL user for OctoXLabs and grant it Read, Select and List privileges.
{% endstep %}

{% step %}

### Prepare the view

OctoXLabs needs a view. The column that holds the hostname must be named `Hostname`. Name other columns with OctoXLabs field names, for example `IpAddresses`, `MacAddresses` and `LastSeen`, to map them automatically.
{% endstep %}
{% endstepper %}

## Connection parameters

| Parameter     | Required | Type    | Default | Description                                               |
| ------------- | -------- | ------- | ------- | --------------------------------------------------------- |
| IP            | Yes      | String  |         | IP address of the PostgreSQL server.                      |
| Port          | No       | Integer | 5432    | Database port.                                            |
| Domain        | No       | String  |         | Domain FQDN. If set, the login becomes `domain\username`. |
| Database      | Yes      | String  |         | Name of the database.                                     |
| Username      | Yes      | String  |         | Database user.                                            |
| Password      | Yes      | String  |         | Password of the user.                                     |
| View Name     | Yes      | String  |         | View to query. Quoted identifiers are accepted.           |
| Query Timeout | No       | Integer | 60      | Seconds before a query is stopped.                        |

## Troubleshooting

| Error message           | Cause             | Fix                                                 |
| ----------------------- | ----------------- | --------------------------------------------------- |
| Curser Failed Execute : | The query failed. | Check the view name and the privileges of the user. |

## Change history
