如何无root权限运行PostgreSQL?解决pgtester在Fedora的套接字创建问题
I’ve run into this exact snag with pgtester on Fedora before—here’s how to get around the socket permission block without needing root access:
1. Configure pgtester to use a custom socket directory
The root problem is that /var/run/postgresql/ is owned by the root or postgres system user by default, so your regular user account can’t create sockets there. The fix is to redirect pgtester to use a directory you control:
- First, create a dedicated socket directory in your home folder (make sure it exists before proceeding):
mkdir -p ~/.pgtester_sockets/ - Locate where pgtester initializes the temporary PostgreSQL server (either in its config files or source code). Look for settings tied to
unix_socket_directoriesor the default socket path. - Override this setting to point to your new directory. For example, add this command-line flag when starting the test server:
Alternatively, update the auto-generated-c unix_socket_directories='~/.pgtester_sockets/'postgresql.confthat pgtester uses to include this path.
2. Use an environment variable to override the socket path
If you don’t want to modify pgtester’s code directly, you can use a PostgreSQL-specific environment variable to redirect the socket location:
- Before running your test suite, export the
PGHOSTvariable to point to your custom directory:
This tells PostgreSQL (and pgtester’s client tools) to look for the socket in your user-owned folder instead of the system default.export PGHOST=~/.pgtester_sockets/
3. Verify permissions and test
Double-check your custom directory has the right permissions to avoid any extra roadblocks—PostgreSQL needs read/write access, so lock it down with:
chmod 700 ~/.pgtester_sockets/
Then run your tests again. The temporary server should now create the socket in your directory without hitting permission errors.
内容的提问来源于stack exchange,提问作者honza_p

