postgresql-k8s

Charmed PostgreSQL K8s

Channel Revision Published Runs on
latest/stable 20 20 Sep 2022
Ubuntu 20.04
14/stable 495 18 Feb 2025
Ubuntu 22.04
14/stable 494 18 Feb 2025
Ubuntu 22.04
14/candidate 495 11 Feb 2025
Ubuntu 22.04
14/candidate 494 11 Feb 2025
Ubuntu 22.04
14/beta 495 06 Feb 2025
Ubuntu 22.04
14/beta 494 06 Feb 2025
Ubuntu 22.04
14/edge 549 28 Mar 2025
Ubuntu 22.04
14/edge 548 28 Mar 2025
Ubuntu 22.04
16/beta 525 19 Mar 2025
Ubuntu 24.04
16/beta 524 19 Mar 2025
Ubuntu 24.04
16/edge 551 Yesterday
Ubuntu 24.04
16/edge 550 Yesterday
Ubuntu 24.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.


Index

class PostgreSQLAssignGroupError

Description

Exception raised when assigning to a group fails. None

class PostgreSQLCreateDatabaseError

Description

Exception raised when creating a database fails. None

class PostgreSQLCreateGroupError

Description

Exception raised when creating a group fails. None

class PostgreSQLCreateUserError

Description

Exception raised when creating a user fails. None

Methods

PostgreSQLCreateUserError. __init__( self , message )

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 PostgreSQLListGroupsError

Description

Exception raised when retrieving PostgreSQL groups list 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_access_groups( self )

Description

Create access groups to distinguish HBA authentication methods. None

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 , admin: bool , extra_user_roles )

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. grant_internal_access_group_memberships( self )

Description

Grant membership to the internal access-group to existing internal users. None

PostgreSQL. grant_relation_access_group_memberships( self )

Description

Grant membership to the relation access-group to existing relation users. None

PostgreSQL. enable_disable_extensions( self , extensions , database )

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_default_table_access_methods( self )

Returns the PostgreSQL available table access methods.

Returns

Set of PostgreSQL table access methods.

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_access_groups( self )

Returns the list of PostgreSQL database access groups.

Returns

List of PostgreSQL database access groups.

PostgreSQL. list_users( self )

Returns the list of PostgreSQL database users.

Returns

List of PostgreSQL database users.

PostgreSQL. list_users_from_relation( self )

Returns the list of PostgreSQL database users that were created by a relation.

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 )

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_group_map( group_map )

Build the PostgreSQL authorization group-map.

Arguments

group_map

serialized group-map with the following format: <ldap_group_1>=<psql_group_1>, <ldap_group_2>=<psql_group_2>, ...

Returns

List of LDAP group to PostgreSQL group tuples.

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.

PostgreSQL. validate_group_map( self , group_map )

Validate the PostgreSQL authorization group-map.

Arguments

group_map

serialized group-map with the following format: <ldap_group_1>=<psql_group_1>, <ldap_group_2>=<psql_group_2>, ...

Returns

Whether the group-map is valid.