Postgresql and SSL certificat - postgresql

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.

Related

Postgresql and ssl start up error

I am new to freenode and postgresql. I am trying to migrate from mysql to postgresql. Currently trying to set up server for ssl. Have created my server certs and configured the .conf files for ssl according to the manual as far as I can see. Trying to restart postgre sql service fails. Windows event log gives me an event ID of 0 and says
pg_ctrl could not start server examine the log output.
I can't find any log detailing the failure to start in the postgresql folders.
I have tried to register the pgevent.dll as advised by the postgresql manual (18.11 of most recent version), but I get an error message
The module "C:postgreSQL\pg10\lib\postgresql\pgevent.dll" was loaded but the entry-point DllRegisterServer was not found
I believe that means it is either not a registrable dll or it's corrupt.
Can anyone please advise how I can track on Windows the error that is causing Postgre to fail to start?

psql: FATAL: could not open file "base/11951/11717": Read-only file system

I'm trying to access the postgreSQL database from CLI. When I login as postgres and enter command
I'm getting error
psql: FATAL: could not open file "base/11951/11717": Read-only file system
I'm new to this. Any pointers on where to look at would be a great help. TIA
Seems like the VM where the database was hosted went to Read-only mode for an unknown issue.
$ fsck
command helped to repair linux filesystems and was able to access psql db.
Most likely your system has detected disk errors and put the filesystem in read-only mode to protect its self from possible corruption.
Check dmesg and the kernel log files.
I strongly advise you to read and act on https://wiki.postgresql.org/wiki/Corruption .
Sometimes It indicates that the server had a general error...(Happened to me yesterday, the moment the server was restarted, the "FATAL: could not open file" disappeared.

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.

Couldn't drop staging_database : #<PG::ConnectionBad: FATAL: no pg_hba.conf

For a system that I am using, I run into the problem pasted on the title when I try to drop a database and recreate it. More specifically, this is the exact problem that I am facing:
Couldn't drop staging_databse : #<PG::ConnectionBad: FATAL: no pg_hba.conf entry for host xxx.xx.xxxx.xxx, user "ruby", database "postgres", SSL off
I've done some research regarding this problem and it seems that the solution is simply to turn on SSL. I've consulted Postgresql Documentation on pg_hba.conf but I'm unable to find this configuration file.
I typed in locate postgresql and I noticed that there is a postgresql-client-9.2 installed on the system. From what I have determined, I won't find this pg_hba.conf file because the client doesn't have it. I've also looked for the postgresql.conf file on SSL according to the official documentation but this file is not included either.
Finally, the documentation shows me this configuration option of the pgsql 9.2 client shown below:
libpq reads the system-wide OpenSSL configuration file. By default,
this file is named openssl.cnf and is located in the directory reported by
openssl version -d. This default can be overridden by setting environment
variable OPENSSL_CONF to the name of the desired configuration file.
However, this too isn't in my system. I've run the linux find command and this file doesn't seem to be there. I've run out of leagues and I have a sneaking suspicion that I am overlooking something very simple. Is there any other leads I can go on? Thanks.
Based on this message and the rest of the context:
FATAL: no pg_hba.conf entry for host xxx.xx.xxxx.xxx, user "ruby", database "postgres", SSL off
It looks plausible that:
you're connecting to a remote PostgreSQL instance which you don't administrate because you're acting as developer, not admin.
the db management layer tries to connect to the database named postgres in order to drop another database (staging_database) . It's necessary indeed because we can't drop a database when we're connected to it (in fact, a database can't be dropped when anyone is connected to it).
the admin policy established by the remote pg_hba.conf is such that your login and IP address together are not allowed to connect to the database named postgres
These facts combined together imply that you're missing the necessary rights to drop your database, even if indirectly.
At this point you want to submit the problem to the admin responsible for that PostgreSQL server.

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