Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smaiyaki opened this issue Apr 15, 2020 · 35 comments
Labels

Comments

@smaiyaki
Copy link

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

@stale
Copy link

stale bot commented Jul 14, 2020

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 stale bot added the stale label Jul 14, 2020
@copolycube
Copy link

copolycube commented Jul 14, 2020

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

@stale
Copy link

stale bot commented Jul 14, 2020

This issue is no longer marked for closure.

@stale stale bot removed the stale label Jul 14, 2020
@stale
Copy link

stale bot commented Oct 12, 2020

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 stale bot added the stale label Oct 12, 2020
@copolycube
Copy link

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

@stale
Copy link

stale bot commented Oct 19, 2020

This issue is no longer marked for closure.

@stale stale bot removed the stale label Oct 19, 2020
@sergei-maertens
Copy link

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
Copy link

flo-rian commented Nov 26, 2020

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
Copy link

stale bot commented Apr 10, 2021

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 stale bot added the stale label Apr 10, 2021
@misilot
Copy link

misilot commented Apr 15, 2021

not stale

@stale
Copy link

stale bot commented Apr 15, 2021

This issue is no longer marked for closure.

@stale stale bot removed the stale label Apr 15, 2021
misilot pushed a commit to misilot/ansible-role-postgresql that referenced this issue May 10, 2021
@marcuslang
Copy link

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
Copy link

syswipe commented Sep 9, 2021

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
Copy link

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
Copy link

@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
Copy link

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

@stale
Copy link

stale bot commented May 2, 2022

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 stale bot added the stale label May 2, 2022
@misilot
Copy link

misilot commented May 2, 2022

not stale

@stale
Copy link

stale bot commented May 2, 2022

This issue is no longer marked for closure.

@stale
Copy link

stale bot commented Sep 19, 2022

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 stale bot added the stale label Sep 19, 2022
@misilot
Copy link

misilot commented Sep 20, 2022 via email

@stale
Copy link

stale bot commented Sep 20, 2022

This issue is no longer marked for closure.

@stale stale bot removed the stale label Sep 20, 2022
@stale
Copy link

stale bot commented Dec 24, 2022

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 stale bot added the stale label Dec 24, 2022
@misilot
Copy link

misilot commented Dec 24, 2022 via email

@stale
Copy link

stale bot commented Dec 24, 2022

This issue is no longer marked for closure.

@stale stale bot removed the stale label Dec 24, 2022
misilot pushed a commit to misilot/ansible-role-postgresql that referenced this issue Feb 21, 2023
misilot pushed a commit to misilot/ansible-role-postgresql that referenced this issue Feb 21, 2023
@denbon05
Copy link

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'",

misilot pushed a commit to misilot/ansible-role-postgresql that referenced this issue Jun 26, 2023
@github-actions
Copy link

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 github-actions bot added the stale label Jul 28, 2023
@misilot
Copy link

misilot commented Aug 1, 2023

no stale

@github-actions github-actions bot removed the stale label Aug 4, 2023
Copy link

github-actions bot commented Dec 8, 2023

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 github-actions bot added the stale label Dec 8, 2023
@misilot
Copy link

misilot commented Dec 9, 2023 via email

@github-actions github-actions bot removed the stale label Dec 15, 2023
@Urgarth
Copy link

Urgarth commented Mar 9, 2024

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

misilot pushed a commit to misilot/ansible-role-postgresql that referenced this issue Mar 10, 2024
Copy link

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 github-actions bot added the stale label Jul 12, 2024
@misilot
Copy link

misilot commented Jul 12, 2024 via email

@github-actions github-actions bot removed the stale label Jul 19, 2024
Copy link

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 github-actions bot added the stale label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests