several confusions about the Fetcher-for-Postgres....
# opal
d
several confusions about the Fetcher-for-Postgres. I found the opal-client could trigger date update using command like:
Copy code
opal-client publish-data-update $token --src-url http://mybillingserver.com/users --src-config '{"headers":{"authorization":"bearer secret-token"}}'
it only needs a single field named
src-url
to determine which datasource should be updates. 1. however, when using posgres table as datasource, this url would like to be
"url": "postgresql://postgres@example_db:5432/postgres"
. Does that means I need to put each data source into different database, in a way like
1 table in 1 database
mode? It sounds wired. 2. I checked another option to trigger data update. i.e. using OPAL Server REST API. However, this method seems to be wrong when only putting
url
in request payload like
curl ... --header 'Content-Type: application/json' -d '{"entries":[{"url":"postgresql://postgres@example_db:5432/postgres"}]}'
. The opal server won't fill the blanks of other field but remain them as empty which cause opal-client failed to fetch data. 3. then i know maybe I should put the whole datasource config entry into the payload. it sounds wired too. Does that mean I should hard-code all the datasouce configuration into my client. Is there some
id
or other workflow, e..g I first go somewhere to get the full datasource configure then post the data update. Really confusing, thanks a lot!
a
Hi @Dai Zhang, I'm an AI assistant for Permit.io. I'll analyze available sources and get back to you shortly.
Let me clarify these OPAL postgres fetcher concepts based on the documentation. 1. Database URL Structure You don't need separate databases for each data source (1) . The PostgreSQL URL
postgresql://postgres@example_db:5432/postgres
connects to a database, but you can fetch different data from the same database using different SQL queries . The
query
field in your fetcher config determines what specific data gets fetched . 2. Complete Configuration Required When using the REST API, you need to provide the complete configuration, not just the URL (2) . The postgres fetcher requires additional fields beyond just the URL (1) . Here's the proper structure for a postgres data update via REST API:
Copy code
{
  "entries": [
    {
      "url": "postgresql://postgres@example_db:5432/postgres",
      "config": {
        "fetcher": "PostgresFetchProvider",
        "query": "SELECT * FROM users WHERE updated_at > NOW() - INTERVAL '1 hour'"
      },
      "topics": [
        "users"
      ],
      "dst_path": "/users"
    }
  ]
}
3. Configuration Management You have a few options for managing configurations: ​*Option 1: Use OPAL_DATA_CONFIG_SOURCES for baseline data*​ (3) Set up your initial data sources in
OPAL_DATA_CONFIG_SOURCES
and use simpler update triggers for incremental changes . ​*Option 2: Store configurations in your application*​ Keep the full DataSourceEntry configurations in your application and include them when triggering updates (1) . ​*Option 3: Use the CLI with full config*​ The CLI command you mentioned works because it uses HTTP fetcher by default (2) . For postgres, you'd need:
Copy code
opal-client publish-data-update $token \
  --src-url postgresql://postgres@example_db:5432/postgres \
  --src-config '{"fetcher":"PostgresFetchProvider","query":"SELECT * FROM users"}' \
  -t users
The key insight is that different fetchers require different configuration fields - HTTP fetcher just needs a URL, but postgres fetcher needs both URL and SQL query (1) .
To learn more, see the sources I considered: [[1] How to extend OPAL with custom Fetch Providers](https://docs.opal.ac/tutorials/write_your_own_fetch_provider) [[2] Triggering Data Updates](https://docs.opal.ac/tutorials/trigger_data_updates) [[3] Data updates](https://docs.opal.ac/faq/)
o
Good answer from AI 🙂
Also note you can always fork / create your own custom fetcher from scratch - this is the main reason we chose Python for this framework
d
I noticed when there are 2 datasource using the same postgres url with different query field to select data from different table, the opal-client log says it seems save these 2 datasource to the same
policy-store url
e.g.
Saving fetched data to policy-store: source url='postgresql://admin@opal-postgresql:5432/opal',
. I don't know the concept of
policy-store
in the opal-client side, could you explain it more for me? would there be some conflicts if they save to the same one.
@Ask Inkeep
a
Thanks for tagging me @Dai Zhang. I'll look through relevant sources and get back to you shortly.
The policy store is the underlying policy engine that OPAL manages - typically OPA (Open Policy Agent) (1) . When OPAL client fetches data from different sources, it saves all the data into the same policy store instance, but at different paths (2) . ​*How Policy Store Works*​ The policy store URL you're seeing (like `postgresql://admin@opal-postgresql:5432/opal`) in the logs is actually the source URL being fetched from, not the destination . The actual policy store is usually OPA running locally with the OPAL client (1) . ​*Data Path Separation*​ Each DataSourceEntry has a
dst_path
field that determines where in the policy store the data gets saved (2) . For example:
Copy code
{
  "url": "postgresql://admin@opal-postgresql:5432/opal",
  "config": {
    "fetcher": "PostgresFetchProvider",
    "query": "SELECT * FROM users;"
  },
  "dst_path": "/users"
}
Copy code
{
  "url": "postgresql://admin@opal-postgresql:5432/opal",
  "config": {
    "fetcher": "PostgresFetchProvider",
    "query": "SELECT * FROM orders;"
  },
  "dst_path": "/orders"
}
​*No Conflicts*​ There are no conflicts when multiple data sources use the same database URL because: 1. Each gets saved to a different
dst_path
in the policy store 2. The
dst_path
acts like a namespace -
/users
and
/orders
are completely separate 3. Your Rego policies can access the data using these paths:
data.users
and
data.orders
​*Policy Store Configuration*​ You can configure which policy store OPAL client connects to using
OPAL_POLICY_STORE_URL
for standalone OPA (3) , or let OPAL manage an inline OPA instance with
OPAL_INLINE_OPA_CONFIG
(1) .
To learn more, see the sources I considered: [[1] OPA Runner Parameters](https://docs.opal.ac/getting-started/running-opal/run-opal-client/opa-runner-parameters) [[2] How to extend OPAL with custom Fetch Providers](https://docs.opal.ac/tutorials/write_your_own_fetch_provider) [[3] Standalone OPA URI](https://docs.opal.ac/getting-started/running-opal/run-opal-client/standalone-opa-uri)