

For this, use the usual Unix shell syntax: Normally it is better to start postgres in the background. If that variable is not provided either, it will fail. Without -D, the server will try to use the data directory named by the environment variable PGDATA. This must be done while logged into the PostgreSQL user account. Which will leave the server running in the foreground. The bare-bones way to start the server manually is just to invoke postgres directly, specifying the location of the data directory with the -D option, for example: Consult the package-level documentation for details.
CONFIGURE POSTGRESQL UNIX SOCKET HOW TO
Using the package's infrastructure to start the server will be much less work than figuring out how to do this yourself. If you are using a pre-packaged version of PostgreSQL, it almost certainly includes provisions for running the server as a background task according to the conventions of your operating system. The database server program is called postgres. Client Connection Problemsīefore anyone can access the database, you must start the database server.

It might be the case, because SELinux allows nginx to use php-fpm Unix domain socket ( /var/run/php5-fpm.sock), but for some reason blocks usage of PostgreSQL Unix domain socket ( /var/pgsql/.s.PGSQL.5432).19.3.1. I'd be glad to know if there is a way to avoid custom SELinux module by changing some file contexts or booleans. # semodule -i httpd_postgresql_unix_socket_connect.ppĬontent of httpd_postgresql_unix_socket_connect.te: module httpd_postgresql_unix_socket_connect 1.0 Permission denied - this is something one can fight.Īllow httpd_t initrc_t:unix_stream_socket connectto Īnd it can be fixed: # audit2allow -a -M httpd_postgresql_unix_socket_connect I thought that the error was the same, but it wasn't: Error (256): Cannot connect to database: SQLSTATE could not connect toĬonnections on Unix domain socket "/var/pgsql/.s.PGSQL.5432"? What I missed was the changed error message. In the original post I wrote that I've tried to change the location of Unix domain socket file, and I really did. Uncomment and modify unix_socket_directories parameter in /var/lib/pgsql/9.3/data/nf ( /tmp is still needed not to break psql and other programs): unix_socket_directories = '/tmp,/var/pgsql'Īnd here was another tricky part. # semanage fcontext -a -t httpd_var_run_t "/var/pgsql(/.*)?" To resolve the issue I've changed the location for PostgreSQL Unix domain socket file with following steps:Ĭreate a new directory /var/pgsql (note changing SELinux file context): # mkdir /var/pgsql This means that php-fpm could not see /tmp/.s.PGSQL.5432 nor anything else located in /tmp. The initial cause of it was in systemd service file for php-fpm /usr/lib/systemd/system/rvice: 1 apache apache 0 Oct 31 19:54 /proc/882/root -> /Īt this point I have no more ideas where the problem can be and I would appreciate any help. It looks like php-fpm process is not chroot'ed: # ls -l /proc/882/root The file name is correct and, again, file /tmp/.s.PGSQL.5432 exists: $ ls -l /tmp/.s.PGSQL.5432 connect(5,, 110) = -1 ENOENT (No such file or directory) fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0 Relevant lines from strace of php-fpm: socket(PF_LOCAL, SOCK_STREAM, 0) = 5

There was nothing in /var/log/audit/audit.log, but I've tried to disable SELinux, just to be sure: # setenforce 0 Relevant line from /var/lib/pgsql/9.3/data/pg_hba.conf: local all username trustĬhange of location for Unix domain socket file in /var/lib/pgsql/9.3/data/nf did not help: unix_socket_directories = '/var/run/pgsql' So there should be no problems from the PostgreSQL side. Is the server running locally and acceptingĬonnections on Unix domain socket "/tmp/.s.PGSQL.5432"?įile /tmp/.s.PGSQL.5432 exists and I can connect using psql: $ psql -Uusername db_name PostgreSQL is listening on standard port 5432 and I have no problems to use it via TCP/IP at 127.0.0.1:5432, but when I try to connect to its Unix domain socket, I have a following error: Cannot connect to database: SQLSTATE could not connect to server: I'm trying to connect to PostgreSQL Unix domain socket from a PHP web application.
