Systemd cannot start Postgresql on Red Hat EL7 - postgresql

On Red Hat EL7, I installed Postgres from the standard repository and initialized the database in the usual way:
# postgresql-setup initdb
But when I try to start the service with:
# systemctl start postgresql.service
I get an error:
Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.
journalctl -xn gives me:
Oct 06 14:52:55 myserver systemd[1]: Starting PostgreSQL database server...
-- Subject: Unit postgresql.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has begun starting up.
Oct 06 14:52:55 myserver systemd[29267]: Failed at step USER spawning /usr/bin/postgresql-check-db-dir: No such process
-- Subject: Process /usr/bin/postgresql-check-db-dir could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /usr/bin/postgresql-check-db-dir could not be executed and failed.
--
-- The error number returned while executing this process is 3.
Anyone have any ideas?

I don't consider this a complete and proper fix, but it's what I'd call a "strong workaround". The problem seems to start with the fact that this Linux system can authenticate locally as well as through a directory server. The PostgreSQL package tries to create a user:group combo called postgres:postgres. The user "postgres" wasn't created because it already exists in the directory server. The group "postgres" was created locally.
When systemd starts Postgres, it changes into the postgres user before trying to call postgresql-check-db-dir which is a script that checks whether the database directory has been intialized with postgresql-setup initdb. It seems that systemd can't change to this directory-supplied postgres user.
My work-around was to create a new local user ("pgsql") and change the ownership of /var/lib/pgsql and /var/run/postgresql to this new user, then create a custom systemd service file called /etc/systemd/system/postgresql.service to override the default one. The contents of this file are:
.include /usr/lib/systemd/system/postgresql.service
[Service]
User=pgsql
Group=postgres
That allows Postgres to be started and stopped by systemd.

For me the logs are telling you that the db path does not exist. Are you sure psql is configured correctly, the db path exists and you have permission to access it ?

Related

System has not been booted with systemd ERROR when updating Postgresql in Ubuntu

I've been following this link to update Postgresql on my Ubuntu-18.04 (VM running on Windows 10)
https://computingforgeeks.com/install-postgresql-12-on-ubuntu/
However, Im getting the below error, so I cannot proceed.
.../desktop/my_app$ systemctl status postgresql.service
System has not been booted with systemd as init system (PID 1). Can't operate.
What can I do?
service postgresql status
or
systemctl status postgresql
Must work.

I can't start server PostgreSQL 11: "pg_ctl: could not start server"

I am in CentOS Linux release 7.5.1804 (Core)
When I login as postgres and run:
bash-4.2$ /usr/pgsql-11/bin/initdb -D /var/lib/pgsql/11/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.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /var/lib/pgsql/11/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/usr/pgsql-11/bin/pg_ctl -D /var/lib/pgsql/11/data -l logfile start
bash-4.2$
then I run
bash-4.2$ /usr/pgsql-11/bin/pg_ctl start -l logfile -D /var/lib/pgsql/11/data
waiting for server to start..../bin/sh: logfile: Permission denied
stopped waiting
pg_ctl: could not start server
Examine the log output.
bash-4.2$ date
Wed Oct 24 01:50:44 -05 2018
bash-4.2$
I search in GOOGLE for "waiting for server to start..../bin/sh: logfile: Permission denied" but this error only happened in MAC and no solutions is displayed...
Also I run
bash-4.2$ postgres --version;postmaster --version;
postgres (PostgreSQL) 11.0
postgres (PostgreSQL) 11.0
bash-4.2$
then I believe PostgreSQL 11 is fine installed, but I can't start server.
I install with this line:
yum install postgresql-jdbc.noarch postgresql-jdbc-javadoc.noarch postgresql-unit11.x86_64 postgresql-unit11-debuginfo.x86_64 postgresql11.x86_64 postgresql11-contrib.x86_64 postgresql11-debuginfo.x86_64 postgresql11-devel.x86_64 postgresql11-docs.x86_64 postgresql11-libs.x86_64 postgresql11-odbc.x86_64 postgresql11-plperl.x86_64 postgresql11-plpython.x86_64 postgresql11-pltcl.x86_64 postgresql11-server.x86_64 postgresql11-tcl.x86_64 postgresql11-test.x86_64
I didn't add [postgresql11-llvmjit.x86_64] because this requires many dependences.
CentOS Linux release 7.5.1804 + PostgreSQL 11 ?
Do I need install aditional software?
The logfile is not to be taken literally, it should be replaced with a file where the PostgreSQL server process has write permission.
You don't do it that way normally, rather you edit postgresql.conf and configure log_destination, logging_collector, log_directory and log_filename. Then you start PostgreSQL without the -l option.
Your attempt to start PostgreSQL with systemctl probably did work; you can check with
systemctl status postgresql-11
So, I faced the same issue.
First I checked for if and what all servers were active on my machine using :
brew services list
Then I had some servers active so I stopped them as you need to stop them for posgresql server to work.
brew services stop < name of the server/s active >
Then I created a new database
initdb /usr/local/var/postgres2
and started the server using
pg_ctl -D /usr/local/var/postgres2 -l logfile start
Worked fine for me !!
enter image description here
I think there is a background postgres process running and firstly you need to kill this service. I had same problem and fixed by this command:
sudo /etc/init.d/postgresql stop
or you can try to kill all postgres named processes in your system monitor and delete postmaster.pid file in your database directory.
Then you can start the server as:
sudo -u <your-username> pg_ctl -D <your-database-file-location> start
An example for this:
sudo -u shc /home/shc/postgres-built/bin/pg_ctl -D /home/shc/mydatabase start
After you are done, to not face same problems again, stop the server as:
sudo -u <your-username> pg_ctl -D <your-database-file-location> stop

Issue in restarting postgres service

I have updated the postgres version to 9.5 (using yum update)
When I try to see the postgres version by :
postgres --version
postgres (PostgreSQL) 9.2.23
There is postgres service running. I confirmed ut by :
systemctl list-unit-files | grep postg
postgresql.service enabled
When I try to stop the running postgres service by :
/etc/init.d/postgresql.service stop
bash: /etc/init.d/postgresql.service: No such file or directory
I tried to start the postgres service gave me same No such file or directory issue.
When I tried to dig into the logs, I found something as below
postgresql.service: control process exited, code=exited status=1
Feb 07 16:06:10 punessgdev2 systemd[1]: Failed to start PostgreSQL database
server.
How do I proceed? Any kind of help is appreciated.
$ sudo systemctl status/start/restart postgresql.service
work fine to me DEBIAN 9 POSTGRES 9.6.15

PostgreSQL Services

Can someone give a detailed explanation of how the postgresql service(s) works on Ubuntu [16.04]? The behavior that leads me to ask is the following. I use the command sudo systemctl start postgresql to start my postgresql service. When I run systemctl list-units | grep post I see
UNIT LOAD ACTIVE SUB DESCRIPTION
postgresql.service loaded active exited PostgreSQL RDBMS
postgresql#9.6-main.service loaded active running PostgreSQL Cluster 9.6-main
system-postgresql.slice loaded active active system-postgresql.slice
and when I run sudo systemctl stop postgresql both postgresql.service and postgresql#9.6-main.service disappear. What is each of these three services doing?
I assume postgresql#9.6-main.service is registered service for PostgreSQL Cluster 9.6-main cluster. This is the one that actually controls postgres on your system.
I assume postgresql.service is the effect desribed here
I assume system-postgresql.slice is a postgres slice unit
none of above are critical for running postgres. You can start/stop the cluser with just pg_ctl, without registering it with your services. But if you wonder which service runs it in your case - then it is postgresql#9.6-main.service

Zend Server CE messing with Apache?

I am starting with a clean install of Fedora 15 on a VirtualBox VM and trying to install Zend Server CE. To install, I adding the Zend repo to yum and ran:
sudo yum install zend-server-ce-php-5.3
The installation itself seemed to go very well. I opened the browser at http://localhost:10081/ZendServer as directed. After clicking through the license page and entering an administative password I get the error:
Failed to access Web server. Please make sure that the Web server is running and listening to the correct port
The Applications, Rules Management and Administration tabs function properly but the Monitor and Server Setup tabs both display the above error. It is a fact that the web server is not running, but when I try to rectify that I get another error:
$ sudo service httpd start
[sudo] Password for XXXXX:
Starting httpd (via systemctl): Job failed. See system logs and 'systemctl status' for details.
[FAILED]
For what it's worth (not much, I'm guessing) here are the details the message refers to:
$ sudo tail /var/log/messages
....
Jan 17 17:24:18 M5 systemd[1]: httpd.service: control process exited, code=exited status=1
Jan 17 17:24:18 M5 systemd[1]: Unit httpd.service entered failed state.
$ systemctl status httpd.service
httpd.service - LSB: start and stop Apache HTTP Server
Loaded: loaded (/etc/rc.d/init.d/httpd)
Active: failed since Tue, 17 Jan 2012 17:24:18 -0500; 3min 44s ago
Process: 19500 ExecStart=/etc/rc.d/init.d/httpd start (code=exited, status=1/FAILURE)
CGroup: name=systemd:/system/httpd.service
The diagnostics don't seem very helpful. I've tried various things, such as installing and starting httpd before installing Zend Server CE, reinstalling httpd (no good: unistalling it caused Zend to uninstall too). The httpd config isn't causing the problem as the following output demonstrates:
$ /usr/sbin/apachectl configtest
Syntax OK
Is this a know problem? What's my next move? Do I start putting debug statements in the control script to see what's failing? I can do that, but I'm hoping someone out there has dealt with this problem and can give me a quick solution.
I was able to get better information on the cause of the problem by invoking the apachectl script directly rather than using the service:
$ sudo /usr/sbin/apachectl start
httpd: Syntax error on line 220 of /etc/httpd/conf/httpd.conf: Syntax error on line 6 of /etc/httpd/conf.d/zendserver_php.conf: Cannot load /usr/local/zend/lib/apache2/libphp5.so into server: /usr/local/zend/lib/apache2/libphp5.so: cannot enable executable stack as shared object requires: Permission denied
The syntax check on httpd.conf didn't catch this because it's not really a syntax error and it's not in httpd.conf either, but in the included zendserver_php.conf. A quick search shows that this error is the result of libphp5.so violating one of the constraints that SELinux enforces. SELinux is enabled by default in Fedora 15.
I don't like to reduce security, but that the only way I've seen this issue addressed. So I disabled SELinux temporarily with the command
$ sudo setenforce 0
I also edited /etc/selinux/config and changed SELINUX=enforced to SELINUX=disabled so SELinux would stay disabled on reboot. Now my web server starts without a hitch:
[mike#M5 ~]$ sudo service httpd start
Starting httpd (via systemctl): [ OK ]
I would like to think someone in the Zend development community is working on this shared library issue. Reducing security is not an acceptable work-around in a lot of cases. If anybody has a better solution, I'd still like to know it.