在使用pg_basebackup备份基础数据的时候,遇到了错误
directory "/home/Thornger" exists but is not empty
经过检查-D ‘/home/Thornger/data2’,指定的文件夹里面确实是空的。
[Thornger@localhost postgres-9.6]$ ll data2/
total 0
data2 下没有数据,这时候你就应该检查你的主库,也就是说你指定创建基础备份的库。检查一下有没有特殊地方的tablespace
psql
postgres=# \db
List of tablespaces
Name | Owner | Location
------------+----------+----------------
pg_default | Thornger |
pg_global | Thornger |
test | Thornger | /home/Thornger
问题找到了,有一个自建的tablespace 在/home/Thornger下。
pg_basebackup 中有一个参数:大概意思就是将你以前创建的tablespace目录对应到现在指定的tablespace 目录。
-T olddir=newdir
--tablespace-mapping=olddir=newdir
Relocate the tablespace in directory olddir to newdir during the backup. To be effective, olddir must exactly match the path specification of the tablespace as it is currently defined. (But it is not an error if there is no tablespace in olddir contained in the backup.) Both olddir and newdir must be absolute paths. If a path happens to contain a = sign, escape it with a backslash. This option can be specified multiple times for multiple tablespaces. See examples below.
If a tablespace is relocated in this way, the symbolic links inside the main data directory are updated to point to the new location. So the new data directory is ready to be used for a new server instance with all tablespaces in the updated locations.
所以:参数中指定
-T /home/Thornger=/home/Thornger/data2/
问题解决