Charmed PostgreSQL K8s

Channel Revision Published Runs on
latest/stable 20 20 Sep 2022
Ubuntu 20.04
14/stable 382 11 Sep 2024
Ubuntu 22.04
14/stable 381 11 Sep 2024
Ubuntu 22.04
14/candidate 382 09 Sep 2024
Ubuntu 22.04
14/candidate 381 09 Sep 2024
Ubuntu 22.04
14/beta 382 09 Sep 2024
Ubuntu 22.04
14/beta 381 09 Sep 2024
Ubuntu 22.04
14/edge 432 25 Oct 2024
Ubuntu 22.04
14/edge 431 25 Oct 2024
Ubuntu 22.04
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 PostgreSQLGetLastArchivedWALError

Description

Exception raised when retrieving last archived WAL fails. None

class PostgreSQLGetCurrentTimelineError

Description

Exception raised when retrieving current timeline id for the PostgreSQL unit 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 , plugins , client_relations )

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.

plugins

extensions to enable in the new database.

client_relations

current established client relations.

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_extensions( self , extensions , database: str )

Enables or disables a PostgreSQL extension.

Description

Args: extensions: the name of the extensions. database: optional database where to enable/disable the extension.

Raises: PostgreSQLEnableDisableExtensionError if the operation fails.

PostgreSQL. get_last_archived_wal( self )

Description

Get the name of the last archived wal for the current PostgreSQL cluster. None

PostgreSQL. get_current_timeline( self )

Description

Get the timeline id for the current PostgreSQL unit. None

PostgreSQL. get_postgresql_text_search_configs( self )

Returns the PostgreSQL available text search configs.

Returns

Set of PostgreSQL text search configs.

PostgreSQL. get_postgresql_timezones( self )

Returns the PostgreSQL available timezones.

Returns

Set of PostgreSQL timezones.

PostgreSQL. get_postgresql_version( self , current_host )

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 , database_host: str )

Update a user password.

Description

Args: username: the user to update the password. password: the new password for the user. database_host: the host to connect to.

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

PostgreSQL. is_restart_pending( self )

Description

Query pg_settings for pending restart. None

PostgreSQL. build_postgresql_parameters( config_options: Dict , available_memory: int , limit_memory )

Builds the PostgreSQL parameters.

Arguments

config_options

charm config options containing profile and PostgreSQL parameters.

available_memory

available memory to use in calculation in bytes.

limit_memory

(optional) limit memory to use in calculation in bytes.

Returns

Dictionary with the PostgreSQL parameters.

PostgreSQL. validate_date_style( self , date_style: str )

Validate a date style against PostgreSQL.

Returns

Whether the date style is valid.