简体   繁体   中英

installing postgres via puppet with customer data_directory

I'm trying to install postgres 9.1 on an ubuntu 12.04 machine using puppet v3.4.3 and puppetlabs/postgresql module v3.3.0. I want the data_directory to point to a large disk I've mounted.

If I change the datadir property of postgresql::globals it doesn't seem to do anything. The postgres.conf file still has data_directory pointing to /var/lib/postgresql/9.1/main Then I tried also using postgresql::server::config_entry to change the data_directory param in postgres.config but that gives the following error:

Debug: Executing 'service postgresql reload'
Notice: /Stage[main]/Postgresql::Server::Reload/Exec[postgresql_reload]/returns:  * Reloading PostgreSQL 9.1 database server
Notice: /Stage[main]/Postgresql::Server::Reload/Exec[postgresql_reload]/returns:  * pg_ctl: PID file "/data/PGDATA/postmaster.pid" does not exist
Notice: /Stage[main]/Postgresql::Server::Reload/Exec[postgresql_reload]/returns: Is server running?
Notice: /Stage[main]/Postgresql::Server::Reload/Exec[postgresql_reload]/returns:    ...fail!
Error: /Stage[main]/Postgresql::Server::Reload/Exec[postgresql_reload]: Failed to call refresh: service postgresql reload returned 1 instead of one of [0]
Error: /Stage[main]/Postgresql::Server::Reload/Exec[postgresql_reload]: service postgresql reload returned 1 instead of one of [0]

I believe this fails because postgres was started before configuring the data_directory, and this parameter is part of the startup of the process so when you change the value it can no longer find the process to stop and start it. If I kill postgres and try to start it I get an error saying /data/PGDATA is not a valid directory, as the database was not created in the data_directory location I specified.

Finally I tried creating the user, group and file path, and then mounting the disk to /var/lib/postgresql/9.1/main all in puppet before puppet installs postgres, but I get this error:

Notice: /Stage[main]/Mm_postgres::Server/Postgresql::Server::Config_entry[checkpoint_segments]/Postgresql_conf[checkpoint_segments]/ensure: created
Error: Puppet::Util::FileType::FileTypeFlat could not write /etc/postgresql/9.1/main/postgresql.conf: No such file or directory - /etc/postgresql/9.1/main/postgresql.conf
Error: /Stage[main]/Mm_postgres::Server/Postgresql::Server::Config_entry[checkpoint_segments]/Postgresql_conf[checkpoint_segments]: Could not evaluate: Puppet::Util::FileType::FileTypeFlat could not write /etc/postgresql/9.1/main/postgresql.conf: No such file or directory - /etc/postgresql/9.1/main/postgresql.conf

I believe everything was done in the correct order, and permissions were fine, but I'll keep looking into this. Does anyone know if it is possible to install postgres via puppet on ubuntu and change the data_directory, and if so, how?

Thanks

Problem is that postgresql module from puppetlabs doesn't quite work with that kind of customization. I think there are even some bug reports out there. This is what I did, and it works without a problem:

file { '/data/postgresql':
  ensure => directory,
}
file { '/var/lib/postgresql':
  ensure  => link,
  target  => '/data/postgresql',
  before  => Class['::postgresql::server::install'],
}

class { '::postgresql::globals':
}->class { '::postgresql::server':
}

Hope it helps!

PS. I used puppetlabs-postgresql version 3.3.3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM