【发布时间】:2018-06-24 11:52:12
【问题描述】:
EDIT-2
我发现更改文件位置后数据库甚至没有启动。
这是默认文件位置:
$pg_isready
/var/run/postgresql:5432 - accepting connections
$pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
9.5 main 5432 online postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log
pg_lsclusters 输出为绿色。
在 postgresql.conf 文件位置改变后:
$pg_isready
/var/run/postgresql:5432 - no response
$pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
9.5 main 5432 down root /mnt/Data/postgresdb/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log
这里的输出是红色的。
按照here这个帖子,我尝试手动启动集群:
$pg_ctlcluster 9.5 main start
Warning: the cluster will not be running as a systemd service. Consider using systemctl:
sudo systemctl start postgresql@9.5-main
Error: You must run this program as the cluster owner (root) or root
我用 sudo 尝试了相同的命令:
Error: Config owner (postgres:124) and data owner (root:0) do not match, and config owner is not root
这再次让我认为问题可能在于目录的权限。该目录归 root 所有,我无法更改其所有权。
EDIT-1
我一直在努力解决这个问题,我想进一步提炼这篇文章以提供更多细节。这是我目前的情况:
- 我安装了postgres:
sudo apt-get install postgresql and postgresql-contrib - 我使用
sudo -U postgres psql进入 postgres shell(我不确定这是否是我需要做的) - 显示数据目录返回:
/var/lib/postgresql/9.5/main
数据目录位于 Ubuntu ext4 格式化硬盘中。我还有一个 1 TB NTFS 格式的硬盘安装在/mnt/Data 上(它会在启动时自动安装)。我尝试了什么:
- 停止 postgres 服务:
sudo systemctl stop postgresql - 创建一个新目录
/mnt/Data/postgresdb并将前一个主目录的内容复制到此目录,这给了我一个/mnt/Data/postgresdb/postgresql/9.5/main的完整路径,使用:sudo rsync -av /var/lib/postgresql/ /mnt/Data/postgresdb/postgresql/ - 编辑
/etc/postgresql/9.5/main/postgresql.conf将data_directory从上述路径更改为/mnt/Data/postgresdb/postgresql/9.5/main - 启动postgres服务:
sudo systemctl start postgresl - 运行
sudo -U postgres psql,但得到原帖中提到的错误。
这些是各个主目录的权限:
ls -l /var/lib/postgresql/9.5/
total 4.0K drwx------ 19 postgres postgres 4.0K Jan 16 12:40 main
ls -l /mnt/Data/postgresdb/postgresql/9.5/
total 4.0K drwxrwxrwx 1 root root 4.0K Jan 16 12:13 main
从外观上看,默认目录归“postgres”所有,新目录归root所有。但是,当我尝试将所有权更改为 postgres:chown -R postgres main 时,它不会输出任何错误,但所有权不会改变。我很好奇这是否是因为该驱动器是 NTFS 格式并已安装。
这是我的 /etc/fstab:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda5 during installation
UUID=3f5a9875-89a3-4ce5-b778-9d7aaf148ed6 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda6 during installation
UUID=85c3f4d4-e450-435b-8dd6-cf1b2cbd8fc2 none swap sw 0 0
/dev/disk/by-label/Data /mnt/Data auto nosuid,nodev,nofail,x-gvfs-show 0 0
关于如何解决此问题的任何想法?
原帖
最近,我安装了 Postgresql 来存储我的研究数据。该数据集附带有关如何在 Postgresql 数据库上设置数据的说明(如果有兴趣,请参阅有关 here 和 here 的更多信息)。我安装了 Postgresql 并设置了一个“角色”,并使用了为加载数据库提供的脚本。它起作用了,但我低估了数据集的大小,脚本退出说没有更多空间了。
我的计算机上有两个驱动器,一个 250G SSD 驱动器,安装了 Windows 和 Ubuntu(每个 125G)。还有一个 1TB HDD NTFS 格式化存储我的数据。所以我认为将数据库移动到另一个驱动器上的文件夹会很有帮助。我清除了所有数据和数据库以重新开始,并按照说明here 移动数据库目录。但是,移动目录后,当我尝试使用 psql 连接时,出现以下错误:
~ psql -U username -d postgres 14:48:33
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我该如何解决这个问题?我正在使用 Postgresql-9.5 运行 64 位 Ubuntu 16.04。如前所述,我将 DB 目录移动为 NTFS 格式的文件系统(不确定这是否会导致任何问题)。
谢谢。
【问题讨论】:
-
那么,你启动服务了吗?如果没有,它开始了吗?如果没有,Postgres 日志文件中是否有任何错误消息?
-
我确实重启了服务。我仍然得到同样的错误。在哪里可以找到日志文件?
-
pg_ctl -D '/your/new/path' start- 输出是什么?.. -
我没有 pg_ctl 命令。我有 pg_ctlcluster 和 pg_lsclusters。
-
我认为是 NTFS 导致了问题。 NTFS 卷上的权限和所有权不正确。这就是你得到错误的原因。简单的解决方案是不使用 NTFS。另外,您应该有
/usr/lib/postgresql/9.5/bin/pg_ctl,并且您应该提及您使用的是 debian 或 ubuntu 版本的 postgres,而不是 postgres 分发的 postgres。
标签: database postgresql