Charmed PostgreSQL K8s

Channel Revision Published Runs on
latest/stable 20 20 Sep 2022
Ubuntu 20.04
14/stable 73 18 Apr 2023
Ubuntu 22.04
14/candidate 139 19 Sep 2023
14/beta 145 26 Sep 2023
14/edge 150 Today
juju deploy postgresql-k8s --channel 14/stable
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

Methods

PostgreSQLCreateUserError. __init__( self , message: str )

class PostgreSQLDatabasesSetupError

Description

Exception raised when the databases setup fails. None

class PostgreSQLDeleteUserError

Description

Exception raised when deleting a user fails. None

class PostgreSQLEnableDisableExtensionError

Description

Exception raised when enabling/disabling an extension fails. None

class PostgreSQLGetPostgreSQLVersionError

Description

Exception raised when retrieving PostgreSQL version fails. None

class PostgreSQLListUsersError

Description

Exception raised when retrieving PostgreSQL users list fails. None

class PostgreSQLUpdateUserPasswordError

Description

Exception raised when updating a user password fails. None

class PostgreSQL

Description

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

Methods

PostgreSQL. __init__( self , primary_host: str , current_host: str , user: str , password: str , database: str , system_users )

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 privileges and/or roles to be assigned to the user.

PostgreSQL. delete_user( self , user: str )

Deletes a database user.

Arguments

user

user to be deleted.

PostgreSQL. enable_disable_extension( self , extension: str , enable: bool , database: str )

Enables or disables a PostgreSQL extension.

Description

Args: extension: the name of the extensions. enable: whether the extension should be enabled or disabled. database: optional database where to enable/disable the extension.

Raises: PostgreSQLEnableDisableExtensionError if the operation fails.

PostgreSQL. get_postgresql_version( self )

Returns the PostgreSQL version.

Returns

PostgreSQL version number.

PostgreSQL. is_tls_enabled( self , check_current_host: bool )

Returns whether TLS is enabled.

Arguments

check_current_host

whether to check the current host instead of the primary host.

Returns

whether TLS is enabled.

PostgreSQL. list_users( self )

Returns the list of PostgreSQL database users.

Returns

List of PostgreSQL database users.

PostgreSQL. list_valid_privileges_and_roles( self )

Returns two sets with valid privileges and roles.

Returns

Tuple containing two sets: the first with valid privileges and the second with valid roles.

PostgreSQL. set_up_database( self )

Description

Set up postgres database with the right permissions. None

PostgreSQL. update_user_password( self , username: str , password: str )

Update a user password.

Description

Args: username: the user to update the password. password: the new password for the user.

Raises: PostgreSQLUpdateUserPasswordError if the password couldn't be changed.

PostgreSQL. build_postgresql_parameters( profile: str , available_memory: int )

Builds the PostgreSQL parameters.

Arguments

profile

the profile to use.

available_memory

available memory to use in calculation in bytes.

Returns

Dictionary with the PostgreSQL parameters.