geerlingguy / ansible-role-postgresql

Ansible Role - PostgreSQL
https://galaxy.ansible.com/geerlingguy/postgresql/
MIT License
570 stars 385 forks source link

The postgres_data_dir variable seems not used when initialising the database #124

Open smaiyaki opened 4 years ago

smaiyaki commented 4 years ago

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 @@ {

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

stale[bot] commented 4 years ago

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.

copolycube commented 4 years ago

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

stale[bot] commented 4 years ago

This issue is no longer marked for closure.

stale[bot] commented 4 years ago

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.

copolycube commented 4 years ago

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

stale[bot] commented 4 years ago

This issue is no longer marked for closure.

sergei-maertens commented 3 years ago

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.

flo-rian commented 3 years ago

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?

stale[bot] commented 3 years ago

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.

misilot commented 3 years ago

not stale

stale[bot] commented 3 years ago

This issue is no longer marked for closure.

marcuslang commented 3 years ago

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

syswipe commented 3 years ago

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

christopheg commented 3 years ago

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.

captain-proton commented 2 years ago

@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.

MichaelDBA commented 2 years ago

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

stale[bot] commented 2 years ago

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.

misilot commented 2 years ago

not stale

stale[bot] commented 2 years ago

This issue is no longer marked for closure.

marcin-github commented 2 years ago

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}
stale[bot] commented 2 years ago

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.

misilot commented 2 years ago

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: @.***>

stale[bot] commented 2 years ago

This issue is no longer marked for closure.

stale[bot] commented 1 year ago

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.

misilot commented 1 year ago

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: @.***>

stale[bot] commented 1 year ago

This issue is no longer marked for closure.

denbon05 commented 1 year ago

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'",
github-actions[bot] commented 1 year ago

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.

misilot commented 1 year ago

no stale

github-actions[bot] commented 11 months ago

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.

misilot commented 11 months ago

not stale

On Fri, Dec 8, 2023 at 1:57 PM github-actions[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-1847769345, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALBHSFQ7XUHN3L7TGINF5DYINWKTAVCNFSM4MIQCFR2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBUG43TMOJTGQ2Q . You are receiving this because you commented.Message ID: @.***>

Urgarth commented 8 months ago
"msg": "[Errno 2] No such file or directory: b'/usr/lib/postgresql/14/bin/initdb'",

same on 3.5.0 version, Ubuntu 22:

fatal: [localhost]: FAILED! => {"changed": false, "cmd": "/usr/lib/postgresql/14/bin/initdb -D /var/lib/postgresql/14/main", "msg": "[Errno 2] No such file or directory: b'/usr/lib/postgresql/14/bin/initdb'", "rc": 2, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

As far as I see, there is 16 version directory, not 14.

github-actions[bot] commented 3 months ago

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.

misilot commented 3 months ago

no stale

On Fri, Jul 12, 2024 at 2:57 PM github-actions[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-2226265314, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALBHSAUYXAMPVDFV5JHKJLZMAYK5AVCNFSM4MIQCFR2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMRSGYZDMNJTGE2A . You are receiving this because you commented.Message ID: @.***>