Setting up the CKAN DataStore database and permissions

The CKAN DataStore needs its own PostgreSQL database and two users with different rights. This page explains how to create them, apply permissions with ckan datastore set-permissions, test the result, and avoid the read-only user mistakes that expose data.

On this page

Why the CKAN DataStore database needs its own users

A portal team that turns on the DataStore and a public Data API is deciding who can change the tables behind those endpoints. The CKAN DataStore keeps resource rows in a separate PostgreSQL database with a write user and a read-only user, and the permissions between those two roles decide what the public API can and cannot change. Any portal that exposes DataStore tables needs this split, whether the rows came from an upload, a linked file or a loader job. The CKAN DataStore documentation describes the Data API as offering filtering, full-text search, pagination and SQL queries, and reads of that kind reach the database under the read-only identity. Before launch, confirm which database role each connection string uses, because a shared connection string quietly removes the separation.

The write user exists so CKAN and its loader can create tables and insert rows when a resource is processed. The read-only user exists so the public API, which any visitor to a public portal can reach, cannot modify those tables, even if a request is malformed or an application check has a gap. For example, in an illustrative case, a query that tries to update or drop a table fails at the database, so the table stays intact whatever happened in CKAN's code. That protection only holds if the read-only role carries read privileges and no write privileges, either directly or through a role it belongs to. Test the boundary instead of assuming it holds: connect as the read-only user and attempt an insert into a DataStore table, expecting a permission error.

Permissions are applied with ckan datastore set-permissions, which grants the read-only user access to the DataStore database. Review what it grants before go-live. The main gap to check is tables loaded later. PostgreSQL grants on existing tables do not automatically cover tables created afterward unless default privileges are also set, so a resource loaded next month may be unreadable to the read-only user and fail in the Data API. Ask your deployment team to confirm how new tables pick up privileges in your environment, then repeat the read-only write test after each loader change or CKAN upgrade.

Which database and user layouts fit each deployment

This table compares the database layouts a team can choose for the DataStore and how each one changes operations. Read each row for who the layout suits, what it adds to day-to-day running and what to confirm before you commit. The main takeaway is that the write and read connection settings must point at the right roles in every layout, so confirm exact config keys in the DataStore docs for your CKAN version before you build.

LayoutWho it suitsWhat it adds to operationsWhat to confirm
Same server as the CKAN metadata databaseSmall portals with one database team and modest data volumesOne server to patch, back up and monitor, but DataStore load competes with metadata writesThe DataStore database and both roles exist, and the read-only role cannot write to DataStore tables
Separate PostgreSQL server or managed servicePortals with a dedicated database team, stricter isolation needs or heavy DataStore loadingIndependent patching, sizing and backups for DataStore, plus a network path CKAN must reach on both URLsConfirm the admin account can create the DataStore database and both roles, and that network rules reach both URLs
Connection pooler such as PgBouncer in frontLarger portals with many web and worker processes opening database connectionsFewer server connections and a single entry point, but another service to patch, monitor and securePooling mode works with the statements CKAN issues, and the read-only role still applies through the pooler
Separate server with a hot standby for readsPortals whose public search and API traffic justifies a read-only replicaRead traffic can go to a standby, but the replica lags the primary and must be monitoredThe write setting must stay on the primary, and the lag must be acceptable for published data

How the write and read-only users split privileges

The write user creates DataStore tables and loads rows into them on behalf of CKAN and its loaders. Whichever role creates a table generally owns it, so ownership decides who can later change that table's structure. The read-only user serves the Data API, including datastore_search and datastore_search_sql, and needs only read access to the tables meant to be public. Schema-level grants matter because they can expose more than the table-level grant you intended, so check both. Before running ckan datastore set-permissions, write down which role should reach which schema and tables, then compare the resulting grants against that list.

The read-only user must not own anything. An owner can change a table's structure, drop it, and grant rights to other roles, which is far more than a public read path needs. Check ownership after every load and every manual change, because a table created or reassigned through another role can end up owned by the wrong account without anyone noticing. Keep the DataStore database and its credentials separate from the CKAN metadata database. If the same account or privileges reach both, a weakness in the public query path could expose user accounts and API tokens stored on the metadata side. Confirm the exact privilege behavior for your CKAN version before you rely on it.

Confirm the exact behavior in the DataStore documentation for the CKAN version you run, since grant handling and defaults can change between releases. DataStore documentation is the place to start. Then test the split directly: connect as the read-only user, confirm that a SELECT on a public table works, and confirm that CREATE, INSERT, ALTER and DROP are refused in the DataStore database. Also confirm that the read-only role cannot connect to the CKAN metadata database at all. Record the results with the configuration so a security reviewer can see that the separation was tested rather than assumed.

How CKAN, the write user and the read-only user reach the DataStore

The diagram starts with the CKAN web app and job workers, which hold the write connection to the DataStore database. The Data API sits in a separate zone and reaches the same database only through the read-only connection, including its SQL search path. Both roles live in the DataStore PostgreSQL database, which is separate from the CKAN metadata database. The metadata database has its own credentials and no DataStore access. When you review the setup, confirm that the Data API never uses the write user and that the read-only role is the only path from the read zone into the database.

Write and read paths meet only at the separate DataStore database.

Setting up the CKAN DataStore database and permissions in order

This sequence creates the DataStore database, the write and read-only roles that CKAN relies on, and the privileges that keep public read access separate from write access. Each step closes with a check, so a mistake shows up before any portal user sees a table. Confirm the exact command output and privilege list against the DataStore documentation for the CKAN version you install.

  1. Confirm PostgreSQL and CKAN versions are supported

    The platform team checks the PostgreSQL server version against the PostgreSQL versioning policy. That policy lists versions 15 through 18 as supported and states that version 14 reaches end of support on November 12, 2026, so confirm the list on the day you install. The CKAN install guide sets PostgreSQL 12 as the minimum, so choose a release that will stay in support for the life of the portal. Also confirm the target CKAN line against the CKAN release policy, which covers the latest patch of the current minor version and the previous minor version. Done when a query such as SELECT version(); returns a supported server release and the CKAN version is recorded in the change ticket.

  2. Create the separate DataStore database

    A PostgreSQL administrator creates a second database for the DataStore, separate from the database that holds CKAN's own catalog. Place it on the same cluster or a dedicated one, based on your backup and availability design. Keep the database owner as an administrator role so that application roles cannot change the schema or database settings. Back up and restore this database as its own unit, since it holds the table data behind every DataStore resource. Done when the database appears in the server's database list and the existing CKAN connection still works unchanged.

  3. Create the write and read-only roles

    The database administrator creates two login roles, each with its own generated password: one write role that CKAN uses to create and load DataStore tables, and one read-only role that the Data API uses to answer queries. Store both passwords in your secrets manager and label the roles clearly so nobody swaps them later. The read-only role is the one exposed to public queries, so its password should never appear in a template or a shared document. Done when each role logs in with its own password and the server refuses a wrong password for each.

  4. Set the write and read connection URLs

    Edit the CKAN configuration file to set ckan.datastore.write_url to the connection string for the write role, and ckan.datastore.read_url to the string for the read-only role. Both strings point at the DataStore database. Limit read access to the configuration file to the service account that runs CKAN, because the write string carries a password with table-creation rights. Keep the two strings in your secrets process so they are not copied into version control. Done when CKAN loads the configuration without errors and each URL names the role you intended.

  5. Run set-permissions and review privileges

    Run ckan datastore set-permissions with the CKAN configuration loaded. The command prints the SQL that grants the read-only role access to DataStore tables and limits what that role can change. Read every statement before applying it, and compare the privilege list with the DataStore documentation for your installed version, since the list can change between releases. Apply the reviewed output to the DataStore database as an administrator. Done when the read-only role can connect to the DataStore database and a CREATE TABLE attempt made as that role is refused with a permission error.

  6. Restart the CKAN services

    Restart the CKAN web application and the background job worker so both load the new connection URLs. Use the service manager your deployment already uses, and restart the web tier and the workers together so they do not run with different settings. Watch the logs during startup for DataStore connection or permission errors. Note any error that mentions the read-only role, since it usually points to a grant that set-permissions did not make. Done when both services start cleanly and the logs show no DataStore connection or permission errors.

  7. Load a test resource and verify access

    Upload a small CSV as a test resource on a private dataset, then load it into the DataStore with the loader your portal uses, such as XLoader. Wait for the loading job to finish and confirm the table exists in the DataStore database. Call datastore_search on the resource through the Data API, then attempt an INSERT through the read-only connection to confirm it is refused. Done when the rows return through the API, the job reports completion, and the write attempt fails with a permission error.

What goes wrong when the CKAN DataStore read-only user is misconfigured

The read-only role is the last control between a public, unauthenticated Data API and the DataStore tables. The API layer checks queries in CKAN, but the database grants decide what the role can do even if a query gets past those checks. The four failures below each weaken that backstop in a different way.

Read-only user has write rights

The read-only role should hold SELECT only on DataStore tables. If it also has INSERT, UPDATE, DELETE or CREATE rights, the public Data API becomes a write path whenever a query runs under that role. The datastore_search_sql endpoint accepts only a single SELECT, but that check runs in CKAN, so the database grants are the only backstop if it fails. Check by connecting as the read-only user and attempting an INSERT, an UPDATE, a DELETE and a CREATE TABLE. Each attempt should fail with a permission error.

CKAN DataStore docs

Read-only user owns the tables

Table owners can change table structure, grant privileges to themselves and drop tables. Ownership carries those powers even after write grants have been revoked. If the read-only role created the DataStore tables or owns the schema, revoking its write privileges will not stop it from altering or deleting data. The write user should own the tables, and the read-only role should hold only SELECT. Check ownership by listing tables with psql or querying pg_tables for tableowner, then confirm the read-only role appears nowhere in the output.

Read-only user reaches the CKAN database

The DataStore lives in a separate database from the CKAN metadata database. CKAN's metadata database holds user accounts, password hashes, API tokens and the metadata for private datasets. If the read-only role can connect to that database, directly or through the default CONNECT privilege granted to PUBLIC, a leaked read-only URL exposes far more than DataStore rows. Grant CONNECT only to the roles that need it. Check by running psql with the read-only URL against the CKAN database and confirming that authentication fails.

Same password for both users

The write and read-only roles appear in separate connection URLs, and different processes read each one. If both roles share one password, anyone who obtains the read-only URL from a config file, log, container environment or backup can log in as the write user and change data. Give each role its own generated password, store them separately and rotate the read-only password without touching the write one. Check by attempting a login as the write user with the read-only password. It should fail.

Testing the CKAN DataStore database setup by environment

On a single server, CKAN, PostgreSQL and the DataStore share one machine, so the tests focus on local role boundaries more than network paths. The database usually listens only on the loopback interface or a Unix socket, network rules are mostly internal, and certificate handling rarely applies. The main risk is a read-only role that can still reach the CKAN metadata database inside the same cluster, and the same team usually controls both the grants and the host configuration.

  • Write user test: Connect with the write URL, create a scratch table, load a few rows, then drop the table. Use a test resource, not production data.
  • Read-only select test: Connect with the read-only URL and run a SELECT against a loaded table. The query should succeed.
  • Denied writes test: With the read-only URL, attempt INSERT, UPDATE, DELETE and ALTER TABLE on that table. Each should fail with a permission error, and the table should be unchanged afterward.
  • Metadata isolation test: Attempt to connect as the read-only role to the CKAN metadata database. The connection should be refused. Review the pg_hba.conf entries to confirm they match the roles and databases you intended.
  • Data API read path: Call datastore_search for the loaded resource and confirm rows return. Repeat the call anonymously if the resource is public.

Confirm that the database administrator account is not shared with the application and that only your administrators can edit pg_hba.conf or run ckan datastore set-permissions.

Security and operations after the DataStore goes live

Setup ends with working users and grants, but the DataStore stays protected only while its controls keep running. The six controls below cover how clients authenticate, how connections are encrypted, how credentials and backups are handled, and how grants are checked over time. Each card names an owner and what to confirm in your own environment.

Password authentication method

PostgreSQL 18 deprecated MD5 password authentication in favor of SCRAM, so new and rotated DataStore passwords should use SCRAM only. The platform or database team owns this setting in pg_hba.conf and password_encryption. Confirm that no MD5 entries remain for the write or read-only users, and check the client authentication page for certificate or LDAP options if your identity team prefers one of them.

PostgreSQL authentication methods

TLS on connections

Every connection from CKAN and XLoader workers to the DataStore database should be encrypted on every hop, so passwords and query results never cross the network in clear text. The platform team owns the server certificate, the hostssl rules in pg_hba.conf, and the sslmode value in each connection URL. Confirm that clients verify the server certificate against a CA they trust, that plain host rules are absent for the DataStore database, and that the setting holds on worker hosts as well as the web servers.

Secret rotation for both users

The write user and the read-only user each have a password that appears in ckan.datastore.write_url and ckan.datastore.read_url, and often in worker settings too, so a change to one means updating every copy. The CKAN administrator and the security team share ownership of the rotation process. Confirm who holds each secret, which hosts store the connection URLs, that the old password stops working after rotation, and that CKAN and XLoader reconnect cleanly before the change is closed.

Backups and point-in-time recovery

The DataStore is its own PostgreSQL database, so a restore must be tested before it is needed. Point-in-time recovery depends on archived write-ahead logs (WAL) on top of a base backup, and the database or operations team owns both. Confirm that the backup captures cluster roles, because pg_dump on a single database does not include them, that a restore has been tested to a chosen point in time, and that restored roles still carry the read-only grant.

Continuous archiving docs

Rerunning set-permissions after changes

The ckan datastore set-permissions command applies the grants that keep the read-only user limited to reading. CKAN administrators own this step and should rerun it after any change to users, database ownership or the DataStore setup, then check the result each time. Confirm the command output for your CKAN version, verify that the read-only user can select from tables created since the last run, and verify that it cannot insert, update or delete. Record each run in your change log.

CKAN DataStore docs

Monitoring role grants

Grants drift when someone edits roles by hand or when a new table appears, so the read-only user must never gain write access without a recorded decision. The security team owns the review, and the database team supplies the query output. Confirm a scheduled check of role memberships, superuser and create privileges, and table privileges for both DataStore users, using catalog views such as pg_roles and information_schema.role_table_grants, with an alert when either changes unexpectedly.

Limits and versions to confirm before you configure anything

Confirm your PostgreSQL major version before you create any DataStore role, because the version you run sets how long the database stays supported. CKAN source installs require PostgreSQL 12 or newer, which is only the minimum, and PostgreSQL itself no longer supports 13 and earlier. PostgreSQL 14 reached the end of its support window on November 12, 2026, so a 14 cluster is now past end of support and needs an upgrade plan immediately. Versions 15, 16, 17 and 18 are supported until November 11, 2027, November 9, 2028, November 8, 2029 and November 14, 2030, respectively. Start any new cluster on one of those versions only after you confirm your CKAN release supports it. Run the PostgreSQL upgrade as its own change, with its own backup and rollback plan, and keep it separate from the DataStore permission work. PostgreSQL versioning policy

Confirm the exact CKAN minor version you run, because the DataStore setup you write depends on it. CKAN 2.12.0 was released on August 26, 2026, alongside maintenance releases 2.11.6 and 2.10.11. Patch releases do not break backwards compatibility, but minor releases may include backwards-incompatible changes. A permissions procedure you checked on 2.11 must be checked again on 2.12 before you reuse it. The project supports the latest patch of the current minor version and the previous minor version, and an older patch loses support once a newer one is out, so run the latest patch of the minor you choose. Review the CKAN release policy before you start.

Take three questions to the people who own the environment before you run anything. First, confirm the exact behavior of ckan datastore set-permissions in your CKAN release, including which privileges it grants to the read-only user and whether it must be rerun when new DataStore tables are created. Second, confirm the PostgreSQL versions your CKAN release supports in your build, whether a package, container image or source install, because the source install minimum says nothing about the other builds. Third, if you use a managed PostgreSQL service, ask the vendor whether you can create a separate DataStore database and two roles, whether the admin account holds the privileges the command needs, and which connection, extension and superuser limits apply. Get the answers in writing, because a wrong assumption here can change who is able to write to the DataStore.

Questions teams ask before setting up the DataStore database

How much does setting up the CKAN DataStore database cost?

Cost depends on how much work the setup creates, and the written scope sets the quote. The main drivers are the number of environments (development, test and production each need their own databases, roles and connection URLs), the database layout (a shared PostgreSQL server or a dedicated host), the depth of testing, and whether your team already has PostgreSQL and CKAN operations skills. Costs fall into two groups: one-time work to build and test the setup, and recurring work to review permissions, rotate credentials and apply PostgreSQL minor updates. Ask for a quote that shows each environment and each test as a separate line, so you can see what changes if you drop one.

How long does it take to set up the DataStore database?

Setup time depends on the database layout, the number of environments and how much testing the scope includes, so ask for a written timeline as part of the scope before work starts. One environment on a PostgreSQL server your team already administers moves faster than several environments that need new server access, network rules and separate credential approvals. Delays usually come from waiting for approvals and access, not from the commands themselves. Ask the provider to list each dependency, such as access approvals and change windows, with its owner and the date it is needed.

What does our team need to provide for DataStore setup?

Most of the work depends on four things from your side:

  • Access to the CKAN configuration files and to the service accounts that restart CKAN after changes.
  • A PostgreSQL administrator who can create databases and roles and approve the connection rules.
  • A test environment close enough to production to prove that the read-only user is restricted.
  • A named owner for the write and read-only credentials who decides who holds them and when they rotate.

Confirm these before the scope is signed, because a missing item usually stops the work until it arrives.

Can an internal team set up the CKAN DataStore alone?

Yes, an internal team can set up the DataStore database alone if it has someone with PostgreSQL privilege experience and a written test plan. Privilege experience means the person can create roles, grant table-level rights, set default privileges for new tables and confirm what a role can actually do. The test plan should cover the write user, the read-only user, the CKAN connection settings and a rejected write attempt through the read-only connection. Teams without CKAN operations experience usually need extra time to learn the DataStore extension and its upgrade path, so plan for that before you commit to a date.

How do I check that the DataStore read-only user is safe?

A read-only user is safe when every check below passes:

  • It can read DataStore tables but cannot INSERT, UPDATE, DELETE or CREATE anything.
  • It is not a superuser and holds no rights on the CKAN metadata database.
  • Its password differs from the write user's password, and its connection URL appears only in the read-only setting.

Test each point by connecting with the read-only URL and attempting a write, because a grant that looks correct in a listing can still allow changes. Rerun the same tests after upgrades and after any run of ckan datastore set-permissions.

What goes wrong if the DataStore read-only user is misconfigured?

A misconfigured read-only user can let callers change data or read tables that were never meant to be public. The read-only role is the database backstop: the Data API limits SQL search to a single SELECT, but that limit does not replace database permissions if the role has more rights than intended. Common mistakes include giving the read role the write password, granting rights on the CKAN metadata database and leaving default privileges that expose tables created later. Each mistake can turn a read path into a write path or expose data beyond the resource. Fix the grants first, then rotate any password that may have been exposed.

Which PostgreSQL version should back the CKAN DataStore?

Choose a PostgreSQL version that is still in support on the day you build, and confirm it works with your CKAN release. CKAN's source install guide requires PostgreSQL 12 or newer. The PostgreSQL project lists version 14 as supported only until November 12, 2026, so that window has already closed for new builds. Versions 15 through 18 are still in their support windows, with version 15 supported until November 11, 2027. Ask your provider or the CKAN release notes to confirm the version pairing before installation, and plan the major upgrade path at the start.

How DeployOpen works on this

DeployOpen plans the DataStore database, its write and read-only users and the connection URLs your CKAN instance uses as one piece of work, inside infrastructure you control. Each engagement starts with a written scope that names the PostgreSQL environment, the CKAN deployment and the access model. The work ends with tested permissions and documentation your operations and security teams can review.

How we scope

  • The written scope names the CKAN site, the PostgreSQL server and the DataStore databases.
  • We list which accounts get write access for loading and which get read-only access for public queries.
  • Fixed-scope engagements agree deliverables and timelines in writing before work starts, and ongoing support can run as a retainer.

How we build

  • Create the DataStore database and both users, and keep connection URLs in the secret store your team chooses.
  • Apply grants with ckan datastore set-permissions, then review the output against the access model in the scope.
  • Test that the read-only user can select rows but cannot insert, update, delete or create objects on DataStore tables.

How we hand over

  • A runbook records each user, its privileges, the connection URL locations and the exact commands used.
  • Test evidence covers the read-only checks, so your security team can rerun them after changes.
  • Handover walks the operators who rotate passwords through the steps needed to repeat them.

How we support

  • Retainers can cover CKAN and PostgreSQL upgrades, so the users and grants are checked after each change.
  • Retesting permissions after password rotation or CKAN upgrades can be written into the scope.
  • Ask for a retest schedule and an owner for each credential in the quote, so support boundaries stay clear.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.