Ces*_*arD 8 linux postgresql ubuntu ubuntu-16.04
我是 Linux 和 Postgres 的新手。我已经尝试将我的数据连接到另一个目录两天了,但没有成功。
首先,我在 postgres.conf 中更改了数据目录:
data_directory = '/var/lib/postgresql/9.6/main'
Run Code Online (Sandbox Code Playgroud)
到:
data_directory = '/media/cesar/My Book/data9.6'
Run Code Online (Sandbox Code Playgroud)
当我尝试连接到 Postgres 时,出现以下错误:
cesar@ubuntu:/$ sudo -u postgres psql postgres
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"?
Run Code Online (Sandbox Code Playgroud)
我多次重新启动Postgres服务器并更改配置也没有成功。
如果我改回旧目录,它就可以正常工作。
cesar@ubuntu:/$ sudo /etc/init.d/postgresql restart
[sudo] password for cesar:
[ ok ] Restarting postgresql (via systemctl): postgresql.service.
cesar@ubuntu:/$ sudo -u postgres psql postgres
psql (9.6.2)
Type "help" for help.
postgres=#
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?
ls -s 响应
postgres@ubuntu:~$ ls -l /media/cesar/My\ Book/data9.6
total 149
drwxrwxrwx 1 cesar cesar 0 Jan 7 22:04 base
drwxrwxrwx 1 cesar cesar 16384 Feb 6 19:40 global
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_clog
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_commit_ts
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_dynshmem
-rwxrwxrwx 2 cesar cesar 4118 Jan 8 14:46 pg_hba.conf
-rwxrwxrwx 2 cesar cesar 1678 Jan 7 21:56 pg_ident.conf
drwxrwxrwx 1 cesar cesar 65536 Feb 6 00:16 pg_log
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_logical
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_multixact
drwxrwxrwx 1 cesar cesar 0 Feb 6 00:16 pg_notify
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_replslot
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_serial
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_snapshots
drwxrwxrwx 1 cesar cesar 0 Feb 6 00:16 pg_stat
drwxrwxrwx 1 cesar cesar 0 Feb 7 21:15 pg_stat_tmp
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_subtrans
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_tblspc
drwxrwxrwx 1 cesar cesar 0 Jan 7 21:56 pg_twophase
-rwxrwxrwx 2 cesar cesar 4 Jan 7 21:56 PG_VERSION
drwxrwxrwx 1 cesar cesar 32768 Feb 6 00:15 pg_xlog
-rwxrwxrwx 2 cesar cesar 90 Jan 7 21:56 postgresql.auto.conf
-rwxrwxrwx 1 cesar cesar 22267 Feb 12 14:25 postgresql.conf
-rwxrwxrwx 2 cesar cesar 67 Feb 6 00:16 postmaster.opts
-rwxrwxrwx 2 cesar cesar 35 Feb 6 00:16 postmaster.pid
-rwxrwxrwx 1 cesar cesar 3 Feb 12 14:52 test.txt
Run Code Online (Sandbox Code Playgroud)
用户postgres
应对数据目录具有读、写和执行权限。其他用户不应具有写入权限。您可以通过以下方式设置这些权限:
chown -R postgres:postgres '/media/cesar/My Book/dataGE'
chmod -R u+rwx,g-rwx,o-rwx '/media/cesar/My Book/dataGE'
Run Code Online (Sandbox Code Playgroud)
更改数据目录后,您应该运行initdb
来设置数据库文件:
su - postgres
initdb
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11777 次 |
最近记录: |