首页 文章

移动数据目录后连接postgresql错误

提问于
浏览
0

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(我不确定这是否是我需要做的)

  • show data_directory返回: /var/lib/postgresql/9.5/main

数据目录位于Ubuntu ext4格式的硬盘中 . 我还有一个安装在 /mnt/Data 上的1 TB NTFS格式化硬盘(在启动时自动挂载) . 我尝试了什么:

  • 停止postgres服务: sudo systemctl stop postgresql

  • 创建一个新目录 /mnt/Data/postgresdb 并将上一个main的内容复制到此处,这使我得到 /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

关于如何解决这个问题的任何想法?

ORIGINAL POST

最近,我安装了Postgresql来存储我研究的一些数据 . 数据集附带有关如何在Postgresql数据库上设置数据的说明(如果感兴趣,有关herehere的更多信息) . 我安装了Postgresql并设置了"role"并使用了为加载数据库而提供的脚本 . 它工作但我低估了数据集的大小,脚本退出说没有更多的空间 .

我的计算机上有两个驱动器,一个安装了Windows和Ubuntu的250G SSD驱动器(每个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格式的文件系统(不确定是否会导致任何问题) .

谢谢 .

1 回答

  • 0

    正如评论中所提到的,NTFS就是问题所在 . 我最终调整了我的更大的硬盘驱动器100GB格式为ext4,并能够使用新的数据目录启动postgres没有任何问题 .

相关问题