installing postgres via puppet with customer data_directory - postgresql

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

Related

Postgres database cluster initialization failed on windows upon installation?

I'm trying to install postgreSQL on my windows 10 computer for the first time. I got an error at the end of the installation saying that there was a "problem running post-install step. Installation may not complete correctly. The database cluster initialization failed."
When I run the sql shell I get an error trying to do the default login that says 'chcp' is not recognized as an internal or external command. I set the environmental path variable to the bin of the Postgres folder in my program files. I also tried a number of other (but very dated) solutions to similar problems users experienced such as moving my data directory outside of the Postgres directory entirely. Most of these solutions date back to 2012 and don't seem to work anymore.
The one that seemed closest to working is postgresql installation failed.
However, I can't find "postgres" as a user. I get an error saying:
"An object named "postgres" cannot be found. Check the selected object types and location for accuracy and ensure that you typed the object name correctly, or remove this object from the selection."
Does anybody have any updated solutions/tips for this?

PostgreSQL "initdb" (Database Initialization) on Linux

I'm working on creating a Database Cluster (single database) in PostgreSQL 9.x working on a Linux system (CentOS - RedHat - Fedora). I've installed the correct PostgreSQL packages (server & client) however, I'm unable to create a database and get some type of initializing dependencies error: Bus Error / Exit Code 135. I've changed my user to "postgres" with "su postgres" and then tried to initialize the database with "initdb" (this may be the problem)
Installed: postgresql-libs-9.2.13-1.el7_1.x86_64
Installed: postgresql-9.2.13-1.el7_1.x86_64
Installed: postgresql-server-9.2.13-1.el7_1.x86_64
$ initdb -D /usr/local/pgsql/data
http://www.postgresql.org/docs/9.2/interactive/creating-cluster.html
Error:
$ initdb -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
creating directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... sh: line 1: 12616 Bus error (core dumped) "/usr/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 > /dev/null
child process exited with exit code 135
Any ideas?
After installing PostgreSQL (server and client tools) one needs to run the following commands as ROOT ("su"). The key step is to start "service postgresql initdb" and let it initialize your PostgreSQL database.
If you have any errors you need to remove the empty install "data" directories and read all log files carefully.
# service postgresql initdb
# systemctl enable postgresql
# systemctl start postgresql
After doing the above verify that postgres is in /var/lib/pgsql and a running process with "ps -ef | grep postgres" (its on port 5432)
If you run into any other problems you may need to create or modify a postgres user/password or clean a postgres data directory out.
If you installed from packages, you should use the package's provided methods for creating the DB. For the PDGD RPMs (from http://yum.postgresql.org/) that's documented in the README.rpm-dist:
/usr/pgsql-9.4/bin/postgresql94-setup initdb
However, the error you're getting really shouldn't happen. It suggests a hardware incompatibility or a low level issue like an incompatible C library. Perhaps you force-installed RPMs from a different OS or version?
Update:
Seems very likely to be a C library incompatibility. Perhaps an issue between RHEL and CentOS? Or version related? That's a fault in the dynamic linker. dl-lookup.c will be glibc/elf/dl-lookup.c and it seems to be crashing during symbol lookup. So there's something really wonky here, like a corrupt symbol hash table in the binary or an incompatibility between the binary and the dynamic linker used. Or a memory fault, disk fault, CPU cache issue, or other hardware error.
If rebooting makes it go away I'd be very suspicious of the hardware. If it doesn't, you might have something really wonky on the system like some 3rd party unpackaged installer overwriting the original C library / dynamic linker, that sort of weirdness.

Changing postgresql 9.3 database location on Amazon ec2 linux

I apologize for the long post. I have a Postgresql 9.3 server running on a Amazon linux AMI. I also have a compressed dump file from another server which I created using pg_dumpall. Now, I want to restore the data from this dump file in my Postgres. However, I want to load this data into a specific location (say /data).
I'm having a fresh installation of Postgres. So when I tried to do a:
sudo service postgresql93 start
I got an error message asking me to initialize the db. So I did a:
sudo service postgresql initdb
which created the required files in /var/lib/pgsql93/data. After that, I changed the 'data_directory' configuration in /var/lib/pgsql93/data/postgresql.conf and pointed it to /data (I had to do this as root user. I couldn't open the file as the default user).
Now when I try to do a
sudo service postgresql93 start
it fails to start, and when I check the /var/lib/pgsql93/pg_startup.log file, it says:
FATAL: "/data/postgresql" is not a valid data directory
DETAIL: File "/data/postgresql/PG_VERSION" is missing.
So I copied the files from the default (/var/lib/pgsql9.3/data) to /data, changed the permissions to 700 and owner to postgres.
However, when I try to start the service again, it still fails, and in the pgstartup.log, it only says:
LOG: redirecting log output to logging collector process
HINT: Future log output will appear in directory "pg_log".
And when I check the log in /data/pg_log, it says:
LOG: database system was shut down at 2014-12-30 21:31:18 UTC
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
What else could be the problem? I haven't restored the data yet. I just have the files which were created by the initdb command.
#BMW http://www.linuxquestions.org/questions/linux-server-73/change-postgresql-data-directory-649911/ is exactly what I was looking for. Thanks.

Postgresql and SSL certificat

I'm trying to install PostgreSQL with another data directory.
The problem comes when I try to start postgresql I have the following error :
Starting PostgreSQL 9.1 database server: main[....] The PostgreSQL server failed to start. Please check the log output: 2014-04-16 22:14:51 CEST FATAL: could not load server [FAILficate file "server.crt": No such file or directory ... failed!
failed!
I've tried a lot of things coming from here or here but nothing works for me.
My configuration file is in /etc/postgresql/9.1/main/ but I don't know why I have a some other configuration files on my new data directory. (visibly they are not used).
Naturally I can fix this bug by commenting the ssl = true on the postgresql.conf but it's not at all the aim.
According to the PostgreSQL Reference you should check your $PGDATA directory for the server.crt file. In cases is missing you should either request a new certificate or make self signed one and place the file there.

PostgreSQL issue: could not access file "$libdir/plpgsql": No such file or directory

I get this exception in PostgreSQL:
org.postgresql.util.PSQLException: ERROR: could not access file "$libdir/plpgsql": No such file or directory
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1721)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1489)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:193)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:337)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:236)
at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:205)
I searched a lot and most solution points to a wrong installation. But this is my test db which has been running without issues for a long time. Also inserts are working. Issue occurs only on select queries.
Apparently, you moved your PostgreSQL lib directory out of place. To confirm this, try the following in psql:
> SET client_encoding TO iso88591;
ERROR: could not access file "$libdir/utf8_and_iso8859_1": No such file or directory
If you get an error message like this, then my theory is correct. You'll need to find out where those files ended up, or you can reinstall PostgreSQL to restore them.
To find out what $libdir is referring to, run the following command:
pg_config --pkglibdir
For me, this produces:
/usr/lib/postgresql
I have the same problem: the other postgres server instance (8.4) was interfering with the 9.1 one; when the 8.4 instance is removed it works.
the other instance can sometimes be removed from the system while still running (e.g. you do a gentoo update and a depclean without stopping and migrating your data). so the error seems particularly mysterious.
the solution is usually going to be doing a slot install/eselect of the old version (in gentoo terms, or simply downgrading on other distros), running its pg_dumpall, and then uninstalling/reinstalling the new version and importing the data.
this worked pretty painlessly for me