ansible-role-postgresql icon indicating copy to clipboard operation
ansible-role-postgresql copied to clipboard

The postgres_data_dir variable seems not used when initialising the database

Open smaiyaki opened this issue 5 years ago • 34 comments

I have installed postgres 9.6 on ubuntu 16 with the aid of your ansible role which is great. One thing I have noticed however is that the database is initialised using the data path /var/lib/postgresql/9.6/main regardless of what was set in the variable postgresql_data_dir .

So it seems the database has been silently initialized with the default postgres data path and before the database directory is then set as I can see in the logs

TASK [geerlingguy.ansible-role-postgresql : Set PostgreSQL environment variables.] ********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************* --- before +++ after: /root/.ansible/tmp/ansible-local-162q6gPKU/tmp5REmaJ/postgres.sh.j2 @@ -0,0 +1,2 @@ +export PGDATA=/custom_path/database/data/postgresql/9.6/main +export PATH=$PATH:/usr/lib/postgresql/9.6/bin

TASK [geerlingguy.ansible-role-postgresql : Set PostgreSQL environment variables.] ********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************* changed: [10.90.22.11] Wednesday 15 April 2020 11:27:15 +0000 (0:00:02.252) 0:08:02.882 *******

TASK [geerlingguy.ansible-role-postgresql : Ensure PostgreSQL data directory exists.] ****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** --- before +++ after @@ -1,7 +1,7 @@ {

  • "group": 0,
  • "mode": "0755",
  • "owner": 0,
  • "group": 121,
  • "mode": "0700",
  • "owner": 116, "path": "/custom_path/database/data/postgresql/9.6/main",
  • "state": "absent"
  • "state": "directory" }

TASK [geerlingguy.ansible-role-postgresql : Ensure PostgreSQL data directory exists.] ****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** changed: [10.90.22.11] Wednesday 15 April 2020 11:27:16 +0000 (0:00:00.969) 0:08:03.851 ******* Wednesday 15 April 2020 11:27:17 +0000 (0:00:00.943) 0:08:04.794 *******

TASK [geerlingguy.ansible-role-postgresql : Ensure PostgreSQL database is initialized.] **************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** changed: [10.90.22.11] Wednesday 15 April 2020 11:27:18 +0000 (0:00:01.621) 0:08:06.416 ******* Wednesday 15 April 2020 11:27:18 +0000 (0:00:00.082) 0:08:06.499 *******

TASK [geerlingguy.ansible-role-postgresql : Configure global settings.] ******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** --- before: /etc/postgresql/9.6/main/postgresql.conf (content) +++ after: /etc/postgresql/9.6/main/postgresql.conf (content) @@ -38,7 +38,7 @@

The default values of these variables are driven from the -D command-line

option or PGDATA environment variable, represented here as ConfigDir.

-data_directory = '/var/lib/postgresql/9.6/main' # use data in another directory +data_directory = '/custom_path/database/data/postgresql/9.6/main' # (change requires restart) hba_file = '/etc/postgresql/9.6/main/pg_hba.conf' # host-based authentication file # (change requires restart)

TASK [geerlingguy.ansible-role-postgresql : Configure global settings.] ******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** changed: [10.90.22.11] => (item={u'option': u'data_directory', u'value': u'/custom_path/database/data/postgresql/9.6/main'}) Wednesday 15 April 2020 11:27:19 +0000 (0:00:01.043) 0:08:07.543 *******

The workaround am using at the moment is to run an rsyn command to copy the data directory using this command below. which introduces some inconsistencies sometimes

service postgresql stop rsync -av /var/lib/postgresql /custom_path/database/data mv /var/lib/postgresql /var/lib/postgresql.bak service postgresql start

smaiyaki avatar Apr 15 '20 11:04 smaiyaki

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Jul 14 '20 11:07 stale[bot]

Hello, we are still facing this issue and were not able to cleanly resolve it.

copolycube avatar Jul 14 '20 18:07 copolycube

This issue is no longer marked for closure.

stale[bot] avatar Jul 14 '20 18:07 stale[bot]

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Oct 12 '20 18:10 stale[bot]

Indeed, it is stale, but the issue still exists :-)

copolycube avatar Oct 19 '20 19:10 copolycube

This issue is no longer marked for closure.

stale[bot] avatar Oct 19 '20 19:10 stale[bot]

That's peculiar, I just installed from official CentOS repo's using this role and overwrote a number of variables, including:

postgresql_data_dir: "/var/lib/pgsql/{{ postgresql_version }}/data"

which correctly initialized the database in /var/lib/pgsql/11/data.

sergei-maertens avatar Nov 18 '20 17:11 sergei-maertens

I've used the version 13 packages from https://www.postgresql.org/download/linux/redhat/ I used postgresql_config_path: /var/lib/pgsql/13 for config and postgresql_data_dir: /data/postgresql for data but the role fails with

TASK [geerlingguy.postgresql : Configure global settings.] ****************************************************************************
failed: [pn] (item={'option': 'unix_socket_directories', 'value': '/var/run/postgresql'}) => {"ansible_loop_var": "item", "changed": false, "item": {"option": "unix_socket_directories", "value": "/var/run/postgresql"}, "msg": "Destination /var/lib/pgsql/13/postgresql.conf does not exist !", "rc": 257}

It turns out the config dir only contains an empty backup and data directory and all the config ends up in the data directory.

Running the "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}" command creates all config file inside the data directory. This seems a bit odd to me. I know it is not the distribution install but the official packages from postgresql. So I assume the role should work with that. Is it a bug of the postgresql packages? Anyone got experience with other versions of postgresqlpackages?

flo-rian avatar Nov 26 '20 15:11 flo-rian

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Apr 10 '21 05:04 stale[bot]

not stale

misilot avatar Apr 15 '21 16:04 misilot

This issue is no longer marked for closure.

stale[bot] avatar Apr 15 '21 16:04 stale[bot]

I can confirm that this is an issue with Postgresql 13. I tried it with 12 and the custom postgres_data_dir works fine.

marcuslang avatar Jul 06 '21 06:07 marcuslang

I defined postgresql_data_dir and it doesn't work. custom data dir was successfully initialized, but PostgreSQL still starts with the default one

syswipe avatar Sep 09 '21 14:09 syswipe

This worked for me:

postgresql_global_config_options:
  - option: data_directory
    value: "/custom/data/dir"

postgresql_data_dir: /custom/data/dir		

The postgresql_data_dir variable only initializes a database in the given directory.

christopheg avatar Oct 08 '21 13:10 christopheg

@christopheg solution worked for me (Ubuntu 20). The database gets initialized in the directory set through postgresql_data_dir, but is not used in the postgresql.conf. The variable should be handled in the task Configure global settings or afterwards.

captain-proton avatar Dec 01 '21 14:12 captain-proton

Is this still an issue for using a custom data directory?

MichaelDBA avatar Feb 01 '22 13:02 MichaelDBA

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar May 02 '22 18:05 stale[bot]

not stale

misilot avatar May 02 '22 18:05 misilot

This issue is no longer marked for closure.

stale[bot] avatar May 02 '22 18:05 stale[bot]

I can't install postgresql-14 because in some places role uses correct version of pg (14) but sometimes uses version 13.

TASK [geerlingguy.postgresql : Ensure PostgreSQL database is initialized.] ********************************************************************************************************************************
fatal: [xxx]: FAILED! => {"changed": false, "cmd": "/usr/lib/postgresql/13/bin/initdb -D /var/lib/postgresql/13/main", "msg": "[Errno 2] No such file or directory: b'/usr/lib/postgresql/13/bin/in
itdb'", "rc": 2}

marcin-github avatar May 18 '22 19:05 marcin-github

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Sep 19 '22 23:09 stale[bot]

not stale ...

On Mon, Sep 19, 2022 at 6:19 PM stale[bot] @.***> wrote:

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories to see the reasons why I mark issues as stale.

— Reply to this email directly, view it on GitHub https://github.com/geerlingguy/ansible-role-postgresql/issues/124#issuecomment-1251666766, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALBHSDOD4OSCQOBDEEPISLV7DYGNANCNFSM4MIQCFRQ . You are receiving this because you commented.Message ID: @.***>

misilot avatar Sep 20 '22 00:09 misilot

This issue is no longer marked for closure.

stale[bot] avatar Sep 20 '22 00:09 stale[bot]

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Dec 24 '22 03:12 stale[bot]

Not stale On Dec 23, 2022, at 10:17 PM, stale[bot] @.***> wrote: This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! Please read this blog post to see the reasons why I mark issues as stale.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

misilot avatar Dec 24 '22 04:12 misilot

This issue is no longer marked for closure.

stale[bot] avatar Dec 24 '22 04:12 stale[bot]

There is a problem with version: 3.4.3

- role: geerlingguy.postgresql
      postgresql_user: postgres
      postgresql_group: postgres
      # postgresql_global_config_options:
      #   - option: listen_addresses
      #     value: '*'
      #   - option: unix_socket_directories
      #     value: '{{ postgresql_unix_socket_directories | join(",") }}'
      #   - option: log_directory
      #     value: 'log'
      postgres_hba_entries:
        - type: host
          database: all
          user: all
          address: '127.0.0.1/32'
          method: trust
        - type: host
          database: all
          user: all
          address: '::1/128'
          method: md5
"msg": "[Errno 2] No such file or directory: b'/usr/lib/postgresql/14/bin/initdb'",

denbon05 avatar Mar 28 '23 21:03 denbon05

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

github-actions[bot] avatar Jul 28 '23 19:07 github-actions[bot]

no stale

misilot avatar Aug 01 '23 14:08 misilot

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

github-actions[bot] avatar Dec 08 '23 19:12 github-actions[bot]