PostgreSQL 设置 PGDATA 变量

4 postgresql drbd postgresql-9.3 ubuntu-14.04

服务器:Ubuntu 服务器 14 lts + PostgreSQL 9.2 我想使用 drbd 创建集群数据库,但如果没有集群初始化,我无法设置 PGDATA。我只需要说 pgsql 使用 drbd 磁盘中的数据。我怎样才能做到呢?

示例1:

mkdir /cluster/var/lib/pgsql -p
chown postgres:postgres /cluster/var/lib/pgsql -R
cp -R /var/lib/pgsql /cluster/var/lib/pgsql

edit /etc/init.d/postgresql :
 PGDATA=/cluster/var/lib/pgsql/data
...
PGLOG=/cluster/var/lib/pgsql/pgstartup.log

/etc/init.d/postgresql start
Run Code Online (Sandbox Code Playgroud)

在 postgresql 8.3 中它可以工作,但在 9.2 中我无法更改 /etc/init.d/postgresql 中的 pgdata,我需要找到另一个文件并设置 pgdata,但是,令人惊讶的是,它什么也没做。

示例2:PGDATA——指定要存储数据库簇的目录;可以使用 -D 选项覆盖。

好的,让我们开始: --pgdata=directory 是的,它有效!但现在我们有 postgresql-xc 和类似“postgresql 不认识这个用户 - postgresql”的错误。drbd 开始从集群复制数据,但 postgresql 也启动它。

更新1:

root: initdb --pgdata=/home/username/dir
~initdb not install~bla-bla-bla~use apt-get install postgres-xc
Run Code Online (Sandbox Code Playgroud)

更新2:

$: /usr/lib/postgresql/9.3/bin/initdb --pgdata=/whateveryouwant

#now you can run postgresql only one way:

$: /usr/lib/postgresql/9.3/bin/postgres -D /see_up

#then:

LOG:  database system was shut down at 2014-09-26 15:56:33 YEKT   
LOG:  database system is ready to accept connections    
LOG:  autovacuum launcher started

#aaaaaaaaaaand...nothing. just empty console, ^C stopping postgres    
#another SSH connect:

$: ps-ela

S  1000  5995  5217  0  80   0 - 62202 poll_s pts/0    00:00:00 postgres    
1 S  1000  5997  5995  0  80   0 - 62202 poll_s ?        00:00:00 postgres    
1 S  1000  5998  5995  0  80   0 - 62202 poll_s ?        00:00:00 postgres    
1 S  1000  5999  5995  0  80   0 - 62202 poll_s ?        00:00:00 postgres    
1 S  1000  6000  5995  0  80   0 - 62415 poll_s ?        00:00:00 postgres    
1 S  1000  6001  5995  0  80   0 - 26121 poll_s ?        00:00:00 postgres

#is it ok? because...

$: /etc/init.d/postgresql status    
9.3/main (port 5432): down
Run Code Online (Sandbox Code Playgroud)

Dan*_*ité 6

使用 Ubuntu,要为 PostgreSQL 实例使用特定的数据目录,您只需执行以下操作:

# pg_createcluster --datadir=/path/to/the/directory 9.3 nameofcluster
Run Code Online (Sandbox Code Playgroud)

您不需要或不想在$PGDATA任何地方摆弄。请参阅pg_createcluster联机帮助页。

如果用于drdb复制集群中的数据目录,请记住cluster PostgreSQL 术语中的术语具有不同的含义:它始终是数据库集群,这意味着由特定 PostgreSQL 实例及其唯一数据目录提供服务的所有数据库。这与drdb cluster机器集群不同。

PostgreSQL 集群的数据目录根本无法共享,从某种意义上说,只有在一台机器上运行的一个特定 PostgreSQL 实例可以写入其中,否则会发生损坏。

如果drdb配置符合这个要求就可以使用,否则不行。您可能还会问为什么要drdb首先使用 PostgreSQL 从 8.3 版本开始就具有内置的复制选项 ,这些选项比纯磁盘复制更专业、更适合数据库。