Charmed PostgreSQL VM

Channel Revision Published Runs on
latest/stable 345 09 Nov 2023
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/stable 239 09 Feb 2022
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/stable 226 01 Apr 2021
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
14/stable 468 11 Sep 2024
Ubuntu 22.04
14/stable 467 11 Sep 2024
Ubuntu 22.04
14/candidate 529 29 Nov 2024
Ubuntu 22.04
14/candidate 528 29 Nov 2024
Ubuntu 22.04
14/beta 529 28 Nov 2024
Ubuntu 22.04
14/beta 528 28 Nov 2024
Ubuntu 22.04
14/edge 535 13 Dec 2024
Ubuntu 22.04
14/edge 534 13 Dec 2024
Ubuntu 22.04
16/edge 527 27 Nov 2024
Ubuntu 24.04
16/edge 526 27 Nov 2024
Ubuntu 24.04
juju deploy postgresql --channel 14/stable
Show information

Platform:

Ubuntu
24.04 22.04 20.04 18.04 16.04 14.04

How to integrate a database with your charm

Charmed PostgreSQL can be integrated with any charmed application that supports its interfaces. This page provides some guidance and resources for charm developers to develop, integrate, and troubleshoot their charm so that it may connect with PostgreSQL.

Summary

  • Check supported interfaces
  • Integrate your charm with PostgreSQL
  • Troubleshooting & testing
  • FAQ

Check supported interfaces

First, we recommend that you check the supported interfaces of the current charm. You have the option to use modern (preferred) or legacy interfaces.

Most existing charms currently use ops-lib-pgsql interface (legacy). For new charms, Canonical recommends using data-platform-libs.

Legacy charm details are described here.

Integrate your charm with PostgreSQL

See also: Juju documentation | Integration

For a detailed tutorial about integrating your charm with the PostgreSQL charm, refer to Juju | Integrate your charm with PostgreSQL.

For some practical examples, take a look at the following:

Troubleshooting & testing

FAQ

Does the requirer need to set anything in relation data?

It depends on the interface. Check the postgresql_client interface requirements.

Is there a charm library available, or does my charm need to compile the postgresql relation data on its own?

Yes, a library is available: data-platform-libs. The integration is trivial: example.

How do I obtain the database url/uri?

This feature is planned but currently missing.

Meanwhile, use this example or refer to the function below.

def _db_connection_string(self) -> str:
   """Report database connection string using info from relation databag."""
   relation = self.model.get_relation("database")
   if not relation:
       return ""

   data = self._database.fetch_relation_data()[relation.id]
   username = data.get("username")
   password = data.get("password")
   endpoints = data.get("endpoints")
   
   return f"postgres://{username}:{password}@{endpoints}/ratings"

Success stories

Contact us if you have any questions, issues, or ideas!