厌倦了创建 /run/postgresql 并在每次重启后设置读取和执行写入
Tired of creating /run/postgresql and setting read and execute writes after every reboot
我是 运行ning Arch Linux,我安装 PostgreSQL 就像安装任何其他 arch 软件包一样。我正在 运行ning postgres,在我的用户目录中有一个本地数据库。 (postgres -D /home/user/data/
) 当我这样做时,出现错误 FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
。创建目录 /run/postgresql 并授予 postgres 用户访问权限解决了这个问题
$ sudo mkdir /run/postgresql
$ sudo chmod a+w /run/postgresql
但是我厌倦了每次重新启动时都编写这些命令,因为 /运行 在重新启动时会被清除。我可以编写一个脚本来执行这些命令,但我觉得我一开始就以错误的方式做这件事。有什么方法可以让 postgres 自己创建目录,或者让它不使用 /run/postgres 作为它的锁定文件?
Postgres 默认在 /run/postgresql
中创建锁文件。
来自联机帮助页:
-k directory
Specifies the directory of the Unix-domain socket on which postgres is
to listen for connections from client applications. The default is
normally /run/postgresql, but can be changed at build time.
使用 -k directory
告诉 postgres 使用不同的目录。
运行 你的命令是 postgres -k /tmp -D /home/user/data/
.
解决方案 1(通过管理临时目录 /run/postgresql、/var/run/postgresql)
Directory /run/postgresql is a temporary directory. Path
/var/run/postgresql is usually a symbolic link to /run/postgresql.
systemd-tmpfiles is mechanism to manage such temporary files and directories. systemd-tmpfiles creates temporary directories during
boot and sets their owner, group and permissions. It may read configuration files in three different locations. Files in
/etc/tmpfiles.d override files with the same name in
/usr/lib/tmpfiles.d and /run/tmpfiles.d.
我们可以通过创建 postgresql 使用 systemd-tmpfiles 机制在启动时动态创建目录 /run/postgresql配置文件如下
echo "d /run/postgresql 0755 postgres postgres -" > /usr/lib/tmpfiles.d/postgresql.conf
解决方案 2(通过重新定位 PostgreSQL 锁定文件位置)
Another way to fix the issue is to relocate the PostgreSQL lock file
location. We can do so by using below query
ALTER SYSTEM SET unix_socket_directories='<any-existing-path-with-valid-permissions>, /tmp';
在这里我们可以为系统中已经存在的 PostgreSQL 锁文件提供任何路径,并且具有 postgres 用户管理锁文件所需的权限。
我是 运行ning Arch Linux,我安装 PostgreSQL 就像安装任何其他 arch 软件包一样。我正在 运行ning postgres,在我的用户目录中有一个本地数据库。 (postgres -D /home/user/data/
) 当我这样做时,出现错误 FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
。创建目录 /run/postgresql 并授予 postgres 用户访问权限解决了这个问题
$ sudo mkdir /run/postgresql
$ sudo chmod a+w /run/postgresql
但是我厌倦了每次重新启动时都编写这些命令,因为 /运行 在重新启动时会被清除。我可以编写一个脚本来执行这些命令,但我觉得我一开始就以错误的方式做这件事。有什么方法可以让 postgres 自己创建目录,或者让它不使用 /run/postgres 作为它的锁定文件?
Postgres 默认在 /run/postgresql
中创建锁文件。
来自联机帮助页:
-k directory Specifies the directory of the Unix-domain socket on which postgres is to listen for connections from client applications. The default is normally /run/postgresql, but can be changed at build time.
使用 -k directory
告诉 postgres 使用不同的目录。
运行 你的命令是 postgres -k /tmp -D /home/user/data/
.
解决方案 1(通过管理临时目录 /run/postgresql、/var/run/postgresql)
Directory /run/postgresql is a temporary directory. Path /var/run/postgresql is usually a symbolic link to /run/postgresql.
systemd-tmpfiles is mechanism to manage such temporary files and directories. systemd-tmpfiles creates temporary directories during boot and sets their owner, group and permissions. It may read configuration files in three different locations. Files in /etc/tmpfiles.d override files with the same name in /usr/lib/tmpfiles.d and /run/tmpfiles.d.
我们可以通过创建 postgresql 使用 systemd-tmpfiles 机制在启动时动态创建目录 /run/postgresql配置文件如下
echo "d /run/postgresql 0755 postgres postgres -" > /usr/lib/tmpfiles.d/postgresql.conf
解决方案 2(通过重新定位 PostgreSQL 锁定文件位置)
Another way to fix the issue is to relocate the PostgreSQL lock file location. We can do so by using below query
ALTER SYSTEM SET unix_socket_directories='<any-existing-path-with-valid-permissions>, /tmp';
在这里我们可以为系统中已经存在的 PostgreSQL 锁文件提供任何路径,并且具有 postgres 用户管理锁文件所需的权限。