PostgreSQL

  • By Data Platform
Channel Version Revision Published Runs on
latest/stable 20 20 20 Sep 2022
Ubuntu 20.04
latest/edge 32 32 17 Nov 2022
Ubuntu 20.04
juju deploy postgresql-k8s
Show information

Platform:

charms.postgresql_k8s.v0.postgresql

PostgreSQL helper class.

The postgresql module provides methods for interacting with the PostgreSQL instance.

Any charm using this library should import the psycopg2 or psycopg2-binary dependency.


class PostgreSQLCreateDatabaseError

Description

Exception raised when creating a database fails. None

class PostgreSQLCreateUserError

Description

Exception raised when creating a user fails. None

class PostgreSQLDeleteUserError

Description

Exception raised when deleting a user fails. None

class PostgreSQLGetPostgreSQLVersionError

Description

Exception raised when retrieving PostgreSQL version fails. None

class PostgreSQL

Description

Class to encapsulate all operations related to interacting with PostgreSQL instance. None

Methods

PostgreSQL. __init__( self , host: str , user: str , password: str , database: str )

PostgreSQL. _connect_to_database( self , database: str )

Creates a connection to the database.

Arguments

database
database to connect to (defaults to the database provided when the object for this class was created).

Returns

psycopg2 connection object.

PostgreSQL. create_database( self , database: str , user: str )

Creates a new database and grant privileges to a user on it.

Arguments

database
database to be created.
user
user that will have access to the database.

PostgreSQL. create_user( self , user: str , password: str , admin: bool , extra_user_roles: str )

Creates a database user.

Arguments

user
user to be created.
password
password to be assigned to the user.
admin
whether the user should have additional admin privileges.
extra_user_roles
additional roles to be assigned to the user.

PostgreSQL. delete_user( self , user: str )

Deletes a database user.

Arguments

user
user to be deleted.

PostgreSQL. get_postgresql_version( self )

Returns the PostgreSQL version.

Returns

PostgreSQL version number.