文章目录

操作步骤

  • 创建目录
mkdir -p /postgresql/test01
  • 创建表空间
psql -c "create tablespace tblspace_test01 location '/postgresql/test01';"
  • 在新建的表空间中新建表
psql -c "create table test(id int) tablespace tblspace_test01";
  • 查看表空间
psql -c "\db+"
  • pg_basebackup 物理备份
mkdir -p /postgresql/{data_bak,tablespace_test01}
pg_basebackup -Upostgres -Fp -Xs -P -v -D /postgresql/data_bak
pg_basebackup -Upostgres -Fp -Xs -P -v -D /postgresql/data_bak -T /postgresql/test01=/postgresql/tablespace_test01

实际操作过程

[pgsql@centos76pg ~]$ mkdir -p /postgresql/test01
[pgsql@centos76pg ~]$ psql -c "create tablespace tblspace_test01 location '/postgresql/test01';"
CREATE TABLESPACE
[pgsql@centos76pg ~]$ psql -c "create table test(id int) tablespace tblspace_test01";
CREATE TABLE
[pgsql@centos76pg ~]$ psql -c "\db+"
List of tablespaces
Name | Owner | Location | Access privileges | Options | Size | Description
-----------------+----------+--------------------+-------------------+---------+------------+-------------
pg_default | postgres | | | | 340 MB |
pg_global | postgres | | | | 559 kB |
tblspace_test01 | postgres | /postgresql/test01 | | | 4096 bytes |
(3 rows)

[pgsql@centos76pg ~]$ mkdir -p /postgresql/{data_bak,test01}
[pgsql@centos76pg ~]$ pg_basebackup -Upostgres -Fp -Xs -P -v -D /postgresql/data_bak
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/35000028 on timeline 1
pg_basebackup: error: directory "/postgresql/test01" exists but is not empty
pg_basebackup: removing contents of data directory "/postgresql/data_bak"
[pgsql@centos76pg ~]$ mkdir -p /postgresql/{data_bak,tablespace_test01}
[pgsql@centos76pg ~]$ pg_basebackup -Upostgres -Fp -Xs -P -v -D /postgresql/data_bak
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/36000028 on timeline 1
pg_basebackup: error: directory "/postgresql/test01" exists but is not empty
pg_basebackup: removing contents of data directory "/postgresql/data_bak"
[pgsql@centos76pg ~]$ pg_basebackup -Upostgres -Fp -Xs -P -v -D /postgresql/data_bak -T /postgresql/test01=/postgresql/tablespace_test01
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/37000028 on timeline 1
pg_basebackup: starting background WAL receiver
pg_basebackup: created temporary replication slot "pg_basebackup_22786"
349807/349807 kB (100%), 2/2 tablespaces
pg_basebackup: write-ahead log end point: 0/37000100
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: syncing data to disk ...
pg_basebackup: renaming backup_manifest.tmp to backup_manifest
pg_basebackup: base backup completed