vitabaks / postgresql_cluster

PostgreSQL High-Availability Cluster (based on "Patroni" and DCS "etcd" or "consul"). Automating with Ansible.
MIT License
1.29k stars 352 forks source link

How to add custom paramters in postgresql.conf #553

Closed shailabsinghha closed 4 months ago

shailabsinghha commented 4 months ago

I want to use some global current_setting params in the db for some of my use cases. I would like it to be part of the configuration. How can we achieve that? I can see the. main.yml parameters change the pgbouncer configuration however I could not find any reference to postgresql.conf file parameters or options as such. Prompt answers will be much appreciated!

Please find a sample query for getting the custom-added field

select current_setting('encrypt.key');

vitabaks commented 4 months ago

You can define the Postgres parameters in the postgresql_parameters variable.

shailabsinghha commented 4 months ago

There is a postgresql.conf file in /var/lib/postgresql/15/main location. I would like to add a custom parameter here such that it can be picked from current_settingsomething like select current_setting('encrypt.key');. I think that patronictl showconfig and postgresql.conf are different.

What I have tried so far to achieve this with this project

  1. adding encrypt.key in postgresql_parameters and run update_pgcluster.yml
  2. Manually adding encrypt.key = 'some_secret' and reloading using SIGHUP asselect pg_reload_conf() in master node
  3. Manually adding encrypt.key = 'some_secret' and reloading using systemctl restart postgresql
  4. systemctl restart patroni in the master node

Nothing worked so far. Am I missing something here?

vitabaks commented 4 months ago

To change the Postgres configuration in a cluster using automation:

1) change the parameters in the postgresql_parameters variable. You can also specify the pending_restart: true variable so that Postgres is automatically restarted if a parameter change requires a restart. 2) run config_pgcluster.yml playbook to apply changes.

vitabaks commented 4 months ago

@shailabsinghha The encrypt.key parameter is not a standard PostgreSQL setting and is not mentioned in the official PostgreSQL documentation. Is this most likely related to some kind of third-party extension?

shailabsinghha commented 4 months ago

To change the Postgres configuration in a cluster using automation:

  1. change the parameters in the postgresql_parameters variable. You can also specify the pending_restart: true variable so that Postgres is automatically restarted if a parameter change requires a restart.
  2. run config_pgcluster.yml playbook to apply changes.

This worked. Prompt response is appreciated 🙌

shailabsinghha commented 4 months ago

@shailabsinghha The encrypt.key parameter is not a standard PostgreSQL setting and is not mentioned in the official PostgreSQL documentation. Is this most likely related to some kind of third-party extension?

encrypt.key is a custom parameter which I was using in my project. It is not related to any PostgreSQL Official config parameters or third party extension

shailabsinghha commented 4 months ago

To change the Postgres configuration in a cluster using automation:

  1. change the parameters in the postgresql_parameters variable. You can also specify the pending_restart: true variable so that Postgres is automatically restarted if a parameter change requires a restart.
  2. run config_pgcluster.yml playbook to apply changes.

This worked. Prompt response is appreciated 🙌