Postgresql_02 切换数据目录
在Linux系统中,Postgresql的默认数据文件是放在/var/lib/postgresql,但是有时候,我们通过mount命令挂载了一个很大的disk,需要把数据库文件放在挂载的空间上,下边就是切换数据文件的方法:
1.查看默认的数据目录
2.停止Postgresql 数据库
[code]
$ sudo systemctl stop postgresql
$ sudo systemctl status postgresql
Output:
postgresql.service – PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor prese
Active: inactive (dead) since Mon 2016-09-12 15:40:23 IST; 3s ago
Process: 1553 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 1553 (code=exited, status=0/SUCCESS)
Sep 07 19:27:27 ubuntu-16 systemd[1]: Starting PostgreSQL RDBMS…
Sep 07 19:27:27 ubuntu-16 systemd[1]: Started PostgreSQL RDBMS.
Sep 12 15:20:23 ubuntu-16 systemd[1]: Stopped PostgreSQL RDBMS.
[/code]
3.复制默认的数据文件和脚本
[code]
sudo rsync -av /var/lib/postgresql /mnt/data_vol/
[/code]
4.修改配置文件
[code]
$ sudo vi /etc/postgresql/9.5/main/postgresql.conf
Output:
….
….
….
#——————————————————————————
# FILE LOCATIONS
#——————————————————————————
# The default values of these variables are driven from the -D command-line
# option or PGDATA environment variable, represented here as ConfigDir
data_directory = ‘/mnt/data_vol/postgresql/9.5/main’ # use data in another directory
# (change requires restart)
hba_file = ‘/etc/postgresql/9.5/main/pg_hba.conf’ # host-based authentication file
# (change requires restart)
ident_file = ‘/etc/postgresql/9.5/main/pg_ident.conf’ # ident configuration file
….
….
….
[/code]
5.重启数据库
[code]
sudo systemctl start postgresql
[/code]
最后重新执行第一步,看是否修改成功。
2 thoughts on “Postgresql_02 切换数据目录”
very good! ++
同意你的观点!