Friday, 17 December 2010

如何在RHEL5.5上更改PostgreSQL的数据目录?

检查缺省数据目录的属性
# ls -lZ /var/lib/pgsql
drwx------  postgres postgres system_u:object_r:postgresql_db_t data

生成新的数据目录
# mkdir -p /opt/postgresql/data

检查新生成的数据目录属性
# ls -lZ /opt/postgresql/
drwxr-xr-x  root root root:object_r:usr_t              data

更改新生成数据目录的所有权
# chown -R postgres:postgres /opt/postgresql

修改启动代码中的相关路径
# vi /etc/rc.d/init.d/postgresql
PGDATA=/opt/postgresql/data
PGLOG=/opt/postgresql/data/pgstartup.log

创建新的数据区
# su - postgres -c "initdb -D /opt/postgresql/data"

为新数据区添加SELINUX标签
# semanage fcontext -a -t postgresql_db_t "/opt/postgresql(/.*)?"

检查新添标签是否到位
# grep -i postgresql /etc/selinux/targeted/contexts/files/file_contexts.local
/opt/postgresql(/.*)?    system_u:object_r:postgresql_db_t:s0

为新数据区贴标签
# restorecon -R -v /opt/postgresql

验证更改后数据库服务能否启动
# service postgresql start
Starting postgresql service:                               [  OK  ]

将数据库服务设置为自动启动
# chkconfig postgresql on
# chkconfig --list | grep post
postgresql      0:off   1:off   2:on    3:on    4:on    5:on    6:off

No comments:

Post a Comment

Note: only a member of this blog may post a comment.